Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pyqpanda-algorithm/pyqpanda_alg/QUBO/QUBO.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions test/QAlgBase/Test_QUBO_QUBO_QAOA_run.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import numpy as np
import pytest
import sympy as sp
from pyqpanda_alg.QUBO import QUBO
Expand All @@ -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"])