diff --git a/pyqpanda-algorithm/pyqpanda_alg/QUBO/QUBO.py b/pyqpanda-algorithm/pyqpanda_alg/QUBO/QUBO.py index 576f1034..39907dfb 100644 --- a/pyqpanda-algorithm/pyqpanda_alg/QUBO/QUBO.py +++ b/pyqpanda-algorithm/pyqpanda_alg/QUBO/QUBO.py @@ -479,13 +479,13 @@ class QUBO_QAOA(QuadraticBinary): def __init__(self, problem): super(QUBO_QAOA, self).__init__(problem) - def run(self, layer=None, optimizer='SLSQP', optimizer_option=None): + def run(self, layer=1, optimizer='SLSQP', optimizer_option=None): """ Run the solver to find the minimum. Parameters - layer : ``int``\n - Layers number of QAOA circuit. + layer : ``int``, ``optional``\n + Layers number of QAOA circuit. Default is 1. If optimize type is interp, then it represents the final layer of the optimization progress. optimizer : ``str``, ``optional``\n Type of solver. Should be one of diff --git a/test/QAlgBase/Test_QUBO_QUBO_QAOA_run.py b/test/QAlgBase/Test_QUBO_QUBO_QAOA_run.py index c050b417..71ae8d4e 100644 --- a/test/QAlgBase/Test_QUBO_QUBO_QAOA_run.py +++ b/test/QAlgBase/Test_QUBO_QUBO_QAOA_run.py @@ -1,3 +1,4 @@ +import numpy as np import pytest import sympy as sp from pyqpanda_alg.QUBO import QUBO @@ -20,6 +21,26 @@ def test_qubo_qaoa_basic_functionality(self, setup_qubo_instance): assert result['010'] >= 0.1 + def test_qubo_qaoa_default_arguments(self, setup_qubo_instance): + test_instance = setup_qubo_instance + np.random.seed(42) + result = test_instance.run() + + assert isinstance(result, dict) + assert len(result) == 8 + assert all(0 <= p <= 1 for p in result.values()) + assert abs(sum(result.values()) - 1) < 1e-6 + assert result['010'] >= 0.1 + + def test_qubo_qaoa_default_layer_is_one(self, setup_qubo_instance): + test_instance = setup_qubo_instance + np.random.seed(42) + default_result = test_instance.run() + np.random.seed(42) + layer_one_result = test_instance.run(layer=1) + + assert default_result == layer_one_result + if __name__ == "__main__": pytest.main([__file__, "-v", "-s"]) \ No newline at end of file