From f1c786159f3eaa7f538af262675ef313795efe0e Mon Sep 17 00:00:00 2001 From: "shahidee44@hotmail.com" Date: Mon, 20 Feb 2023 06:54:48 +0000 Subject: [PATCH 01/67] aaa --- tests/test_qpu_qiskit.py | 58 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 54 insertions(+), 4 deletions(-) diff --git a/tests/test_qpu_qiskit.py b/tests/test_qpu_qiskit.py index 2948c424e..8fb2b7dcf 100644 --- a/tests/test_qpu_qiskit.py +++ b/tests/test_qpu_qiskit.py @@ -12,6 +12,58 @@ QAOAQiskitBackendStatevecSimulator) from openqaoa.utilities import X_mixer_hamiltonian from openqaoa.problems import NumberPartition +from openqaoa import QAOA + + +class TestingQAOAQiskitQPUBackendAzure(unittest.TestCase): + + """This Object tests the QAOA Qiskit QPU Backend object with the Azure + Device object. This checks that the use of qiskit to send circuits to Azure + is working as intended. + + The Azure CLI has to be configured beforehand to run these tests. + """ + + @pytest.mark.qpu + def setUp(self): + + bashCommand = "az resource list" + process = subprocess.Popen(bashCommand.split(), stdout=subprocess.PIPE) + output, error = process.communicate() + + if error is not None: + print(error) + raise Exception('You must have the Azure CLI installed and must be logged in to use the Azure Quantum Backends') + else: + output_json = json.loads(output) + output_json_s = [each_json for each_json in output_json if each_json['name'] == 'TestingOpenQAOA'][0] + self.RESOURCE_ID = output_json_s['id'] + self.AZ_LOCATION = output_json_s['location'] + + @pytest.mark.qpu + def check_shots_tally(self): + + """There is a known bug in the qiskit backend for azure where if the shots + argument might be ignored. This test checks that the output from the azure + computation matches the input requirements. + """ + + shots = 1024 + problem_qubo = NumberPartition([1, 2, 3]).qubo + azure_device = create_device(location='azure', name='rigetti.sim.qvm', + resource_id=self.RESOURCE_ID, + az_location=self.AZ_LOCATION) + + q = QAOA() + q.set_device(azure_device) + q.set_backend_properties(n_shots=shots) + q.set_classical_optimizer(maxiter = 1) + q.compile(problem_qubo) + q.optimize() + + comp_shots = sum(q.result.optimized['optimized measurement outcomes'].values()) + + self.assertEqual(shots, comp_shots) class TestingQAOAQiskitQPUBackend(unittest.TestCase): @@ -19,10 +71,8 @@ class TestingQAOAQiskitQPUBackend(unittest.TestCase): """This Object tests the QAOA Qiskit QPU Backend objects, which is tasked with the creation and execution of a QAOA circuit for the selected QPU provider and backend. - - For all of these tests, credentials.json MUST be filled with the appropriate - credentials. If unsure about to correctness of the current input credentials - , please run test_qpu_devices.py. + + IBMQ Account has to be saved locally to run these tests. """ @pytest.mark.qpu From 4aa29cd6f74691a868071c753e98aee6faeddf7c Mon Sep 17 00:00:00 2001 From: Leonardo Disilvestro Date: Tue, 21 Feb 2023 16:04:40 +0800 Subject: [PATCH 02/67] Add docker tests --- .github/workflows/test_dev.yml | 4 +++- Dockerfile | 1 + docker-compose.yml | 5 +++++ 3 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.github/workflows/test_dev.yml b/.github/workflows/test_dev.yml index c5bec4860..90802abd9 100644 --- a/.github/workflows/test_dev.yml +++ b/.github/workflows/test_dev.yml @@ -30,6 +30,8 @@ jobs: uses: actions/setup-python@v3 with: python-version: ${{ matrix.python }} + - name: Build the stack + run: docker-compose up -d - name: Install OpenQAOA run: | @@ -61,7 +63,7 @@ jobs: run: | source env/bin/activate ipython kernel install --name "env" --user - python -m pytest -v -m 'not (qpu or api or docker_aws)' --cov --cov-report=xml:coverage.xml + python -m pytest -v -m 'not (qpu or api)' --cov --cov-report=xml:coverage.xml - name: Upload coverage reports to Codecov with GitHub Action uses: codecov/codecov-action@v3 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..13a650976 --- /dev/null +++ b/Dockerfile @@ -0,0 +1 @@ +FROM qlds/openqaoa-braket-jobs diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..3f2efa029 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,5 @@ +version: '3' +services: + web: + container_name: oq-aws-jobs-local + build: . From 12e38cba4e4693cce7f4b502d2732acc84dc3abb Mon Sep 17 00:00:00 2001 From: Leonardo Disilvestro Date: Tue, 21 Feb 2023 16:54:05 +0800 Subject: [PATCH 03/67] Add qvm and quilc as dockers in the tests --- .github/workflows/test_dev.yml | 18 +----------------- docker-compose.yml | 8 +++++++- 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/.github/workflows/test_dev.yml b/.github/workflows/test_dev.yml index 90802abd9..31a385778 100644 --- a/.github/workflows/test_dev.yml +++ b/.github/workflows/test_dev.yml @@ -41,23 +41,7 @@ jobs: python -m pip install --upgrade pip pip install .[tests] pip install ipykernel - - - name: Install qvm - run: | - find /usr/lib -name "libffi.so*" - sudo ln -s /usr/lib/x86_64-linux-gnu/libffi.so /usr/lib/x86_64-linux-gnu/libffi.so.6 - wget -q https://downloads.rigetti.com/qcs-sdk/forest-sdk-2.23.0-linux-deb.tar.bz2 - tar -xf forest-sdk-2.23.0-linux-deb.tar.bz2 - cd forest-sdk-2.23.0-linux-deb/ - sudo apt-get update - sudo apt-get install -y screen libblas-dev libblas3 libgfortran5 liblapack-dev liblapack3 - sudo ./forest-sdk-2.23.0-linux-deb.run - qvm --version - quilc --version - echo "Starting qvm and quilc" - screen -d -m qvm -S - screen -d -m quilc -S - cd .. + - name: Run tests run: | diff --git a/docker-compose.yml b/docker-compose.yml index 3f2efa029..1c96e0fa8 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,5 +1,11 @@ version: '3' services: - web: + oq-braket: container_name: oq-aws-jobs-local build: . + qvm: + container_name: rigetti/qvm + build: run --rm -it -p 5000:5000 rigetti/qvm -S + quilc: + container_name: rigetti/quilc + build: run --rm -it -p 5555:5555 rigetti/quilc -P -S From c7bcb5ddf1df9ee8cdc5d60fd378326e70205603 Mon Sep 17 00:00:00 2001 From: Leonardo Disilvestro Date: Tue, 21 Feb 2023 17:02:48 +0800 Subject: [PATCH 04/67] Update rigetti dockers --- .github/workflows/test_dev.yml | 5 ++++- docker-compose.yml | 7 ++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test_dev.yml b/.github/workflows/test_dev.yml index 31a385778..9fe2a0654 100644 --- a/.github/workflows/test_dev.yml +++ b/.github/workflows/test_dev.yml @@ -32,7 +32,10 @@ jobs: python-version: ${{ matrix.python }} - name: Build the stack run: docker-compose up -d - + - name: Start the rigetti machines + run: | + docker run --rm -it -p 5000:5000 rigetti/qvm -S + docker run --rm -it -p 5555:5555 rigetti/quilc -P -S - name: Install OpenQAOA run: | python -m pip install --user virtualenv diff --git a/docker-compose.yml b/docker-compose.yml index 1c96e0fa8..cbb3b0aa2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,7 +5,8 @@ services: build: . qvm: container_name: rigetti/qvm - build: run --rm -it -p 5000:5000 rigetti/qvm -S + image: rigetti/qvm:latest quilc: - container_name: rigetti/quilc - build: run --rm -it -p 5555:5555 rigetti/quilc -P -S + container_name: quilc + image: rigetti/quilc:latest + From 3f0a7ae3de229a8fe331d6836021390c0e00835d Mon Sep 17 00:00:00 2001 From: Leonardo Disilvestro Date: Tue, 21 Feb 2023 17:11:23 +0800 Subject: [PATCH 05/67] Update docker run commands --- .github/workflows/test_dev.yml | 4 ++-- docker-compose.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test_dev.yml b/.github/workflows/test_dev.yml index 9fe2a0654..07d9a97e9 100644 --- a/.github/workflows/test_dev.yml +++ b/.github/workflows/test_dev.yml @@ -34,8 +34,8 @@ jobs: run: docker-compose up -d - name: Start the rigetti machines run: | - docker run --rm -it -p 5000:5000 rigetti/qvm -S - docker run --rm -it -p 5555:5555 rigetti/quilc -P -S + docker run --rm -it -p 5000:5000 qvm -S + docker run --rm -it -p 5555:5555 quilc -P -S - name: Install OpenQAOA run: | python -m pip install --user virtualenv diff --git a/docker-compose.yml b/docker-compose.yml index cbb3b0aa2..d9af09396 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,7 +4,7 @@ services: container_name: oq-aws-jobs-local build: . qvm: - container_name: rigetti/qvm + container_name: qvm image: rigetti/qvm:latest quilc: container_name: quilc From 32b8fe4537698e176aeed71e149b01018138ad71 Mon Sep 17 00:00:00 2001 From: Leonardo Disilvestro Date: Tue, 21 Feb 2023 17:23:04 +0800 Subject: [PATCH 06/67] remove -it from docker run --- .github/workflows/test_dev.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test_dev.yml b/.github/workflows/test_dev.yml index 07d9a97e9..d985c3e16 100644 --- a/.github/workflows/test_dev.yml +++ b/.github/workflows/test_dev.yml @@ -34,8 +34,8 @@ jobs: run: docker-compose up -d - name: Start the rigetti machines run: | - docker run --rm -it -p 5000:5000 qvm -S - docker run --rm -it -p 5555:5555 quilc -P -S + docker run --rm -i -p 5000:5000 qvm -S + docker run --rm -i -p 5555:5555 quilc -P -S - name: Install OpenQAOA run: | python -m pip install --user virtualenv From 1cbfdc94952e7d77c58a3529324f87f8c5806c8c Mon Sep 17 00:00:00 2001 From: Leonardo Disilvestro Date: Tue, 21 Feb 2023 17:29:52 +0800 Subject: [PATCH 07/67] Update tests --- .github/workflows/test_dev.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test_dev.yml b/.github/workflows/test_dev.yml index d985c3e16..2da0fe430 100644 --- a/.github/workflows/test_dev.yml +++ b/.github/workflows/test_dev.yml @@ -34,8 +34,8 @@ jobs: run: docker-compose up -d - name: Start the rigetti machines run: | - docker run --rm -i -p 5000:5000 qvm -S - docker run --rm -i -p 5555:5555 quilc -P -S + docker run container:qvm --rm -i -p 5000:5000 qvm -S + docker run container:quilc --rm -i -p 5555:5555 quilc -P -S - name: Install OpenQAOA run: | python -m pip install --user virtualenv From 84cb7192264b2d3885f1c0d13dcc46c8f0fa5e83 Mon Sep 17 00:00:00 2001 From: Leonardo Disilvestro Date: Tue, 21 Feb 2023 17:37:28 +0800 Subject: [PATCH 08/67] Update --- .github/workflows/test_dev.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test_dev.yml b/.github/workflows/test_dev.yml index 2da0fe430..e3c4da7dc 100644 --- a/.github/workflows/test_dev.yml +++ b/.github/workflows/test_dev.yml @@ -34,8 +34,8 @@ jobs: run: docker-compose up -d - name: Start the rigetti machines run: | - docker run container:qvm --rm -i -p 5000:5000 qvm -S - docker run container:quilc --rm -i -p 5555:5555 quilc -P -S + docker run --rm -i -p 5000:5000 container:qvm -S + docker run --rm -i -p 5555:5555 container:quilc -P -S - name: Install OpenQAOA run: | python -m pip install --user virtualenv From cfc5fb2e0e32259adb5a113ad40fe26b4fa9ac06 Mon Sep 17 00:00:00 2001 From: Leonardo Disilvestro Date: Tue, 21 Feb 2023 17:44:13 +0800 Subject: [PATCH 09/67] Updates --- .github/workflows/test_dev.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test_dev.yml b/.github/workflows/test_dev.yml index e3c4da7dc..362d2b579 100644 --- a/.github/workflows/test_dev.yml +++ b/.github/workflows/test_dev.yml @@ -34,8 +34,8 @@ jobs: run: docker-compose up -d - name: Start the rigetti machines run: | - docker run --rm -i -p 5000:5000 container:qvm -S - docker run --rm -i -p 5555:5555 container:quilc -P -S + docker run --rm -i -p 5000:5000 rigetti/qvm:latest -S + docker run --rm -i -p 5555:5555 rigetti/quilc:latest -P -S - name: Install OpenQAOA run: | python -m pip install --user virtualenv From 4c504b2db593c25960bfd136aa871303bb5cf428 Mon Sep 17 00:00:00 2001 From: Leonardo Disilvestro Date: Tue, 21 Feb 2023 17:50:35 +0800 Subject: [PATCH 10/67] Update --- .github/workflows/test_dev.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test_dev.yml b/.github/workflows/test_dev.yml index 362d2b579..b8309a9a9 100644 --- a/.github/workflows/test_dev.yml +++ b/.github/workflows/test_dev.yml @@ -34,8 +34,8 @@ jobs: run: docker-compose up -d - name: Start the rigetti machines run: | - docker run --rm -i -p 5000:5000 rigetti/qvm:latest -S - docker run --rm -i -p 5555:5555 rigetti/quilc:latest -P -S + docker run --rm -p 5000:5000 rigetti/qvm:latest -S + docker run --rm -p 5555:5555 rigetti/quilc:latest -P -S - name: Install OpenQAOA run: | python -m pip install --user virtualenv From bd98d19fa3be03843b973c450a3fe0b8d1d02ecc Mon Sep 17 00:00:00 2001 From: Leonardo Disilvestro Date: Tue, 21 Feb 2023 17:57:15 +0800 Subject: [PATCH 11/67] add -id flag --- .github/workflows/test_dev.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test_dev.yml b/.github/workflows/test_dev.yml index b8309a9a9..44c233c0f 100644 --- a/.github/workflows/test_dev.yml +++ b/.github/workflows/test_dev.yml @@ -34,8 +34,8 @@ jobs: run: docker-compose up -d - name: Start the rigetti machines run: | - docker run --rm -p 5000:5000 rigetti/qvm:latest -S - docker run --rm -p 5555:5555 rigetti/quilc:latest -P -S + docker run --rm -id -p 5000:5000 rigetti/qvm:latest -S + docker run --rm -id -p 5555:5555 rigetti/quilc:latest -P -S - name: Install OpenQAOA run: | python -m pip install --user virtualenv From b3c9b2fcdeec238355b90894395e6823d0287b5e Mon Sep 17 00:00:00 2001 From: Leonardo Disilvestro Date: Tue, 21 Feb 2023 19:47:37 +0800 Subject: [PATCH 12/67] update aws tests --- tests/test_aws_managed_jobs.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tests/test_aws_managed_jobs.py b/tests/test_aws_managed_jobs.py index 508e691fd..78b911c27 100644 --- a/tests/test_aws_managed_jobs.py +++ b/tests/test_aws_managed_jobs.py @@ -70,7 +70,7 @@ def testOsEnvironAssignment(self): assert rqaoa_workflow.algorithm == "rqaoa" assert rqaoa_workflow.device.device_name == os.environ["AMZN_BRAKET_DEVICE_ARN"] - @pytest.mark.api + def testCreateAwsQAOA(self): """ Test Creation and Loading of input_data @@ -83,6 +83,7 @@ def testCreateAwsQAOA(self): # Create the qubo and the qaoa q = QAOA() q.set_device(create_device('aws', 'arn:aws:braket:::device/quantum-simulator/amazon/sv1')) + q.device.check_connection = True q.compile(self.vc) q.dump(file_name='openqaoa_params.json', file_path=input_data_path, prepend_id=False, overwrite=True) @@ -92,7 +93,7 @@ def testCreateAwsQAOA(self): assert job.workflow.asdict() == q.asdict() - @pytest.mark.api + def testCreateAwsRecursiveQAOA(self): """ Test Creation and Loading of input_data @@ -105,6 +106,7 @@ def testCreateAwsRecursiveQAOA(self): # Create the qubo and the qaoa r = RQAOA() r.set_device(create_device('aws', 'arn:aws:braket:::device/quantum-simulator/amazon/sv1')) + q.device.check_connection = True r.set_classical_optimizer(maxiter=3, save_intermediate=False) r.compile(self.vc) r.dump(file_name='openqaoa_params.json', file_path=input_data_path, prepend_id=False, overwrite=True) @@ -116,7 +118,6 @@ def testCreateAwsRecursiveQAOA(self): assert job.workflow.asdict() == r.asdict() - @pytest.mark.api def testEndToEndLocalQAOA(self): """ Test Creation and Loading of input_data @@ -141,7 +142,7 @@ def testEndToEndLocalQAOA(self): job.run_workflow() - @pytest.mark.api + @pytest.mark.qpu def testEndToEndLocalRQAOA(self): """ Test Creation and Loading of input_data @@ -168,6 +169,7 @@ def testEndToEndLocalRQAOA(self): assert job.completed == True + @pytest.mark.docker_aws def testLocalJob(self): """Test an end-to-end qaoa running on a local docker instance""" @@ -179,6 +181,7 @@ def testLocalJob(self): # Create the qubo and the qaoa q = QAOA() q.set_device(create_device('aws', 'arn:aws:braket:::device/quantum-simulator/amazon/sv1')) + q.device.check_connection = True q.compile(self.vc) q.dump(file_name='openqaoa_params.json', file_path=input_data_path, prepend_id=False, overwrite=True) @@ -191,6 +194,7 @@ def testLocalJob(self): assert job.state() == 'COMPLETED' + @pytest.mark.docker_aws def testLocalJobRQAOA(self): """Test an end-to-end rqaoa running on a local docker instance""" @@ -203,6 +207,7 @@ def testLocalJobRQAOA(self): r.set_rqaoa_parameters(n_cutoff=6) r.set_classical_optimizer(maxiter=3, save_intermediate=False) r.set_device(create_device('aws', 'arn:aws:braket:::device/quantum-simulator/amazon/sv1')) + q.device.check_connection = True r.compile(self.vc) r.dump(file_name='openqaoa_params.json', file_path=input_data_path, prepend_id=False, overwrite=True) From 1803cd361ffa30277bcc762d74cdd03cb3bb041a Mon Sep 17 00:00:00 2001 From: Leonardo Disilvestro Date: Tue, 21 Feb 2023 21:28:20 +0800 Subject: [PATCH 13/67] Update tests --- src/openqaoa-core/backends/basebackend.py | 3 +- tests/test_aws_managed_jobs.py | 87 ++++++++++++----------- 2 files changed, 46 insertions(+), 44 deletions(-) diff --git a/src/openqaoa-core/backends/basebackend.py b/src/openqaoa-core/backends/basebackend.py index d8335fa4f..22dd48627 100644 --- a/src/openqaoa-core/backends/basebackend.py +++ b/src/openqaoa-core/backends/basebackend.py @@ -558,7 +558,8 @@ class QAOABaseBackendCloud: def __init__(self, device: DeviceBase): self.device = device - self.device.check_connection() + self.device.check_connection == Flase: + self.device.check_connection() class QAOABaseBackendParametric: diff --git a/tests/test_aws_managed_jobs.py b/tests/test_aws_managed_jobs.py index 78b911c27..0b98e8eb4 100644 --- a/tests/test_aws_managed_jobs.py +++ b/tests/test_aws_managed_jobs.py @@ -106,7 +106,7 @@ def testCreateAwsRecursiveQAOA(self): # Create the qubo and the qaoa r = RQAOA() r.set_device(create_device('aws', 'arn:aws:braket:::device/quantum-simulator/amazon/sv1')) - q.device.check_connection = True + r.device.check_connection = True r.set_classical_optimizer(maxiter=3, save_intermediate=False) r.compile(self.vc) r.dump(file_name='openqaoa_params.json', file_path=input_data_path, prepend_id=False, overwrite=True) @@ -118,56 +118,57 @@ def testCreateAwsRecursiveQAOA(self): assert job.workflow.asdict() == r.asdict() - def testEndToEndLocalQAOA(self): - """ - Test Creation and Loading of input_data - """ + # @pytest.mark.qpu + # def testEndToEndLocalQAOA(self): + # """ + # Test Creation and Loading of input_data + # """ - input_data_path = os.path.join( - os.environ["AMZN_BRAKET_INPUT_DIR"], "input_data/" - ) - os.environ[ - "AMZN_BRAKET_JOB_RESULTS_DIR" - ] = "/oq_release_tests/testing_jobs/EndToEnd" + # input_data_path = os.path.join( + # os.environ["AMZN_BRAKET_INPUT_DIR"], "input_data/" + # ) + # os.environ[ + # "AMZN_BRAKET_JOB_RESULTS_DIR" + # ] = "/oq_release_tests/testing_jobs/EndToEnd" - # Create the qubo and the qaoa - q = QAOA() - q.set_classical_optimizer(maxiter=2) - q.compile(self.vc) - q.dump(file_name='openqaoa_params.json', file_path=input_data_path, prepend_id=False, overwrite=True) + # # Create the qubo and the qaoa + # q = QAOA() + # q.set_classical_optimizer(maxiter=2) + # q.compile(self.vc) + # q.dump(file_name='openqaoa_params.json', file_path=input_data_path, prepend_id=False, overwrite=True) - # Create an aws workflow and try check that loading the json gives the same params - job = AWSJobs(algorithm="QAOA") - job.load_compile_data() - job.run_workflow() + # # Create an aws workflow and try check that loading the json gives the same params + # job = AWSJobs(algorithm="QAOA") + # job.load_compile_data() + # job.run_workflow() - @pytest.mark.qpu - def testEndToEndLocalRQAOA(self): - """ - Test Creation and Loading of input_data - """ + # @pytest.mark.qpu + # def testEndToEndLocalRQAOA(self): + # """ + # Test Creation and Loading of input_data + # """ - input_data_path = os.path.join( - os.environ["AMZN_BRAKET_INPUT_DIR"], "input_data/" - ) - os.environ[ - "AMZN_BRAKET_JOB_RESULTS_DIR" - ] = "/oq_release_tests/testing_jobs/EndToEnd" + # input_data_path = os.path.join( + # os.environ["AMZN_BRAKET_INPUT_DIR"], "input_data/" + # ) + # os.environ[ + # "AMZN_BRAKET_JOB_RESULTS_DIR" + # ] = "/oq_release_tests/testing_jobs/EndToEnd" - # Create the qubo and the qaoa - r = RQAOA() - r.set_rqaoa_parameters(steps = 2, n_cutoff = 3) - r.set_classical_optimizer(maxiter=3, save_intermediate=False) - r.compile(self.vc) - r.dump(file_name='openqaoa_params.json', file_path=input_data_path, prepend_id=False, overwrite=True) + # # Create the qubo and the qaoa + # r = RQAOA() + # r.set_rqaoa_parameters(steps = 2, n_cutoff = 3) + # r.set_classical_optimizer(maxiter=3, save_intermediate=False) + # r.compile(self.vc) + # r.dump(file_name='openqaoa_params.json', file_path=input_data_path, prepend_id=False, overwrite=True) - # Create an aws workflow and try check that loading the json gives the same params - job = AWSJobs(algorithm="RQAOA") - job.load_compile_data() - job.run_workflow() + # # Create an aws workflow and try check that loading the json gives the same params + # job = AWSJobs(algorithm="RQAOA") + # job.load_compile_data() + # job.run_workflow() - assert job.completed == True + # assert job.completed == True @pytest.mark.docker_aws @@ -207,7 +208,7 @@ def testLocalJobRQAOA(self): r.set_rqaoa_parameters(n_cutoff=6) r.set_classical_optimizer(maxiter=3, save_intermediate=False) r.set_device(create_device('aws', 'arn:aws:braket:::device/quantum-simulator/amazon/sv1')) - q.device.check_connection = True + r.device.check_connection = True r.compile(self.vc) r.dump(file_name='openqaoa_params.json', file_path=input_data_path, prepend_id=False, overwrite=True) From 768f1ebd2f1bcc5faf547a8185df6f5e1c8ed088 Mon Sep 17 00:00:00 2001 From: Leonardo Disilvestro Date: Tue, 21 Feb 2023 21:33:29 +0800 Subject: [PATCH 14/67] Update check_connection requirement in QAOABaseBackendCloud --- src/openqaoa-core/backends/basebackend.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/openqaoa-core/backends/basebackend.py b/src/openqaoa-core/backends/basebackend.py index 22dd48627..4af01f717 100644 --- a/src/openqaoa-core/backends/basebackend.py +++ b/src/openqaoa-core/backends/basebackend.py @@ -558,7 +558,7 @@ class QAOABaseBackendCloud: def __init__(self, device: DeviceBase): self.device = device - self.device.check_connection == Flase: + if self.device.check_connection == Flase: self.device.check_connection() From 917254325cd135663e1df8a787a6b7ec3668fb3a Mon Sep 17 00:00:00 2001 From: Leonardo Disilvestro Date: Tue, 21 Feb 2023 21:44:51 +0800 Subject: [PATCH 15/67] Add MagicMock to AWS tests --- src/openqaoa-core/backends/basebackend.py | 3 +-- tests/test_aws_managed_jobs.py | 9 +++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/openqaoa-core/backends/basebackend.py b/src/openqaoa-core/backends/basebackend.py index 4af01f717..d8335fa4f 100644 --- a/src/openqaoa-core/backends/basebackend.py +++ b/src/openqaoa-core/backends/basebackend.py @@ -558,8 +558,7 @@ class QAOABaseBackendCloud: def __init__(self, device: DeviceBase): self.device = device - if self.device.check_connection == Flase: - self.device.check_connection() + self.device.check_connection() class QAOABaseBackendParametric: diff --git a/tests/test_aws_managed_jobs.py b/tests/test_aws_managed_jobs.py index 0b98e8eb4..24ce5469e 100644 --- a/tests/test_aws_managed_jobs.py +++ b/tests/test_aws_managed_jobs.py @@ -17,6 +17,7 @@ import unittest import networkx as nw from braket.jobs.local import LocalQuantumJob +from unittest.mock import MagicMock from openqaoa.problems import MinimumVertexCover from openqaoa.algorithms import AWSJobs @@ -82,8 +83,8 @@ def testCreateAwsQAOA(self): # Create the qubo and the qaoa q = QAOA() + q.device.check_connection = MagicMock(return_value = True) q.set_device(create_device('aws', 'arn:aws:braket:::device/quantum-simulator/amazon/sv1')) - q.device.check_connection = True q.compile(self.vc) q.dump(file_name='openqaoa_params.json', file_path=input_data_path, prepend_id=False, overwrite=True) @@ -105,8 +106,8 @@ def testCreateAwsRecursiveQAOA(self): # Create the qubo and the qaoa r = RQAOA() - r.set_device(create_device('aws', 'arn:aws:braket:::device/quantum-simulator/amazon/sv1')) r.device.check_connection = True + r.set_device(create_device('aws', 'arn:aws:braket:::device/quantum-simulator/amazon/sv1')) r.set_classical_optimizer(maxiter=3, save_intermediate=False) r.compile(self.vc) r.dump(file_name='openqaoa_params.json', file_path=input_data_path, prepend_id=False, overwrite=True) @@ -181,8 +182,8 @@ def testLocalJob(self): # Create the qubo and the qaoa q = QAOA() + q.device.check_connection = MagicMock(return_value = True) q.set_device(create_device('aws', 'arn:aws:braket:::device/quantum-simulator/amazon/sv1')) - q.device.check_connection = True q.compile(self.vc) q.dump(file_name='openqaoa_params.json', file_path=input_data_path, prepend_id=False, overwrite=True) @@ -207,8 +208,8 @@ def testLocalJobRQAOA(self): r = RQAOA() r.set_rqaoa_parameters(n_cutoff=6) r.set_classical_optimizer(maxiter=3, save_intermediate=False) + r.device.check_connection = MagicMock(return_value = True) r.set_device(create_device('aws', 'arn:aws:braket:::device/quantum-simulator/amazon/sv1')) - r.device.check_connection = True r.compile(self.vc) r.dump(file_name='openqaoa_params.json', file_path=input_data_path, prepend_id=False, overwrite=True) From c4aa59765f0807ca9bcc9c5840a738ff1db6846d Mon Sep 17 00:00:00 2001 From: Leonardo Disilvestro Date: Tue, 21 Feb 2023 22:00:54 +0800 Subject: [PATCH 16/67] Fix MagicMock issue --- tests/test_aws_managed_jobs.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/tests/test_aws_managed_jobs.py b/tests/test_aws_managed_jobs.py index 24ce5469e..51ee8abda 100644 --- a/tests/test_aws_managed_jobs.py +++ b/tests/test_aws_managed_jobs.py @@ -83,8 +83,11 @@ def testCreateAwsQAOA(self): # Create the qubo and the qaoa q = QAOA() - q.device.check_connection = MagicMock(return_value = True) q.set_device(create_device('aws', 'arn:aws:braket:::device/quantum-simulator/amazon/sv1')) + q.device.check_connection = MagicMock(return_value = True) + q.device.qpu_connected = MagicMock(return_value = True) + q.device.provider_connected = MagicMock(return_value = True) + q.device.n_qubits = MagicMock(return_value = 10) q.compile(self.vc) q.dump(file_name='openqaoa_params.json', file_path=input_data_path, prepend_id=False, overwrite=True) @@ -106,8 +109,11 @@ def testCreateAwsRecursiveQAOA(self): # Create the qubo and the qaoa r = RQAOA() - r.device.check_connection = True - r.set_device(create_device('aws', 'arn:aws:braket:::device/quantum-simulator/amazon/sv1')) + r.set_device(create_device('aws', 'arn:aws:braket:::device/quantum-simulator/amazon/sv1'))\ + r.device.check_connection = MagicMock(return_value = True) + r.device.qpu_connected = MagicMock(return_value = True) + r.device.provider_connected = MagicMock(return_value = True) + r.device.n_qubits = MagicMock(return_value = 10) r.set_classical_optimizer(maxiter=3, save_intermediate=False) r.compile(self.vc) r.dump(file_name='openqaoa_params.json', file_path=input_data_path, prepend_id=False, overwrite=True) @@ -182,8 +188,11 @@ def testLocalJob(self): # Create the qubo and the qaoa q = QAOA() - q.device.check_connection = MagicMock(return_value = True) q.set_device(create_device('aws', 'arn:aws:braket:::device/quantum-simulator/amazon/sv1')) + q.device.check_connection = MagicMock(return_value = True) + q.device.qpu_connected = MagicMock(return_value = True) + q.device.provider_connected = MagicMock(return_value = True) + q.device.n_qubits = MagicMock(return_value = 10) q.compile(self.vc) q.dump(file_name='openqaoa_params.json', file_path=input_data_path, prepend_id=False, overwrite=True) @@ -208,8 +217,11 @@ def testLocalJobRQAOA(self): r = RQAOA() r.set_rqaoa_parameters(n_cutoff=6) r.set_classical_optimizer(maxiter=3, save_intermediate=False) - r.device.check_connection = MagicMock(return_value = True) r.set_device(create_device('aws', 'arn:aws:braket:::device/quantum-simulator/amazon/sv1')) + r.device.check_connection = MagicMock(return_value = True) + r.device.qpu_connected = MagicMock(return_value = True) + r.device.provider_connected = MagicMock(return_value = True) + r.device.n_qubits = MagicMock(return_value = 10) r.compile(self.vc) r.dump(file_name='openqaoa_params.json', file_path=input_data_path, prepend_id=False, overwrite=True) From 3420b407a351d2fba5fb3bbc66286686effa71db Mon Sep 17 00:00:00 2001 From: Leonardo Disilvestro Date: Tue, 21 Feb 2023 22:22:10 +0800 Subject: [PATCH 17/67] Update magicMock conditions --- tests/test_aws_managed_jobs.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/tests/test_aws_managed_jobs.py b/tests/test_aws_managed_jobs.py index 51ee8abda..6b8a1e612 100644 --- a/tests/test_aws_managed_jobs.py +++ b/tests/test_aws_managed_jobs.py @@ -85,9 +85,9 @@ def testCreateAwsQAOA(self): q = QAOA() q.set_device(create_device('aws', 'arn:aws:braket:::device/quantum-simulator/amazon/sv1')) q.device.check_connection = MagicMock(return_value = True) - q.device.qpu_connected = MagicMock(return_value = True) - q.device.provider_connected = MagicMock(return_value = True) - q.device.n_qubits = MagicMock(return_value = 10) + q.device.qpu_connected = True + q.device.provider_connected = True + q.device.n_qubits = 10 q.compile(self.vc) q.dump(file_name='openqaoa_params.json', file_path=input_data_path, prepend_id=False, overwrite=True) @@ -109,11 +109,11 @@ def testCreateAwsRecursiveQAOA(self): # Create the qubo and the qaoa r = RQAOA() - r.set_device(create_device('aws', 'arn:aws:braket:::device/quantum-simulator/amazon/sv1'))\ + r.set_device(create_device('aws', 'arn:aws:braket:::device/quantum-simulator/amazon/sv1')) r.device.check_connection = MagicMock(return_value = True) - r.device.qpu_connected = MagicMock(return_value = True) - r.device.provider_connected = MagicMock(return_value = True) - r.device.n_qubits = MagicMock(return_value = 10) + r.device.qpu_connected = True + r.device.provider_connected = True + r.device.n_qubits = 10 r.set_classical_optimizer(maxiter=3, save_intermediate=False) r.compile(self.vc) r.dump(file_name='openqaoa_params.json', file_path=input_data_path, prepend_id=False, overwrite=True) @@ -190,9 +190,9 @@ def testLocalJob(self): q = QAOA() q.set_device(create_device('aws', 'arn:aws:braket:::device/quantum-simulator/amazon/sv1')) q.device.check_connection = MagicMock(return_value = True) - q.device.qpu_connected = MagicMock(return_value = True) - q.device.provider_connected = MagicMock(return_value = True) - q.device.n_qubits = MagicMock(return_value = 10) + q.device.qpu_connected = True + q.device.provider_connected = True + q.device.n_qubits = 10 q.compile(self.vc) q.dump(file_name='openqaoa_params.json', file_path=input_data_path, prepend_id=False, overwrite=True) @@ -219,9 +219,9 @@ def testLocalJobRQAOA(self): r.set_classical_optimizer(maxiter=3, save_intermediate=False) r.set_device(create_device('aws', 'arn:aws:braket:::device/quantum-simulator/amazon/sv1')) r.device.check_connection = MagicMock(return_value = True) - r.device.qpu_connected = MagicMock(return_value = True) - r.device.provider_connected = MagicMock(return_value = True) - r.device.n_qubits = MagicMock(return_value = 10) + r.device.qpu_connected = True + r.device.provider_connected = True + r.device.n_qubits = 10 r.compile(self.vc) r.dump(file_name='openqaoa_params.json', file_path=input_data_path, prepend_id=False, overwrite=True) From a5c119aaebd1dd9205e489ca34ea2798fd145fbb Mon Sep 17 00:00:00 2001 From: Leonardo Disilvestro Date: Tue, 21 Feb 2023 22:48:01 +0800 Subject: [PATCH 18/67] Mock available_qpus --- tests/test_aws_managed_jobs.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/test_aws_managed_jobs.py b/tests/test_aws_managed_jobs.py index 6b8a1e612..6a08d0105 100644 --- a/tests/test_aws_managed_jobs.py +++ b/tests/test_aws_managed_jobs.py @@ -87,6 +87,7 @@ def testCreateAwsQAOA(self): q.device.check_connection = MagicMock(return_value = True) q.device.qpu_connected = True q.device.provider_connected = True + q.device.available_qpus = ['arn:aws:braket:::device/quantum-simulator/amazon/sv1'] q.device.n_qubits = 10 q.compile(self.vc) q.dump(file_name='openqaoa_params.json', file_path=input_data_path, prepend_id=False, overwrite=True) @@ -114,6 +115,7 @@ def testCreateAwsRecursiveQAOA(self): r.device.qpu_connected = True r.device.provider_connected = True r.device.n_qubits = 10 + r.device.available_qpus = ['arn:aws:braket:::device/quantum-simulator/amazon/sv1'] r.set_classical_optimizer(maxiter=3, save_intermediate=False) r.compile(self.vc) r.dump(file_name='openqaoa_params.json', file_path=input_data_path, prepend_id=False, overwrite=True) @@ -193,6 +195,7 @@ def testLocalJob(self): q.device.qpu_connected = True q.device.provider_connected = True q.device.n_qubits = 10 + q.device.available_qpus = ['arn:aws:braket:::device/quantum-simulator/amazon/sv1'] q.compile(self.vc) q.dump(file_name='openqaoa_params.json', file_path=input_data_path, prepend_id=False, overwrite=True) @@ -222,6 +225,7 @@ def testLocalJobRQAOA(self): r.device.qpu_connected = True r.device.provider_connected = True r.device.n_qubits = 10 + r.device.available_qpus = ['arn:aws:braket:::device/quantum-simulator/amazon/sv1'] r.compile(self.vc) r.dump(file_name='openqaoa_params.json', file_path=input_data_path, prepend_id=False, overwrite=True) From a4f2df1ac12f3208fcddcd421167a5a4fd82cd61 Mon Sep 17 00:00:00 2001 From: Leonardo Disilvestro Date: Wed, 22 Feb 2023 09:21:59 +0800 Subject: [PATCH 19/67] Update aws docker tests --- docker-compose.yml | 2 +- tests/test_aws_managed_jobs.py | 34 ++++++++++++++++++++++------------ 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index d9af09396..ff6a500cc 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,7 @@ version: '3' services: oq-braket: - container_name: oq-aws-jobs-local + container_name: amazon-braket-oq-dev build: . qvm: container_name: qvm diff --git a/tests/test_aws_managed_jobs.py b/tests/test_aws_managed_jobs.py index 6a08d0105..bc04efb25 100644 --- a/tests/test_aws_managed_jobs.py +++ b/tests/test_aws_managed_jobs.py @@ -56,8 +56,10 @@ def setUp(self): # the string that should be passed to CreateQuantumTask’s jobToken parameter for quantum tasks created in the job container # os.environ["AMZN_BRAKET_JOB_TOKEN"] = '' + self.n_qubits = 10 + self.vc = MinimumVertexCover( - nw.circulant_graph(10, [1]), field=1.0, penalty=10 + nw.circulant_graph(n_qubits, [1]), field=1.0, penalty=10 ).qubo def testOsEnvironAssignment(self): @@ -74,7 +76,7 @@ def testOsEnvironAssignment(self): def testCreateAwsQAOA(self): """ - Test Creation and Loading of input_data + Checks whether the dict representation of q and the workflow match """ input_data_path = os.path.join( @@ -84,11 +86,13 @@ def testCreateAwsQAOA(self): # Create the qubo and the qaoa q = QAOA() q.set_device(create_device('aws', 'arn:aws:braket:::device/quantum-simulator/amazon/sv1')) + ### The following lines are needed to fool the github actions into correctly executing q.compile() !! q.device.check_connection = MagicMock(return_value = True) q.device.qpu_connected = True q.device.provider_connected = True - q.device.available_qpus = ['arn:aws:braket:::device/quantum-simulator/amazon/sv1'] - q.device.n_qubits = 10 + q.device.n_qubits = self.n_qubits + q.device.backend_device = '' + q.compile(self.vc) q.dump(file_name='openqaoa_params.json', file_path=input_data_path, prepend_id=False, overwrite=True) @@ -101,7 +105,7 @@ def testCreateAwsQAOA(self): def testCreateAwsRecursiveQAOA(self): """ - Test Creation and Loading of input_data + Checks whether the dict representation of r and the workflow match """ input_data_path = os.path.join( @@ -110,13 +114,15 @@ def testCreateAwsRecursiveQAOA(self): # Create the qubo and the qaoa r = RQAOA() + r.set_classical_optimizer(maxiter=3, save_intermediate=False) r.set_device(create_device('aws', 'arn:aws:braket:::device/quantum-simulator/amazon/sv1')) + ### The following lines are needed to fool the github actions into correctly executing q.compile() !! r.device.check_connection = MagicMock(return_value = True) r.device.qpu_connected = True r.device.provider_connected = True - r.device.n_qubits = 10 - r.device.available_qpus = ['arn:aws:braket:::device/quantum-simulator/amazon/sv1'] - r.set_classical_optimizer(maxiter=3, save_intermediate=False) + r.device.n_qubits = self.n_qubits + r.device.backend_device = '' + r.compile(self.vc) r.dump(file_name='openqaoa_params.json', file_path=input_data_path, prepend_id=False, overwrite=True) @@ -191,11 +197,13 @@ def testLocalJob(self): # Create the qubo and the qaoa q = QAOA() q.set_device(create_device('aws', 'arn:aws:braket:::device/quantum-simulator/amazon/sv1')) + ### The following lines are needed to fool the github actions into correctly executing q.compile() !! q.device.check_connection = MagicMock(return_value = True) q.device.qpu_connected = True q.device.provider_connected = True - q.device.n_qubits = 10 - q.device.available_qpus = ['arn:aws:braket:::device/quantum-simulator/amazon/sv1'] + q.device.n_qubits = self.n_qubits + q.device.backend_device = '' + q.compile(self.vc) q.dump(file_name='openqaoa_params.json', file_path=input_data_path, prepend_id=False, overwrite=True) @@ -221,11 +229,13 @@ def testLocalJobRQAOA(self): r.set_rqaoa_parameters(n_cutoff=6) r.set_classical_optimizer(maxiter=3, save_intermediate=False) r.set_device(create_device('aws', 'arn:aws:braket:::device/quantum-simulator/amazon/sv1')) + ### The following lines are needed to fool the github actions into correctly executing q.compile() !! r.device.check_connection = MagicMock(return_value = True) r.device.qpu_connected = True r.device.provider_connected = True - r.device.n_qubits = 10 - r.device.available_qpus = ['arn:aws:braket:::device/quantum-simulator/amazon/sv1'] + r.device.n_qubits = self.n_qubits + q.device.backend_device = '' + r.compile(self.vc) r.dump(file_name='openqaoa_params.json', file_path=input_data_path, prepend_id=False, overwrite=True) From e01b11c523f276a7c22809a2a43868cd4ace8582 Mon Sep 17 00:00:00 2001 From: Leonardo Disilvestro Date: Wed, 22 Feb 2023 09:41:32 +0800 Subject: [PATCH 20/67] fix aws tests --- tests/test_aws_managed_jobs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_aws_managed_jobs.py b/tests/test_aws_managed_jobs.py index bc04efb25..349116fc3 100644 --- a/tests/test_aws_managed_jobs.py +++ b/tests/test_aws_managed_jobs.py @@ -59,7 +59,7 @@ def setUp(self): self.n_qubits = 10 self.vc = MinimumVertexCover( - nw.circulant_graph(n_qubits, [1]), field=1.0, penalty=10 + nw.circulant_graph(self.n_qubits, [1]), field=1.0, penalty=10 ).qubo def testOsEnvironAssignment(self): From 0665df9668ab1f429c116dbd4b929c262215da1e Mon Sep 17 00:00:00 2001 From: Leonardo Disilvestro Date: Wed, 22 Feb 2023 10:37:58 +0800 Subject: [PATCH 21/67] Update aws docker tests --- tests/test_aws_managed_jobs.py | 93 +++++++++++++++++----------------- 1 file changed, 47 insertions(+), 46 deletions(-) diff --git a/tests/test_aws_managed_jobs.py b/tests/test_aws_managed_jobs.py index 349116fc3..b4d319ddb 100644 --- a/tests/test_aws_managed_jobs.py +++ b/tests/test_aws_managed_jobs.py @@ -74,63 +74,63 @@ def testOsEnvironAssignment(self): assert rqaoa_workflow.device.device_name == os.environ["AMZN_BRAKET_DEVICE_ARN"] - def testCreateAwsQAOA(self): - """ - Checks whether the dict representation of q and the workflow match - """ + # def testCreateAwsQAOA(self): + # """ + # Checks whether the dict representation of q and the workflow match + # """ - input_data_path = os.path.join( - os.environ["AMZN_BRAKET_INPUT_DIR"], "input_data/" - ) + # input_data_path = os.path.join( + # os.environ["AMZN_BRAKET_INPUT_DIR"], "input_data/" + # ) - # Create the qubo and the qaoa - q = QAOA() - q.set_device(create_device('aws', 'arn:aws:braket:::device/quantum-simulator/amazon/sv1')) - ### The following lines are needed to fool the github actions into correctly executing q.compile() !! - q.device.check_connection = MagicMock(return_value = True) - q.device.qpu_connected = True - q.device.provider_connected = True - q.device.n_qubits = self.n_qubits - q.device.backend_device = '' + # # Create the qubo and the qaoa + # q = QAOA() + # q.set_device(create_device('aws', 'arn:aws:braket:::device/quantum-simulator/amazon/sv1')) + # ### The following lines are needed to fool the github actions into correctly executing q.compile() !! + # q.device.check_connection = MagicMock(return_value = True) + # q.device.qpu_connected = True + # q.device.provider_connected = True + # q.device.n_qubits = self.n_qubits + # q.device.backend_device = '' - q.compile(self.vc) - q.dump(file_name='openqaoa_params.json', file_path=input_data_path, prepend_id=False, overwrite=True) + # q.compile(self.vc) + # q.dump(file_name='openqaoa_params.json', file_path=input_data_path, prepend_id=False, overwrite=True) - # Create an aws workflow and try check that loading the json gives the same params - job = AWSJobs(algorithm="QAOA") - job.load_compile_data() + # # Create an aws workflow and try check that loading the json gives the same params + # job = AWSJobs(algorithm="QAOA") + # job.load_compile_data() - assert job.workflow.asdict() == q.asdict() + # assert job.workflow.asdict() == q.asdict() - def testCreateAwsRecursiveQAOA(self): - """ - Checks whether the dict representation of r and the workflow match - """ + # def testCreateAwsRecursiveQAOA(self): + # """ + # Checks whether the dict representation of r and the workflow match + # """ - input_data_path = os.path.join( - os.environ["AMZN_BRAKET_INPUT_DIR"], "input_data/" - ) + # input_data_path = os.path.join( + # os.environ["AMZN_BRAKET_INPUT_DIR"], "input_data/" + # ) - # Create the qubo and the qaoa - r = RQAOA() - r.set_classical_optimizer(maxiter=3, save_intermediate=False) - r.set_device(create_device('aws', 'arn:aws:braket:::device/quantum-simulator/amazon/sv1')) - ### The following lines are needed to fool the github actions into correctly executing q.compile() !! - r.device.check_connection = MagicMock(return_value = True) - r.device.qpu_connected = True - r.device.provider_connected = True - r.device.n_qubits = self.n_qubits - r.device.backend_device = '' + # # Create the qubo and the qaoa + # r = RQAOA() + # r.set_classical_optimizer(maxiter=3, save_intermediate=False) + # r.set_device(create_device('aws', 'arn:aws:braket:::device/quantum-simulator/amazon/sv1')) + # ### The following lines are needed to fool the github actions into correctly executing q.compile() !! + # r.device.check_connection = MagicMock(return_value = True) + # r.device.qpu_connected = True + # r.device.provider_connected = True + # r.device.n_qubits = self.n_qubits + # r.device.backend_device = '' - r.compile(self.vc) - r.dump(file_name='openqaoa_params.json', file_path=input_data_path, prepend_id=False, overwrite=True) + # r.compile(self.vc) + # r.dump(file_name='openqaoa_params.json', file_path=input_data_path, prepend_id=False, overwrite=True) - # Create an aws workflow and try check that loading the json gives the same params - job = AWSJobs(algorithm="RQAOA") - job.load_compile_data() + # # Create an aws workflow and try check that loading the json gives the same params + # job = AWSJobs(algorithm="RQAOA") + # job.load_compile_data() - assert job.workflow.asdict() == r.asdict() + # assert job.workflow.asdict() == r.asdict() # @pytest.mark.qpu @@ -203,6 +203,7 @@ def testLocalJob(self): q.device.provider_connected = True q.device.n_qubits = self.n_qubits q.device.backend_device = '' + q.device.aws_region = 'us-west-1' q.compile(self.vc) q.dump(file_name='openqaoa_params.json', file_path=input_data_path, prepend_id=False, overwrite=True) @@ -234,7 +235,7 @@ def testLocalJobRQAOA(self): r.device.qpu_connected = True r.device.provider_connected = True r.device.n_qubits = self.n_qubits - q.device.backend_device = '' + r.device.backend_device = '' r.compile(self.vc) r.dump(file_name='openqaoa_params.json', file_path=input_data_path, prepend_id=False, overwrite=True) From b9d8e794ccbe7fb7c670c44e09389240e8e7a151 Mon Sep 17 00:00:00 2001 From: Leonardo Disilvestro Date: Wed, 22 Feb 2023 15:56:56 +0800 Subject: [PATCH 22/67] Add aws cli --- .github/workflows/test_dev.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/test_dev.yml b/.github/workflows/test_dev.yml index 44c233c0f..b1759c43b 100644 --- a/.github/workflows/test_dev.yml +++ b/.github/workflows/test_dev.yml @@ -30,6 +30,12 @@ jobs: uses: actions/setup-python@v3 with: python-version: ${{ matrix.python }} + - name: Setup AWS + with: + token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos + run: | + python -m pip install awscli + aws configure ${{ secrets.ACCESS_KEY }} ${{ secrets.ACCESS_KEY }} us-east-1 json - name: Build the stack run: docker-compose up -d - name: Start the rigetti machines From 8f9e3e945a01f0168654e36adb1fbc63ad85849e Mon Sep 17 00:00:00 2001 From: Leonardo Disilvestro Date: Wed, 22 Feb 2023 16:00:07 +0800 Subject: [PATCH 23/67] Update awscli --- .github/workflows/test_dev.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test_dev.yml b/.github/workflows/test_dev.yml index b1759c43b..998e6d8ff 100644 --- a/.github/workflows/test_dev.yml +++ b/.github/workflows/test_dev.yml @@ -32,10 +32,11 @@ jobs: python-version: ${{ matrix.python }} - name: Setup AWS with: - token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos + ACCESS_KEY: ${{ secrets.ACCESS_KEY }} + SECRET_ACCESS_KEY: ${{ secrets.SECRET_ACCESS_KEY }} run: | python -m pip install awscli - aws configure ${{ secrets.ACCESS_KEY }} ${{ secrets.ACCESS_KEY }} us-east-1 json + aws configure $ACCESS_KEY $SECRET_ACCESS_KEY us-east-1 json - name: Build the stack run: docker-compose up -d - name: Start the rigetti machines From 7932a63e02b2a2261f21e80f89c75494f22392c3 Mon Sep 17 00:00:00 2001 From: Leonardo Disilvestro Date: Wed, 22 Feb 2023 16:01:55 +0800 Subject: [PATCH 24/67] Update awscli --- .github/workflows/test_dev.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test_dev.yml b/.github/workflows/test_dev.yml index 998e6d8ff..e4b7c47d1 100644 --- a/.github/workflows/test_dev.yml +++ b/.github/workflows/test_dev.yml @@ -35,8 +35,8 @@ jobs: ACCESS_KEY: ${{ secrets.ACCESS_KEY }} SECRET_ACCESS_KEY: ${{ secrets.SECRET_ACCESS_KEY }} run: | - python -m pip install awscli - aws configure $ACCESS_KEY $SECRET_ACCESS_KEY us-east-1 json + python -m pip install awscli + aws configure $ACCESS_KEY $SECRET_ACCESS_KEY us-east-1 json - name: Build the stack run: docker-compose up -d - name: Start the rigetti machines From 656761f27022b5cb8c1be40a04f36a8dc1d5fe31 Mon Sep 17 00:00:00 2001 From: Leonardo Disilvestro Date: Wed, 22 Feb 2023 16:03:44 +0800 Subject: [PATCH 25/67] Update test_dev.yml --- .github/workflows/test_dev.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test_dev.yml b/.github/workflows/test_dev.yml index e4b7c47d1..02a613cd1 100644 --- a/.github/workflows/test_dev.yml +++ b/.github/workflows/test_dev.yml @@ -31,7 +31,7 @@ jobs: with: python-version: ${{ matrix.python }} - name: Setup AWS - with: + env: ACCESS_KEY: ${{ secrets.ACCESS_KEY }} SECRET_ACCESS_KEY: ${{ secrets.SECRET_ACCESS_KEY }} run: | From d148bc1c6099e276eb49e48adcd2ed74b3c1740c Mon Sep 17 00:00:00 2001 From: Leonardo Disilvestro Date: Wed, 22 Feb 2023 16:15:46 +0800 Subject: [PATCH 26/67] Update cli aws --- .github/workflows/test_dev.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/test_dev.yml b/.github/workflows/test_dev.yml index 02a613cd1..a7c8243ef 100644 --- a/.github/workflows/test_dev.yml +++ b/.github/workflows/test_dev.yml @@ -37,6 +37,10 @@ jobs: run: | python -m pip install awscli aws configure $ACCESS_KEY $SECRET_ACCESS_KEY us-east-1 json + aws configure set aws_access_key_id $ACCESS_KEY + aws configure set aws_secret_access_key $SECRET_ACCESS_KEY + aws configure set region us-west-1 + aws configure set output json - name: Build the stack run: docker-compose up -d - name: Start the rigetti machines From d645d2c67252d36934e0f1ac8b73a624628bbcd1 Mon Sep 17 00:00:00 2001 From: Leonardo Disilvestro Date: Wed, 22 Feb 2023 16:17:09 +0800 Subject: [PATCH 27/67] update cli --- .github/workflows/test_dev.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/test_dev.yml b/.github/workflows/test_dev.yml index a7c8243ef..0200b1650 100644 --- a/.github/workflows/test_dev.yml +++ b/.github/workflows/test_dev.yml @@ -36,7 +36,6 @@ jobs: SECRET_ACCESS_KEY: ${{ secrets.SECRET_ACCESS_KEY }} run: | python -m pip install awscli - aws configure $ACCESS_KEY $SECRET_ACCESS_KEY us-east-1 json aws configure set aws_access_key_id $ACCESS_KEY aws configure set aws_secret_access_key $SECRET_ACCESS_KEY aws configure set region us-west-1 From 308cef6d33ab56973b1643a891562516bd6cd6f6 Mon Sep 17 00:00:00 2001 From: Leonardo Disilvestro Date: Wed, 22 Feb 2023 16:44:43 +0800 Subject: [PATCH 28/67] add braket_api pytest flag --- pytest.ini | 1 + tests/test_qpu_braket.py | 14 +++++++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/pytest.ini b/pytest.ini index bc405ff5f..850ea25a7 100644 --- a/pytest.ini +++ b/pytest.ini @@ -4,4 +4,5 @@ markers = api: marks tests that require a coonection to a QC cloud (deselect with '-m "not api"') qvm: marks tests that require an attive Rigetti QVM and QILC compiler (deselect with '-m "not qvm"') docker_aws: marks tests that require to build aws docker (deselect with '-m "not docker_aws"') + braket_api: marks tests that require valid AWS credentials (no QPU) (deselect with '-m "not braket_api"') notebook: marks tests that run on jupyter noteboks (deselect with '-m "not notebook"') \ No newline at end of file diff --git a/tests/test_qpu_braket.py b/tests/test_qpu_braket.py index 4d841a0da..0708a9763 100644 --- a/tests/test_qpu_braket.py +++ b/tests/test_qpu_braket.py @@ -21,7 +21,7 @@ class TestingQAOABraketQPUBackend(unittest.TestCase): These tests require authentication through the AWS CLI. """ - @pytest.mark.qpu + @pytest.mark.braket_api def test_circuit_angle_assignment_qpu_backend(self): """ A tests that checks if the circuit created by the AWS Backend @@ -80,7 +80,7 @@ def test_circuit_angle_assignment_qpu_backend(self): self.assertEqual(main_circuit, qpu_circuit) - @pytest.mark.qpu + @pytest.mark.braket_api def test_circuit_angle_assignment_qpu_backend_w_hadamard(self): """ Checks for consistent if init_hadamard is set to True. @@ -140,7 +140,7 @@ def test_circuit_angle_assignment_qpu_backend_w_hadamard(self): self.assertEqual(main_circuit, qpu_circuit) - @pytest.mark.qpu + @pytest.mark.braket_api def test_prepend_circuit(self): """ Checks if prepended circuit has been prepended correctly. @@ -197,7 +197,7 @@ def test_prepend_circuit(self): self.assertEqual(main_circuit, qpu_circuit) - @pytest.mark.qpu + @pytest.mark.braket_api def test_append_circuit(self): """ Checks if appended circuit is appropriately appended to the back of the @@ -254,7 +254,7 @@ def test_append_circuit(self): self.assertEqual(main_circuit, qpu_circuit) - @pytest.mark.qpu + @pytest.mark.braket_api def test_prepend_exception(self): """ @@ -291,7 +291,7 @@ def test_prepend_exception(self): except Exception as e: self.assertEqual(str(e), "Cannot attach a bigger circuit to the QAOA routine") - @pytest.mark.qpu + @pytest.mark.braket_api def test_exceptions_in_init(self): """ @@ -348,7 +348,7 @@ def test_exceptions_in_init(self): QAOAAWSQPUBackend(qaoa_descriptor, aws_device, shots, None, None, True, 1.) - @pytest.mark.qpu + @pytest.mark.braket_api def test_remote_qubit_overflow(self): """ From 096a612264b84fd302eb47e0078316940b0f3412 Mon Sep 17 00:00:00 2001 From: Leonardo Disilvestro Date: Wed, 22 Feb 2023 19:05:54 +0800 Subject: [PATCH 29/67] Update braket_api marker --- .github/workflows/test_dev.yml | 3 +-- tests/test_qpu_devices.py | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/.github/workflows/test_dev.yml b/.github/workflows/test_dev.yml index 0200b1650..cdeff45db 100644 --- a/.github/workflows/test_dev.yml +++ b/.github/workflows/test_dev.yml @@ -55,12 +55,11 @@ jobs: pip install .[tests] pip install ipykernel - - name: Run tests run: | source env/bin/activate ipython kernel install --name "env" --user - python -m pytest -v -m 'not (qpu or api)' --cov --cov-report=xml:coverage.xml + python -m pytest -v -m '(docker_aws or braket_api)' --cov --cov-report=xml:coverage.xml - name: Upload coverage reports to Codecov with GitHub Action uses: codecov/codecov-action@v3 diff --git a/tests/test_qpu_devices.py b/tests/test_qpu_devices.py index a27b96b1b..a61a6ec21 100644 --- a/tests/test_qpu_devices.py +++ b/tests/test_qpu_devices.py @@ -160,7 +160,6 @@ def test_unsupported_device_names(self): class TestingDeviceAWS(unittest.TestCase): - """These tests check the Object used to access AWS Braket and their available QPUs can be established. @@ -168,7 +167,7 @@ class TestingDeviceAWS(unittest.TestCase): details provided are correct/valid with AWS Braket. """ - @pytest.mark.api + @pytest.mark.braket_api def test_changing_aws_region(self): device_obj = DeviceAWS(device_name='arn:aws:braket:::device/quantum-simulator/amazon/sv1') @@ -185,7 +184,7 @@ def test_changing_aws_region(self): self.assertEqual('us-west-1', custom_region) - @pytest.mark.api + @pytest.mark.braket_api def test_changing_s3_bucket_names(self): device_obj = DeviceAWS(device_name='arn:aws:braket:::device/quantum-simulator/amazon/sv1', s3_bucket_name='random_new_name') @@ -195,7 +194,7 @@ def test_changing_s3_bucket_names(self): self.assertEqual('random_new_name', custom_bucket) - @pytest.mark.api + @pytest.mark.braket_api def test_check_connection_provider_no_backend_provided_credentials(self): """ @@ -211,7 +210,7 @@ def test_check_connection_provider_no_backend_provided_credentials(self): self.assertEqual(device_obj.qpu_connected, None) - @pytest.mark.api + @pytest.mark.braket_api def test_check_connection_provider_right_backend_provided_credentials(self): """ @@ -233,7 +232,7 @@ def test_check_connection_provider_right_backend_provided_credentials(self): self.assertEqual(device_obj.qpu_connected, True) - @pytest.mark.api + @pytest.mark.braket_api def test_check_connection_provider_wrong_backend_provided_credentials(self): """ From 1107294a381209fbac83a5283fbf2a2842df6402 Mon Sep 17 00:00:00 2001 From: Leonardo Disilvestro Date: Wed, 22 Feb 2023 20:33:41 +0800 Subject: [PATCH 30/67] Update docker instructions --- docker-compose.yml | 2 +- tests/test_aws_managed_jobs.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index ff6a500cc..694098880 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,6 +1,6 @@ version: '3' services: - oq-braket: + amazon-braket-oq-dev: container_name: amazon-braket-oq-dev build: . qvm: diff --git a/tests/test_aws_managed_jobs.py b/tests/test_aws_managed_jobs.py index b4d319ddb..dd48e7af6 100644 --- a/tests/test_aws_managed_jobs.py +++ b/tests/test_aws_managed_jobs.py @@ -203,7 +203,7 @@ def testLocalJob(self): q.device.provider_connected = True q.device.n_qubits = self.n_qubits q.device.backend_device = '' - q.device.aws_region = 'us-west-1' + q.device.aws_region = 'us-east-1' q.compile(self.vc) q.dump(file_name='openqaoa_params.json', file_path=input_data_path, prepend_id=False, overwrite=True) @@ -236,6 +236,7 @@ def testLocalJobRQAOA(self): r.device.provider_connected = True r.device.n_qubits = self.n_qubits r.device.backend_device = '' + q.device.aws_region = 'us-east-1' r.compile(self.vc) r.dump(file_name='openqaoa_params.json', file_path=input_data_path, prepend_id=False, overwrite=True) From b30567137321b8bc4b3319255b8ced627f5f3b7e Mon Sep 17 00:00:00 2001 From: Leonardo Disilvestro Date: Wed, 22 Feb 2023 22:14:17 +0800 Subject: [PATCH 31/67] Update docker --- .github/workflows/test_dev.yml | 8 +++----- docker-compose.yml | 23 +++++++++++++++++++---- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/.github/workflows/test_dev.yml b/.github/workflows/test_dev.yml index cdeff45db..20a3a749c 100644 --- a/.github/workflows/test_dev.yml +++ b/.github/workflows/test_dev.yml @@ -41,11 +41,10 @@ jobs: aws configure set region us-west-1 aws configure set output json - name: Build the stack - run: docker-compose up -d - - name: Start the rigetti machines run: | - docker run --rm -id -p 5000:5000 rigetti/qvm:latest -S - docker run --rm -id -p 5555:5555 rigetti/quilc:latest -P -S + docker network create local_bridge + docker build -t amazon-braket-oq-dev . + docker-compose up -d - name: Install OpenQAOA run: | python -m pip install --user virtualenv @@ -54,7 +53,6 @@ jobs: python -m pip install --upgrade pip pip install .[tests] pip install ipykernel - - name: Run tests run: | source env/bin/activate diff --git a/docker-compose.yml b/docker-compose.yml index 694098880..db77e2d29 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,12 +1,27 @@ version: '3' + +networks: + local_bridge: + external: true + services: amazon-braket-oq-dev: - container_name: amazon-braket-oq-dev - build: . + image: amazon-braket-oq-dev + networks: + - local_bridge qvm: container_name: qvm image: rigetti/qvm:latest + command: ["-S"] + networks: + - local_bridge + ports: + - 5000:5000 quilc: container_name: quilc - image: rigetti/quilc:latest - + image: rigetti/quilc:latest + command: ["-S"] + networks: + - local_bridge + ports: + - 5555:5555 From c548da188ada048bfbcbd2b4dde9f43591b9727e Mon Sep 17 00:00:00 2001 From: Leonardo Disilvestro Date: Wed, 22 Feb 2023 22:37:38 +0800 Subject: [PATCH 32/67] update tests --- .github/workflows/test_dev.yml | 2 +- docker-compose.yml | 2 +- tests/test_aws_managed_jobs.py | 2 +- tests/test_qpu_devices.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test_dev.yml b/.github/workflows/test_dev.yml index 20a3a749c..e9baf9917 100644 --- a/.github/workflows/test_dev.yml +++ b/.github/workflows/test_dev.yml @@ -57,7 +57,7 @@ jobs: run: | source env/bin/activate ipython kernel install --name "env" --user - python -m pytest -v -m '(docker_aws or braket_api)' --cov --cov-report=xml:coverage.xml + python -m pytest -v -m '(not qpu or api)' --cov --cov-report=xml:coverage.xml - name: Upload coverage reports to Codecov with GitHub Action uses: codecov/codecov-action@v3 diff --git a/docker-compose.yml b/docker-compose.yml index db77e2d29..940dddc4b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -20,7 +20,7 @@ services: quilc: container_name: quilc image: rigetti/quilc:latest - command: ["-S"] + command: ["-P", "-S" ] networks: - local_bridge ports: diff --git a/tests/test_aws_managed_jobs.py b/tests/test_aws_managed_jobs.py index dd48e7af6..9ea913db8 100644 --- a/tests/test_aws_managed_jobs.py +++ b/tests/test_aws_managed_jobs.py @@ -236,7 +236,7 @@ def testLocalJobRQAOA(self): r.device.provider_connected = True r.device.n_qubits = self.n_qubits r.device.backend_device = '' - q.device.aws_region = 'us-east-1' + r.device.aws_region = 'us-east-1' r.compile(self.vc) r.dump(file_name='openqaoa_params.json', file_path=input_data_path, prepend_id=False, overwrite=True) diff --git a/tests/test_qpu_devices.py b/tests/test_qpu_devices.py index a61a6ec21..bb78a0358 100644 --- a/tests/test_qpu_devices.py +++ b/tests/test_qpu_devices.py @@ -170,7 +170,7 @@ class TestingDeviceAWS(unittest.TestCase): @pytest.mark.braket_api def test_changing_aws_region(self): - device_obj = DeviceAWS(device_name='arn:aws:braket:::device/quantum-simulator/amazon/sv1') + device_obj = DeviceAWS(device_name='arn:aws:braket:::device/quantum-simulator/amazon/sv1', aws_region='us-east-1') device_obj.check_connection() default_region = device_obj.aws_region From 201b1f31fb6200147d116a30f80124c004f8e68b Mon Sep 17 00:00:00 2001 From: Leonardo Disilvestro Date: Thu, 23 Feb 2023 11:34:35 +0800 Subject: [PATCH 33/67] update ibmq and az tests --- .github/workflows/test_dev.yml | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/.github/workflows/test_dev.yml b/.github/workflows/test_dev.yml index e9baf9917..1314355d2 100644 --- a/.github/workflows/test_dev.yml +++ b/.github/workflows/test_dev.yml @@ -30,6 +30,25 @@ jobs: uses: actions/setup-python@v3 with: python-version: ${{ matrix.python }} + - name: Install OpenQAOA + run: | + python -m pip install --user virtualenv + python -m venv env + source env/bin/activate + python -m pip install --upgrade pip + pip install .[tests] + pip install ipykernel + - name: Setup IBMQ account + env: + IBMQ_TOKEN: ${{ secrets.IBMQ_TOKEN }} + run: | + python -c'from qiskit import IBMQ; IBMQ.save_account(os.environ['IBMQ_TOKEN'])' + - 'Az CLI login' + uses: azure/login@v1 + with: + client-id: ${{ secrets.AZURE_CLIENT_ID }} + tenant-id: ${{ secrets.AZURE_TENANT_ID }} + subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} - name: Setup AWS env: ACCESS_KEY: ${{ secrets.ACCESS_KEY }} @@ -45,14 +64,6 @@ jobs: docker network create local_bridge docker build -t amazon-braket-oq-dev . docker-compose up -d - - name: Install OpenQAOA - run: | - python -m pip install --user virtualenv - python -m venv env - source env/bin/activate - python -m pip install --upgrade pip - pip install .[tests] - pip install ipykernel - name: Run tests run: | source env/bin/activate From f9c231224330d72f95fce5d9250b59e53f374858 Mon Sep 17 00:00:00 2001 From: Leonardo Disilvestro Date: Thu, 23 Feb 2023 11:37:16 +0800 Subject: [PATCH 34/67] Update tests --- tests/test_aws_managed_jobs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_aws_managed_jobs.py b/tests/test_aws_managed_jobs.py index 49fe7ef07..a832f3cba 100644 --- a/tests/test_aws_managed_jobs.py +++ b/tests/test_aws_managed_jobs.py @@ -137,7 +137,7 @@ def testLocalJobRQAOA(self): input_data={"input_data": input_data_path}, ) - assert (job.state() == 'COMPLETED') and (job.result() != None) == True + assert (job.state() == 'COMPLETED') and (job.result() != None) == True if __name__ == "__main__": From d9dd66a6691bcdf19fc4b7c010f1f306eba13bc6 Mon Sep 17 00:00:00 2001 From: Leonardo Disilvestro Date: Thu, 23 Feb 2023 11:38:06 +0800 Subject: [PATCH 35/67] Update test_dev.yml --- .github/workflows/test_dev.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test_dev.yml b/.github/workflows/test_dev.yml index 1314355d2..4956b836d 100644 --- a/.github/workflows/test_dev.yml +++ b/.github/workflows/test_dev.yml @@ -43,7 +43,7 @@ jobs: IBMQ_TOKEN: ${{ secrets.IBMQ_TOKEN }} run: | python -c'from qiskit import IBMQ; IBMQ.save_account(os.environ['IBMQ_TOKEN'])' - - 'Az CLI login' + - name: 'Az CLI login' uses: azure/login@v1 with: client-id: ${{ secrets.AZURE_CLIENT_ID }} From 8415d9e269a52d688546963fa5de03333c763bce Mon Sep 17 00:00:00 2001 From: Leonardo Disilvestro Date: Thu, 23 Feb 2023 11:41:29 +0800 Subject: [PATCH 36/67] Update az --- .github/workflows/test_dev.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/test_dev.yml b/.github/workflows/test_dev.yml index 4956b836d..439d4a2db 100644 --- a/.github/workflows/test_dev.yml +++ b/.github/workflows/test_dev.yml @@ -49,6 +49,9 @@ jobs: client-id: ${{ secrets.AZURE_CLIENT_ID }} tenant-id: ${{ secrets.AZURE_TENANT_ID }} subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} + enable-AzPSSession: true + run: + az login - name: Setup AWS env: ACCESS_KEY: ${{ secrets.ACCESS_KEY }} From f95e0f1c9d9417fe5ec31432426cda24b58c47e0 Mon Sep 17 00:00:00 2001 From: Leonardo Disilvestro Date: Thu, 23 Feb 2023 11:42:49 +0800 Subject: [PATCH 37/67] Update test_dev.yml --- .github/workflows/test_dev.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test_dev.yml b/.github/workflows/test_dev.yml index 439d4a2db..25c2f73cb 100644 --- a/.github/workflows/test_dev.yml +++ b/.github/workflows/test_dev.yml @@ -41,8 +41,8 @@ jobs: - name: Setup IBMQ account env: IBMQ_TOKEN: ${{ secrets.IBMQ_TOKEN }} - run: | - python -c'from qiskit import IBMQ; IBMQ.save_account(os.environ['IBMQ_TOKEN'])' + run: + python -c'from qiskit import IBMQ; IBMQ.save_account(os.environ['IBMQ_TOKEN'])' - name: 'Az CLI login' uses: azure/login@v1 with: From 3a5e5c8a05a6053191e5aa0f9cebcd49a4c1ddf7 Mon Sep 17 00:00:00 2001 From: Leonardo Disilvestro Date: Thu, 23 Feb 2023 11:45:01 +0800 Subject: [PATCH 38/67] Update az --- .github/workflows/test_dev.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/test_dev.yml b/.github/workflows/test_dev.yml index 25c2f73cb..bd6ce7ea4 100644 --- a/.github/workflows/test_dev.yml +++ b/.github/workflows/test_dev.yml @@ -50,8 +50,6 @@ jobs: tenant-id: ${{ secrets.AZURE_TENANT_ID }} subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} enable-AzPSSession: true - run: - az login - name: Setup AWS env: ACCESS_KEY: ${{ secrets.ACCESS_KEY }} From 0d798e2392b5494459ceae7782d310d4a37ac959 Mon Sep 17 00:00:00 2001 From: Leonardo Disilvestro Date: Thu, 23 Feb 2023 11:48:29 +0800 Subject: [PATCH 39/67] Update ibm yml --- .github/workflows/test_dev.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test_dev.yml b/.github/workflows/test_dev.yml index bd6ce7ea4..2eeaa70cb 100644 --- a/.github/workflows/test_dev.yml +++ b/.github/workflows/test_dev.yml @@ -41,7 +41,8 @@ jobs: - name: Setup IBMQ account env: IBMQ_TOKEN: ${{ secrets.IBMQ_TOKEN }} - run: + run: | + source env/bin/activate python -c'from qiskit import IBMQ; IBMQ.save_account(os.environ['IBMQ_TOKEN'])' - name: 'Az CLI login' uses: azure/login@v1 From aae34c004e205a7ba40e026d6a31092f86c0d187 Mon Sep 17 00:00:00 2001 From: Leonardo Disilvestro Date: Thu, 23 Feb 2023 11:51:15 +0800 Subject: [PATCH 40/67] Add import os to tests --- .github/workflows/test_dev.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test_dev.yml b/.github/workflows/test_dev.yml index 2eeaa70cb..9195f6f12 100644 --- a/.github/workflows/test_dev.yml +++ b/.github/workflows/test_dev.yml @@ -43,7 +43,7 @@ jobs: IBMQ_TOKEN: ${{ secrets.IBMQ_TOKEN }} run: | source env/bin/activate - python -c'from qiskit import IBMQ; IBMQ.save_account(os.environ['IBMQ_TOKEN'])' + python -c'from qiskit import IBMQ; import os; IBMQ.save_account(os.environ['IBMQ_TOKEN'])' - name: 'Az CLI login' uses: azure/login@v1 with: From 36e4e25cbda615f74d10443f6684de58c1439746 Mon Sep 17 00:00:00 2001 From: Leonardo Disilvestro Date: Thu, 23 Feb 2023 12:45:01 +0800 Subject: [PATCH 41/67] Test --- .github/workflows/test_dev.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test_dev.yml b/.github/workflows/test_dev.yml index 9195f6f12..d1bf7362b 100644 --- a/.github/workflows/test_dev.yml +++ b/.github/workflows/test_dev.yml @@ -42,6 +42,7 @@ jobs: env: IBMQ_TOKEN: ${{ secrets.IBMQ_TOKEN }} run: | + IBMQ_TOKEN=$IBMQ_TOKEN source env/bin/activate python -c'from qiskit import IBMQ; import os; IBMQ.save_account(os.environ['IBMQ_TOKEN'])' - name: 'Az CLI login' From 98a911679ac74d45700e7937525989a84bb0051a Mon Sep 17 00:00:00 2001 From: Leonardo Disilvestro Date: Thu, 23 Feb 2023 12:51:55 +0800 Subject: [PATCH 42/67] Update --- .github/workflows/test_dev.yml | 78 +++++++++++++++++----------------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/.github/workflows/test_dev.yml b/.github/workflows/test_dev.yml index d1bf7362b..352a98509 100644 --- a/.github/workflows/test_dev.yml +++ b/.github/workflows/test_dev.yml @@ -44,7 +44,7 @@ jobs: run: | IBMQ_TOKEN=$IBMQ_TOKEN source env/bin/activate - python -c'from qiskit import IBMQ; import os; IBMQ.save_account(os.environ['IBMQ_TOKEN'])' + python -c'from qiskit import IBMQ; import os; IBMQ.save_account(os.environ.get("IBMQ_TOKEN"))' - name: 'Az CLI login' uses: azure/login@v1 with: @@ -79,44 +79,44 @@ jobs: token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos files: ./coverage.xml - docs: - runs-on: ubuntu-latest - steps: - - name: Check out openqaoa - uses: actions/checkout@v3 - with: - ref: ${{ github.event.pull_request.head.sha }} - - name: Set up Python - uses: actions/setup-python@v3 - with: - python-version: 3.8 + # docs: + # runs-on: ubuntu-latest + # steps: + # - name: Check out openqaoa + # uses: actions/checkout@v3 + # with: + # ref: ${{ github.event.pull_request.head.sha }} + # - name: Set up Python + # uses: actions/setup-python@v3 + # with: + # python-version: 3.8 - - name: Install OpenQAOA - run: | - python -m pip install --upgrade pip - pip install .[docs] + # - name: Install OpenQAOA + # run: | + # python -m pip install --upgrade pip + # pip install .[docs] - - name: Install qvm - run: | - find /usr/lib -name "libffi.so*" - sudo ln -s /usr/lib/x86_64-linux-gnu/libffi.so /usr/lib/x86_64-linux-gnu/libffi.so.6 - wget -q https://downloads.rigetti.com/qcs-sdk/forest-sdk-2.23.0-linux-deb.tar.bz2 - tar -xf forest-sdk-2.23.0-linux-deb.tar.bz2 - cd forest-sdk-2.23.0-linux-deb/ - sudo apt-get update - sudo apt-get install -y screen libblas-dev libblas3 libgfortran5 liblapack-dev liblapack3 - sudo ./forest-sdk-2.23.0-linux-deb.run - qvm --version - quilc --version - echo "Starting qvm and quilc" - screen -d -m qvm -S - screen -d -m quilc -S - cd .. + # - name: Install qvm + # run: | + # find /usr/lib -name "libffi.so*" + # sudo ln -s /usr/lib/x86_64-linux-gnu/libffi.so /usr/lib/x86_64-linux-gnu/libffi.so.6 + # wget -q https://downloads.rigetti.com/qcs-sdk/forest-sdk-2.23.0-linux-deb.tar.bz2 + # tar -xf forest-sdk-2.23.0-linux-deb.tar.bz2 + # cd forest-sdk-2.23.0-linux-deb/ + # sudo apt-get update + # sudo apt-get install -y screen libblas-dev libblas3 libgfortran5 liblapack-dev liblapack3 + # sudo ./forest-sdk-2.23.0-linux-deb.run + # qvm --version + # quilc --version + # echo "Starting qvm and quilc" + # screen -d -m qvm -S + # screen -d -m quilc -S + # cd .. - - name: Build and test Sphinx docs - run: | - sudo apt-get install pandoc - mkdir ./docs/source/notebooks - cp ./examples/*.ipynb ./docs/source/notebooks/ - cd docs/ - make html SPHINXOPTS="-W --keep-going" + # - name: Build and test Sphinx docs + # run: | + # sudo apt-get install pandoc + # mkdir ./docs/source/notebooks + # cp ./examples/*.ipynb ./docs/source/notebooks/ + # cd docs/ + # make html SPHINXOPTS="-W --keep-going" From 3fbe0f9c46d377816a9663eb806b40daadc6466f Mon Sep 17 00:00:00 2001 From: Leonardo Disilvestro Date: Thu, 23 Feb 2023 12:59:34 +0800 Subject: [PATCH 43/67] Update az --- .github/workflows/test_dev.yml | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test_dev.yml b/.github/workflows/test_dev.yml index 352a98509..702bfe97c 100644 --- a/.github/workflows/test_dev.yml +++ b/.github/workflows/test_dev.yml @@ -45,13 +45,9 @@ jobs: IBMQ_TOKEN=$IBMQ_TOKEN source env/bin/activate python -c'from qiskit import IBMQ; import os; IBMQ.save_account(os.environ.get("IBMQ_TOKEN"))' - - name: 'Az CLI login' - uses: azure/login@v1 - with: - client-id: ${{ secrets.AZURE_CLIENT_ID }} - tenant-id: ${{ secrets.AZURE_TENANT_ID }} - subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} - enable-AzPSSession: true + - name: Set up az cli + env: # as an environment variable + credentials: ${{ secrets.AZURE_CREDENTIALS }} - name: Setup AWS env: ACCESS_KEY: ${{ secrets.ACCESS_KEY }} From 5febbac1cad54e280f74a4233a009cdb80d3a0c0 Mon Sep 17 00:00:00 2001 From: Leonardo Disilvestro Date: Thu, 23 Feb 2023 13:00:30 +0800 Subject: [PATCH 44/67] Update az --- .github/workflows/test_dev.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test_dev.yml b/.github/workflows/test_dev.yml index 702bfe97c..35bc57c33 100644 --- a/.github/workflows/test_dev.yml +++ b/.github/workflows/test_dev.yml @@ -46,7 +46,7 @@ jobs: source env/bin/activate python -c'from qiskit import IBMQ; import os; IBMQ.save_account(os.environ.get("IBMQ_TOKEN"))' - name: Set up az cli - env: # as an environment variable + with: credentials: ${{ secrets.AZURE_CREDENTIALS }} - name: Setup AWS env: From f3b8103116fa739ba5be31541ae864ab642a6591 Mon Sep 17 00:00:00 2001 From: Leonardo Disilvestro Date: Thu, 23 Feb 2023 13:03:55 +0800 Subject: [PATCH 45/67] update az --- .github/workflows/test_dev.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test_dev.yml b/.github/workflows/test_dev.yml index 35bc57c33..ffd1abc9f 100644 --- a/.github/workflows/test_dev.yml +++ b/.github/workflows/test_dev.yml @@ -49,9 +49,11 @@ jobs: with: credentials: ${{ secrets.AZURE_CREDENTIALS }} - name: Setup AWS - env: + with: ACCESS_KEY: ${{ secrets.ACCESS_KEY }} SECRET_ACCESS_KEY: ${{ secrets.SECRET_ACCESS_KEY }} + run: + az login run: | python -m pip install awscli aws configure set aws_access_key_id $ACCESS_KEY From 2cea6b78c2dd0cbb3d249dc490f37a1f26788503 Mon Sep 17 00:00:00 2001 From: Leonardo Disilvestro Date: Thu, 23 Feb 2023 13:04:30 +0800 Subject: [PATCH 46/67] update az --- .github/workflows/test_dev.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test_dev.yml b/.github/workflows/test_dev.yml index ffd1abc9f..06439cc3e 100644 --- a/.github/workflows/test_dev.yml +++ b/.github/workflows/test_dev.yml @@ -49,7 +49,7 @@ jobs: with: credentials: ${{ secrets.AZURE_CREDENTIALS }} - name: Setup AWS - with: + env: ACCESS_KEY: ${{ secrets.ACCESS_KEY }} SECRET_ACCESS_KEY: ${{ secrets.SECRET_ACCESS_KEY }} run: From 95e4e90d7e5e5898980b6c379b4b4bde60159375 Mon Sep 17 00:00:00 2001 From: Leonardo Disilvestro Date: Thu, 23 Feb 2023 13:05:09 +0800 Subject: [PATCH 47/67] update az --- .github/workflows/test_dev.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test_dev.yml b/.github/workflows/test_dev.yml index 06439cc3e..c8dc9119d 100644 --- a/.github/workflows/test_dev.yml +++ b/.github/workflows/test_dev.yml @@ -48,12 +48,12 @@ jobs: - name: Set up az cli with: credentials: ${{ secrets.AZURE_CREDENTIALS }} + run: + az login - name: Setup AWS - env: + with: ACCESS_KEY: ${{ secrets.ACCESS_KEY }} SECRET_ACCESS_KEY: ${{ secrets.SECRET_ACCESS_KEY }} - run: - az login run: | python -m pip install awscli aws configure set aws_access_key_id $ACCESS_KEY From 8d6e3ff366b42d4df7d236770a7001c7ecf99402 Mon Sep 17 00:00:00 2001 From: Leonardo Disilvestro Date: Thu, 23 Feb 2023 13:05:42 +0800 Subject: [PATCH 48/67] update az --- .github/workflows/test_dev.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test_dev.yml b/.github/workflows/test_dev.yml index c8dc9119d..44c2f3319 100644 --- a/.github/workflows/test_dev.yml +++ b/.github/workflows/test_dev.yml @@ -46,12 +46,12 @@ jobs: source env/bin/activate python -c'from qiskit import IBMQ; import os; IBMQ.save_account(os.environ.get("IBMQ_TOKEN"))' - name: Set up az cli - with: + env: credentials: ${{ secrets.AZURE_CREDENTIALS }} run: az login - name: Setup AWS - with: + env: ACCESS_KEY: ${{ secrets.ACCESS_KEY }} SECRET_ACCESS_KEY: ${{ secrets.SECRET_ACCESS_KEY }} run: | From f71b8a1030f9c617eff4e455dc2ec45c5dacea6e Mon Sep 17 00:00:00 2001 From: Leonardo Disilvestro Date: Thu, 23 Feb 2023 13:06:41 +0800 Subject: [PATCH 49/67] update az --- .github/workflows/test_dev.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test_dev.yml b/.github/workflows/test_dev.yml index 44c2f3319..9a11b2c1e 100644 --- a/.github/workflows/test_dev.yml +++ b/.github/workflows/test_dev.yml @@ -44,7 +44,7 @@ jobs: run: | IBMQ_TOKEN=$IBMQ_TOKEN source env/bin/activate - python -c'from qiskit import IBMQ; import os; IBMQ.save_account(os.environ.get("IBMQ_TOKEN"))' + python -c'from qiskit import IBMQ; import os; IBMQ.save_account(os.environ.get("IBMQ_TOKEN"))' - name: Set up az cli env: credentials: ${{ secrets.AZURE_CREDENTIALS }} From 11021b94abb46c83e680c79846d2b2a7bfc3dfb2 Mon Sep 17 00:00:00 2001 From: Leonardo Disilvestro Date: Thu, 23 Feb 2023 13:10:21 +0800 Subject: [PATCH 50/67] update az --- .github/workflows/test_dev.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test_dev.yml b/.github/workflows/test_dev.yml index 9a11b2c1e..b662d4b56 100644 --- a/.github/workflows/test_dev.yml +++ b/.github/workflows/test_dev.yml @@ -30,6 +30,11 @@ jobs: uses: actions/setup-python@v3 with: python-version: ${{ matrix.python }} + - name: Set up az cli + env: + credentials: ${{ secrets.AZURE_CREDENTIALS }} + run: + az login --identity - name: Install OpenQAOA run: | python -m pip install --user virtualenv @@ -44,12 +49,7 @@ jobs: run: | IBMQ_TOKEN=$IBMQ_TOKEN source env/bin/activate - python -c'from qiskit import IBMQ; import os; IBMQ.save_account(os.environ.get("IBMQ_TOKEN"))' - - name: Set up az cli - env: - credentials: ${{ secrets.AZURE_CREDENTIALS }} - run: - az login + python -c'from qiskit import IBMQ; import os; IBMQ.save_account(os.environ.get("IBMQ_TOKEN"))' - name: Setup AWS env: ACCESS_KEY: ${{ secrets.ACCESS_KEY }} @@ -60,7 +60,7 @@ jobs: aws configure set aws_secret_access_key $SECRET_ACCESS_KEY aws configure set region us-west-1 aws configure set output json - - name: Build the stack + - name: Build the docker stack run: | docker network create local_bridge docker build -t amazon-braket-oq-dev . From 0180c17fe151a12638093210d2b248bc9d7b6e2f Mon Sep 17 00:00:00 2001 From: Leonardo Disilvestro Date: Thu, 23 Feb 2023 13:18:13 +0800 Subject: [PATCH 51/67] add az cli --- .github/workflows/test_dev.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test_dev.yml b/.github/workflows/test_dev.yml index b662d4b56..5239d183b 100644 --- a/.github/workflows/test_dev.yml +++ b/.github/workflows/test_dev.yml @@ -30,11 +30,10 @@ jobs: uses: actions/setup-python@v3 with: python-version: ${{ matrix.python }} - - name: Set up az cli - env: - credentials: ${{ secrets.AZURE_CREDENTIALS }} - run: - az login --identity + - name: Log in with Azure + uses: azure/login@v1 + with: + creds: '${{ secrets.AZURE_CREDENTIALS }}' - name: Install OpenQAOA run: | python -m pip install --user virtualenv From 2406a70a26efabaf611ac0425b8ae3586dc0f612 Mon Sep 17 00:00:00 2001 From: Leonardo Disilvestro Date: Thu, 23 Feb 2023 15:35:12 +0800 Subject: [PATCH 52/67] update tests --- .github/workflows/test_dev.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test_dev.yml b/.github/workflows/test_dev.yml index 5239d183b..fec4947dd 100644 --- a/.github/workflows/test_dev.yml +++ b/.github/workflows/test_dev.yml @@ -68,7 +68,7 @@ jobs: run: | source env/bin/activate ipython kernel install --name "env" --user - python -m pytest -v -m '(not qpu or api)' --cov --cov-report=xml:coverage.xml + pytest tests/ -v -m '(not qpu or api)' --cov --cov-report=xml:coverage.xml - name: Upload coverage reports to Codecov with GitHub Action uses: codecov/codecov-action@v3 From 41afda55ed2798ccd278ece3f165fb65b37b8ecd Mon Sep 17 00:00:00 2001 From: Leonardo Disilvestro Date: Thu, 23 Feb 2023 16:01:40 +0800 Subject: [PATCH 53/67] Change dockerfile --- .github/workflows/test_dev.yml | 1 + Dockerfile | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test_dev.yml b/.github/workflows/test_dev.yml index fec4947dd..689d5ea4a 100644 --- a/.github/workflows/test_dev.yml +++ b/.github/workflows/test_dev.yml @@ -61,6 +61,7 @@ jobs: aws configure set output json - name: Build the docker stack run: | + docker login -u AWS -p $(aws ecr get-login-password --region us-east-1) 292282985366.dkr.ecr.us-east-1.amazonaws.com docker network create local_bridge docker build -t amazon-braket-oq-dev . docker-compose up -d diff --git a/Dockerfile b/Dockerfile index 13a650976..3697245e9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1 +1,7 @@ -FROM qlds/openqaoa-braket-jobs +FROM 292282985366.dkr.ecr.us-east-1.amazonaws.com/amazon-braket-pytorch-jobs:1.9.1-gpu-py38-cu111-ubuntu20.04 + +RUN mkdir -p /openqaoa + +ADD ./ /openqaoa/ + +RUN pip3 install /openqaoa/. From d52c366fba88a008d0a6dca96c106a62f2f11022 Mon Sep 17 00:00:00 2001 From: "shahidee44@hotmail.com" Date: Thu, 23 Feb 2023 17:30:18 +0000 Subject: [PATCH 54/67] Update unittests, notebooks and error messages --- examples/12_testing_azure.ipynb | 45 ++++++++++- src/openqaoa-azure/backends/devices.py | 4 +- .../backends/qaoa_qiskit_qpu.py | 16 +--- tests/test_qpu_devices.py | 20 ++--- tests/test_qpu_qiskit.py | 77 ++++++++++++++++++- tests/test_workflows.py | 8 ++ 6 files changed, 144 insertions(+), 26 deletions(-) diff --git a/examples/12_testing_azure.ipynb b/examples/12_testing_azure.ipynb index 6ac70f581..ba785b88e 100644 --- a/examples/12_testing_azure.ipynb +++ b/examples/12_testing_azure.ipynb @@ -17,7 +17,9 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Default QAOA on the IonQ Emulator" + "## Default QAOA on the IonQ Emulator\n", + "\n", + "Before using OpenQAOA with Azure quantum, you will be required to log in to your azure account through the Azure CLI. This can be done via `az login` in your command line terminal after installing the Azure CLI. After following the steps required for authentication, you will be able to use the Azure backend with OpenQAOA!" ] }, { @@ -37,6 +39,15 @@ "cell_type": "markdown", "metadata": {}, "source": [ + "In order to create the Azure Device for OpenQAOA, you have to provide a valid resource ID that points to the Workspace that contains access to the QPU (and emulator) providers, `resource_id`, and the location of the azure server hosting that workspace, `az_location`." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Once you've created the Azure Device, you can use the OpenQAOA workflow like you normally do for other backends. (Only this time you pass in the Azure Device instead!)\n", + "\n", "Let's generate a sample problem, and solve it using an OpenQAOA workflow" ] }, @@ -209,6 +220,13 @@ "q.result.optimized" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "And that's it! You've completed your first OpenQAOA Workflow run on the Azure platform with the IonQ Emulator." + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -216,6 +234,13 @@ "## A more advanced QAOA workflow on the Rigetti QVM" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Let's try another QAOA Workflow, but this time on the Rigetti QVM hosted on Azure." + ] + }, { "cell_type": "code", "execution_count": 17, @@ -366,6 +391,13 @@ "## RQAOA on a QVM" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The RQAOA Workflow also works with Azure. (Note: RQAOA requires multiple loops of the QAOA algorithm, this algorithm can require many executions on the QPU. Thus, it will take a while!)" + ] + }, { "cell_type": "code", "execution_count": 22, @@ -1643,6 +1675,17 @@ "source": [ "r.result" ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "And there you have it! You've just performed QAOA and RQAOA on Emulators hosted by Azure.\n", + "Azure Quantum also contains QPUs hosted by hardware providers like Rigetti and IonQ. \n", + "We can't wait to see what you can do with OpenQAOA and this new backend!\n", + "If you find something that you'd like to have as a feature or a bug while using the Azure backend. \n", + "Raise an issue and we will keep in touch!" + ] } ], "metadata": { diff --git a/src/openqaoa-azure/backends/devices.py b/src/openqaoa-azure/backends/devices.py index bcaa8c089..e079784c9 100644 --- a/src/openqaoa-azure/backends/devices.py +++ b/src/openqaoa-azure/backends/devices.py @@ -28,9 +28,9 @@ def __init__(self, device_name: str, resource_id: str, az_location: str): device_name: `str` The name of the Azure remote QPU/Simulator to be used resource_id: `str` - resource_id + The resource_id of the Workplace az_location: `str` - az_location + The location of the Azure Workplace. e.g. "us-west-1" """ self.resource_id = resource_id diff --git a/src/openqaoa-qiskit/backends/qaoa_qiskit_qpu.py b/src/openqaoa-qiskit/backends/qaoa_qiskit_qpu.py index 53c3ef112..f4e26b38c 100644 --- a/src/openqaoa-qiskit/backends/qaoa_qiskit_qpu.py +++ b/src/openqaoa-qiskit/backends/qaoa_qiskit_qpu.py @@ -89,19 +89,11 @@ def __init__( False, None, ]: - if type(self.device).__name__ == "DeviceAzure": - raise Exception( - "Connection to Azure was made. Error connecting to the specified backend." - ) - else: - raise Exception( - "Connection to IBMQ was made. Error connecting to the specified backend." - ) + raise Exception("Connection to {} was made. Error connecting to the specified backend.".format(self.device.device_location.upper())) + else: - if type(self.device).__name__ == "DeviceAzure": - raise Exception("Error connecting to Azure.") - else: - raise Exception("Error connecting to IBMQ.") + + raise Exception("Error connecting to {}.".format(self.device.device_location.upper())) if self.device.n_qubits < self.n_qubits: raise Exception( diff --git a/tests/test_qpu_devices.py b/tests/test_qpu_devices.py index a27b96b1b..300912c6a 100644 --- a/tests/test_qpu_devices.py +++ b/tests/test_qpu_devices.py @@ -276,7 +276,7 @@ def setUp(self): self.AZ_LOCATION = output_json_s['location'] @pytest.mark.api - def test_check_connection_provider_no_resource_id(self): + def test_check_connection_provider_no_resource_id_or_az_location(self): """ If no information about about the workspace is provided, the resource id @@ -298,11 +298,11 @@ def test_check_connection_provider_no_resource_id(self): @pytest.mark.api - def test_check_connection_provider_no_backend_provided_credentials(self): + def test_check_connection_provider_no_backend_provided_resource_id_and_az_location(self): """ - If no information about the device name, but the credentials - used are correct, check_connection should return True. + If no information about the device name, but the resource id and azure + location used are correct, check_connection should return True. The provider_connected attribute should be updated to True. """ @@ -315,11 +315,11 @@ def test_check_connection_provider_no_backend_provided_credentials(self): @pytest.mark.api - def test_check_connection_provider_right_backend_provided_credentials(self): + def test_check_connection_provider_right_backend_provided_resource_id_and_az_location(self): """ - If the correct device name is provided and the credentials - used are correct, check_connection should return True. + If the correct device name is provided and the resource id and azure + location used are correct, check_connection should return True. The provider_connected attribute should be updated to True. The qpu_connected attribute should be updated to True. """ @@ -339,11 +339,11 @@ def test_check_connection_provider_right_backend_provided_credentials(self): @pytest.mark.api - def test_check_connection_provider_wrong_backend_provided_credentials(self): + def test_check_connection_provider_wrong_backend_provided_resource_id_and_az_location(self): """ - If device name provided is incorrect, and not empty, and the credentials - used are correct, check_connection should return False. + If device name provided is incorrect, and not empty, and the resource id + and azure location used are correct, check_connection should return False. The provider_connected attribute should be updated to True. The qpu_connected attribute should be updated to False. """ diff --git a/tests/test_qpu_qiskit.py b/tests/test_qpu_qiskit.py index 4bbafb970..4d012a3a6 100644 --- a/tests/test_qpu_qiskit.py +++ b/tests/test_qpu_qiskit.py @@ -3,6 +3,7 @@ import json import numpy as np import pytest +import subprocess from qiskit import QuantumCircuit from qiskit.quantum_info import Operator @@ -10,7 +11,8 @@ from openqaoa.qaoa_components import (create_qaoa_variational_params, PauliOp, Hamiltonian, QAOADescriptor, QAOAVariationalStandardParams) from openqaoa_qiskit.backends import (DeviceQiskit, QAOAQiskitQPUBackend, - QAOAQiskitBackendStatevecSimulator) + QAOAQiskitBackendStatevecSimulator) +from openqaoa_azure.backends import DeviceAzure from openqaoa.utilities import X_mixer_hamiltonian from openqaoa.problems import NumberPartition from openqaoa import QAOA @@ -65,6 +67,79 @@ def check_shots_tally(self): comp_shots = sum(q.result.optimized['optimized measurement outcomes'].values()) self.assertEqual(shots, comp_shots) + + @pytest.mark.qpu + def test_expectations_in_init(self): + + """ + Testing the Exceptions in the init function of the QiskitQPUShotBasedBackend + """ + + nqubits = 3 + p = 1 + weights = [1, 1, 1] + gammas = [1/8*np.pi] + betas = [1/8*np.pi] + shots = 10000 + + cost_hamil = Hamiltonian([PauliOp('ZZ', (0, 1)), PauliOp('ZZ', (1, 2)), + PauliOp('ZZ', (0, 2))], weights, 1) + mixer_hamil = X_mixer_hamiltonian(n_qubits=nqubits) + qaoa_descriptor = QAOADescriptor(cost_hamil, mixer_hamil, p=p) + variate_params = QAOAVariationalStandardParams(qaoa_descriptor, + betas, gammas) + + # We mock the potential Exception that could occur in the Device class + azure_device = DeviceAzure('', '', '') + azure_device._check_provider_connection = Mock(return_value=False) + + try: + QAOAQiskitQPUBackend(qaoa_descriptor, azure_device, + shots, None, None, True) + except Exception as e: + self.assertEqual(str(e), 'Error connecting to AZURE.') + + with self.assertRaises(Exception): + QAOAQiskitQPUBackend(qaoa_descriptor, azure_device, shots, None, None, True) + + + azure_device = DeviceAzure(device_name='', resource_id=self.RESOURCE_ID, + az_location=self.AZ_LOCATION) + + try: + QAOAQiskitQPUBackend(qaoa_descriptor, azure_device, + shots, None, None, True) + except Exception as e: + self.assertEqual(str(e), 'Connection to AZURE was made. Error connecting to the specified backend.') + + with self.assertRaises(Exception): + QAOAQiskitQPUBackend(qaoa_descriptor, azure_device, shots, None, None, True) + + @pytest.mark.qpu + def test_remote_qubit_overflow(self): + + """ + If the user creates a circuit that is larger than the maximum circuit size + that is supported by the QPU. An Exception should be raised with the + appropriate error message alerting the user to the error. + """ + + shots = 100 + + set_of_numbers = np.random.randint(1, 10, 6).tolist() + qubo = NumberPartition(set_of_numbers).qubo + + mixer_hamil = X_mixer_hamiltonian(n_qubits=6) + qaoa_descriptor = QAOADescriptor(qubo.hamiltonian, mixer_hamil, p=1) + variate_params = create_qaoa_variational_params(qaoa_descriptor, 'standard', 'rand') + + azure_device = DeviceAzure('rigetti.sim.qvm', self.RESOURCE_ID, self.AZ_LOCATION) + + try: + QAOAQiskitQPUBackend(qaoa_descriptor, azure_device, + shots, None, None, True) + except Exception as e: + self.assertEqual(str(e), 'There are lesser qubits on the device than the number of qubits required for the circuit.') class TestingQAOAQiskitQPUBackend(unittest.TestCase): diff --git a/tests/test_workflows.py b/tests/test_workflows.py index e7a019c24..1e791b7a6 100644 --- a/tests/test_workflows.py +++ b/tests/test_workflows.py @@ -43,6 +43,7 @@ QAOAQiskitBackendShotBasedSimulator, QAOAQiskitBackendStatevecSimulator ) +from openqaoa_azure.backends import DeviceAzure ALLOWED_LOCAL_SIMUALTORS = SUPPORTED_LOCAL_SIMULATORS @@ -154,6 +155,13 @@ def test_set_device_cloud(self): assert type(q.device) == DeviceQiskit assert q.device.device_name == 'place_holder' assert q.device.device_location == 'ibmq' + + + q.set_device(create_device('azure', name='place_holder', resource_id='***', + az_location='***')) + assert type(q.device) == DeviceAzure + assert q.device.device_name == 'place_holder' + assert q.device.device_location == 'azure' def test_compile_before_optimise(self): """ From ea20d8c93881947289001a90d4f8902508175779 Mon Sep 17 00:00:00 2001 From: "shahidee44@hotmail.com" Date: Fri, 24 Feb 2023 02:26:02 +0000 Subject: [PATCH 55/67] Missing docstring quotation marks --- tests/test_qpu_devices.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_qpu_devices.py b/tests/test_qpu_devices.py index 68dd48fe4..15d2fafc1 100644 --- a/tests/test_qpu_devices.py +++ b/tests/test_qpu_devices.py @@ -322,6 +322,7 @@ def test_check_connection_provider_no_resource_id_or_az_location(self): @pytest.mark.api def test_check_connection_provider_no_backend_provided_resource_id_and_az_location(self): + """ If no information about the device name, but the resource id and azure location used are correct, check_connection should return True. The provider_connected attribute should be updated to True. From ddc27126f4e43e3a67af23e8bf5f5cf1cb829b28 Mon Sep 17 00:00:00 2001 From: "shahidee44@hotmail.com" Date: Tue, 28 Feb 2023 02:17:16 +0000 Subject: [PATCH 56/67] Updated docstrings --- src/openqaoa-azure/backends/devices.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/openqaoa-azure/backends/devices.py b/src/openqaoa-azure/backends/devices.py index e02dd4337..1e79dbc3e 100644 --- a/src/openqaoa-azure/backends/devices.py +++ b/src/openqaoa-azure/backends/devices.py @@ -30,7 +30,7 @@ def __init__(self, device_name: str, resource_id: str, az_location: str): resource_id: `str` The resource_id of the Workplace az_location: `str` - The location of the Azure Workplace. e.g. "us-west-1" + The location of the Azure Workplace. e.g. "westus" """ self.resource_id = resource_id From aeb0206c9d8e567f2b0ef19b744824a1cb7c5cbd Mon Sep 17 00:00:00 2001 From: Leonardo Disilvestro Date: Thu, 9 Mar 2023 16:07:25 +0800 Subject: [PATCH 57/67] Update tests --- .github/workflows/test_dev.yml | 76 +++++++++++++-------------- .github/workflows/test_main_linux.yml | 52 ++++++++++-------- 2 files changed, 68 insertions(+), 60 deletions(-) diff --git a/.github/workflows/test_dev.yml b/.github/workflows/test_dev.yml index 689d5ea4a..e70620a93 100644 --- a/.github/workflows/test_dev.yml +++ b/.github/workflows/test_dev.yml @@ -77,44 +77,44 @@ jobs: token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos files: ./coverage.xml - # docs: - # runs-on: ubuntu-latest - # steps: - # - name: Check out openqaoa - # uses: actions/checkout@v3 - # with: - # ref: ${{ github.event.pull_request.head.sha }} - # - name: Set up Python - # uses: actions/setup-python@v3 - # with: - # python-version: 3.8 + docs: + runs-on: ubuntu-latest + steps: + - name: Check out openqaoa + uses: actions/checkout@v3 + with: + ref: ${{ github.event.pull_request.head.sha }} + - name: Set up Python + uses: actions/setup-python@v3 + with: + python-version: 3.8 - # - name: Install OpenQAOA - # run: | - # python -m pip install --upgrade pip - # pip install .[docs] + - name: Install OpenQAOA + run: | + python -m pip install --upgrade pip + pip install .[docs] - # - name: Install qvm - # run: | - # find /usr/lib -name "libffi.so*" - # sudo ln -s /usr/lib/x86_64-linux-gnu/libffi.so /usr/lib/x86_64-linux-gnu/libffi.so.6 - # wget -q https://downloads.rigetti.com/qcs-sdk/forest-sdk-2.23.0-linux-deb.tar.bz2 - # tar -xf forest-sdk-2.23.0-linux-deb.tar.bz2 - # cd forest-sdk-2.23.0-linux-deb/ - # sudo apt-get update - # sudo apt-get install -y screen libblas-dev libblas3 libgfortran5 liblapack-dev liblapack3 - # sudo ./forest-sdk-2.23.0-linux-deb.run - # qvm --version - # quilc --version - # echo "Starting qvm and quilc" - # screen -d -m qvm -S - # screen -d -m quilc -S - # cd .. + - name: Install qvm + run: | + find /usr/lib -name "libffi.so*" + sudo ln -s /usr/lib/x86_64-linux-gnu/libffi.so /usr/lib/x86_64-linux-gnu/libffi.so.6 + wget -q https://downloads.rigetti.com/qcs-sdk/forest-sdk-2.23.0-linux-deb.tar.bz2 + tar -xf forest-sdk-2.23.0-linux-deb.tar.bz2 + cd forest-sdk-2.23.0-linux-deb/ + sudo apt-get update + sudo apt-get install -y screen libblas-dev libblas3 libgfortran5 liblapack-dev liblapack3 + sudo ./forest-sdk-2.23.0-linux-deb.run + qvm --version + quilc --version + echo "Starting qvm and quilc" + screen -d -m qvm -S + screen -d -m quilc -S + cd .. - # - name: Build and test Sphinx docs - # run: | - # sudo apt-get install pandoc - # mkdir ./docs/source/notebooks - # cp ./examples/*.ipynb ./docs/source/notebooks/ - # cd docs/ - # make html SPHINXOPTS="-W --keep-going" + - name: Build and test Sphinx docs + run: | + sudo apt-get install pandoc + mkdir ./docs/source/notebooks + cp ./examples/*.ipynb ./docs/source/notebooks/ + cd docs/ + make html SPHINXOPTS="-W --keep-going" diff --git a/.github/workflows/test_main_linux.yml b/.github/workflows/test_main_linux.yml index d50f3c07a..1181b5d19 100644 --- a/.github/workflows/test_main_linux.yml +++ b/.github/workflows/test_main_linux.yml @@ -19,16 +19,19 @@ jobs: # The type of runner that the job will run on runs-on: ${{ matrix.os }} - # Steps represent a sequence of tasks that will be executed as part of the job steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - uses: actions/checkout@v3 with: ref: ${{ github.event.pull_request.head.sha }} - name: Set up Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v3 with: python-version: ${{ matrix.python }} - + - name: Log in with Azure + uses: azure/login@v1 + with: + creds: '${{ secrets.AZURE_CREDENTIALS }}' - name: Install OpenQAOA run: | python -m pip install --user virtualenv @@ -37,30 +40,34 @@ jobs: python -m pip install --upgrade pip pip install .[tests] pip install ipykernel - - - name: QVM on ubuntu - if: ${{ matrix.os=='ubuntu-latest' }} + - name: Setup IBMQ account + env: + IBMQ_TOKEN: ${{ secrets.IBMQ_TOKEN }} run: | - find /usr/lib -name "libffi.so*" - sudo ln -s /usr/lib/x86_64-linux-gnu/libffi.so /usr/lib/x86_64-linux-gnu/libffi.so.6 - wget -q https://downloads.rigetti.com/qcs-sdk/forest-sdk-2.23.0-linux-deb.tar.bz2 - tar -xf forest-sdk-2.23.0-linux-deb.tar.bz2 - cd forest-sdk-2.23.0-linux-deb/ - sudo apt-get update - sudo apt-get install -y screen libblas-dev libblas3 libgfortran5 liblapack-dev liblapack3 - sudo ./forest-sdk-2.23.0-linux-deb.run - qvm --version - quilc --version - echo "Starting qvm and quilc" - screen -d -m qvm -S - screen -d -m quilc -S - cd .. - + IBMQ_TOKEN=$IBMQ_TOKEN + source env/bin/activate + python -c'from qiskit import IBMQ; import os; IBMQ.save_account(os.environ.get("IBMQ_TOKEN"))' + - name: Setup AWS + env: + ACCESS_KEY: ${{ secrets.ACCESS_KEY }} + SECRET_ACCESS_KEY: ${{ secrets.SECRET_ACCESS_KEY }} + run: | + python -m pip install awscli + aws configure set aws_access_key_id $ACCESS_KEY + aws configure set aws_secret_access_key $SECRET_ACCESS_KEY + aws configure set region us-west-1 + aws configure set output json + - name: Build the docker stack + run: | + docker login -u AWS -p $(aws ecr get-login-password --region us-east-1) 292282985366.dkr.ecr.us-east-1.amazonaws.com + docker network create local_bridge + docker build -t amazon-braket-oq-dev . + docker-compose up -d - name: Run tests run: | source env/bin/activate ipython kernel install --name "env" --user - python -m pytest -v -m 'not (qpu or api or docker_aws)' + pytest tests/ -v -m '(not qpu or api)' --cov --cov-report=xml:coverage.xml - name: Upload coverage reports to Codecov with GitHub Action uses: codecov/codecov-action@v3 @@ -68,6 +75,7 @@ jobs: token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos files: ./coverage.xml + docs: runs-on: ubuntu-latest steps: From cdb1702aa164a3f7d874031792a8919b01ffbdce Mon Sep 17 00:00:00 2001 From: Vishal Sharma Date: Fri, 10 Mar 2023 05:21:39 +0000 Subject: [PATCH 58/67] update test workflow to run selectively --- .github/workflows/test_dev.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/test_dev.yml b/.github/workflows/test_dev.yml index e70620a93..d35d10b31 100644 --- a/.github/workflows/test_dev.yml +++ b/.github/workflows/test_dev.yml @@ -3,6 +3,7 @@ name: test_dev # Controls when the workflow will run on: pull_request: + types: [review_requested, ready_for_review] branches: - dev # Manual trigger @@ -12,6 +13,7 @@ on: jobs: # This workflow contains a single job called "build" build: + if: ${{ github.event.label.name != 'halted_testing' }} strategy: fail-fast: false matrix: @@ -78,6 +80,7 @@ jobs: files: ./coverage.xml docs: + if: ${{ github.event.label.name == 'halted_testing' }} runs-on: ubuntu-latest steps: - name: Check out openqaoa From 461c31f3e6b7e2227686e07855567c91532a46ab Mon Sep 17 00:00:00 2001 From: Vishal Sharma Date: Fri, 10 Mar 2023 05:36:32 +0000 Subject: [PATCH 59/67] updated label conditional --- .github/workflows/test_dev.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/test_dev.yml b/.github/workflows/test_dev.yml index d35d10b31..ca273a76c 100644 --- a/.github/workflows/test_dev.yml +++ b/.github/workflows/test_dev.yml @@ -11,9 +11,9 @@ on: # A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: + if: ${{ github.event.label.name != 'halted_testing' }} # This workflow contains a single job called "build" build: - if: ${{ github.event.label.name != 'halted_testing' }} strategy: fail-fast: false matrix: @@ -80,7 +80,6 @@ jobs: files: ./coverage.xml docs: - if: ${{ github.event.label.name == 'halted_testing' }} runs-on: ubuntu-latest steps: - name: Check out openqaoa From efbe30bbe922ab5aeacae3c9a8cce0278cf98c0c Mon Sep 17 00:00:00 2001 From: Vishal Sharma Date: Fri, 10 Mar 2023 05:43:24 +0000 Subject: [PATCH 60/67] syntax fix attempt --- .github/workflows/test_dev.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test_dev.yml b/.github/workflows/test_dev.yml index ca273a76c..18be53c59 100644 --- a/.github/workflows/test_dev.yml +++ b/.github/workflows/test_dev.yml @@ -11,9 +11,9 @@ on: # A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: - if: ${{ github.event.label.name != 'halted_testing' }} # This workflow contains a single job called "build" build: + if: ${{ github.event.label.name != 'halted_testing' }} strategy: fail-fast: false matrix: @@ -80,6 +80,7 @@ jobs: files: ./coverage.xml docs: + if: ${{ github.event.label.name != 'halted_testing' }} runs-on: ubuntu-latest steps: - name: Check out openqaoa From 7b6e86520a6fdfec813b33da031dfe45dd24f8e3 Mon Sep 17 00:00:00 2001 From: Vishal Sharma Date: Fri, 10 Mar 2023 05:54:13 +0000 Subject: [PATCH 61/67] trigger for running test onlabel removal --- .github/workflows/test_dev.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test_dev.yml b/.github/workflows/test_dev.yml index 18be53c59..450892ef7 100644 --- a/.github/workflows/test_dev.yml +++ b/.github/workflows/test_dev.yml @@ -6,6 +6,7 @@ on: types: [review_requested, ready_for_review] branches: - dev + unlabel: [halted_testing] # Manual trigger workflow_dispatch: From fc6ec88f4c0963a93a8eb2478d8bbb7e6d019825 Mon Sep 17 00:00:00 2001 From: Vishal Sharma Date: Mon, 13 Mar 2023 05:27:39 +0000 Subject: [PATCH 62/67] toggle based on draft status --- .github/workflows/test_dev.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/test_dev.yml b/.github/workflows/test_dev.yml index 450892ef7..91935a1c6 100644 --- a/.github/workflows/test_dev.yml +++ b/.github/workflows/test_dev.yml @@ -6,7 +6,6 @@ on: types: [review_requested, ready_for_review] branches: - dev - unlabel: [halted_testing] # Manual trigger workflow_dispatch: @@ -14,7 +13,6 @@ on: jobs: # This workflow contains a single job called "build" build: - if: ${{ github.event.label.name != 'halted_testing' }} strategy: fail-fast: false matrix: @@ -81,7 +79,6 @@ jobs: files: ./coverage.xml docs: - if: ${{ github.event.label.name != 'halted_testing' }} runs-on: ubuntu-latest steps: - name: Check out openqaoa From 1979b264bb42f3a9e4103c171badfe53fa1a6db8 Mon Sep 17 00:00:00 2001 From: Leonardo Disilvestro Date: Mon, 13 Mar 2023 13:33:46 +0800 Subject: [PATCH 63/67] Update docker-compose.yml Comment docker compose --- docker-compose.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/docker-compose.yml b/docker-compose.yml index 940dddc4b..a4001219f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,3 +1,4 @@ +# Docker compose mostly used for testing purposes: it provides dockers to interact with OQ's braket jobs and rigetti's QVM version: '3' networks: From 0deb49c9126eab83a951896a828cc25b1fe090f8 Mon Sep 17 00:00:00 2001 From: Leonardo Disilvestro Date: Mon, 13 Mar 2023 13:34:35 +0800 Subject: [PATCH 64/67] Update Dockerfile --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index 3697245e9..96b0b3d02 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,4 @@ +# The dockerfile for OpenQAOA braket jobs FROM 292282985366.dkr.ecr.us-east-1.amazonaws.com/amazon-braket-pytorch-jobs:1.9.1-gpu-py38-cu111-ubuntu20.04 RUN mkdir -p /openqaoa From 2b8b22ff56a9e849602b199c08d30e1d5acebd84 Mon Sep 17 00:00:00 2001 From: "shahidee44@hotmail.com" Date: Tue, 14 Mar 2023 06:58:29 +0000 Subject: [PATCH 65/67] Update flags and test_dev.yml --- .github/workflows/test_dev.yml | 2 +- pytest.ini | 3 ++- tests/test_qpu_qiskit.py | 24 ++++++++++++------------ 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/.github/workflows/test_dev.yml b/.github/workflows/test_dev.yml index 91935a1c6..55d4223f9 100644 --- a/.github/workflows/test_dev.yml +++ b/.github/workflows/test_dev.yml @@ -70,7 +70,7 @@ jobs: run: | source env/bin/activate ipython kernel install --name "env" --user - pytest tests/ -v -m '(not qpu or api)' --cov --cov-report=xml:coverage.xml + pytest tests/ -v -m '(not qpu or sim)' --cov --cov-report=xml:coverage.xml - name: Upload coverage reports to Codecov with GitHub Action uses: codecov/codecov-action@v3 diff --git a/pytest.ini b/pytest.ini index 850ea25a7..04e8f57ce 100644 --- a/pytest.ini +++ b/pytest.ini @@ -5,4 +5,5 @@ markers = qvm: marks tests that require an attive Rigetti QVM and QILC compiler (deselect with '-m "not qvm"') docker_aws: marks tests that require to build aws docker (deselect with '-m "not docker_aws"') braket_api: marks tests that require valid AWS credentials (no QPU) (deselect with '-m "not braket_api"') - notebook: marks tests that run on jupyter noteboks (deselect with '-m "not notebook"') \ No newline at end of file + notebook: marks tests that run on jupyter noteboks (deselect with '-m "not notebook"') + sim: marks tests that run on remote Simulators (deselect with '-m "not sim"') \ No newline at end of file diff --git a/tests/test_qpu_qiskit.py b/tests/test_qpu_qiskit.py index 5a75f56fc..967509543 100644 --- a/tests/test_qpu_qiskit.py +++ b/tests/test_qpu_qiskit.py @@ -36,7 +36,7 @@ class TestingQAOAQiskitQPUBackendAzure(unittest.TestCase): The Azure CLI has to be configured beforehand to run these tests. """ - @pytest.mark.qpu + @pytest.mark.api def setUp(self): bashCommand = "az resource list" @@ -52,7 +52,7 @@ def setUp(self): self.RESOURCE_ID = output_json_s['id'] self.AZ_LOCATION = output_json_s['location'] - @pytest.mark.qpu + @pytest.mark.sim def check_shots_tally(self): """There is a known bug in the qiskit backend for azure where if the shots @@ -77,7 +77,7 @@ def check_shots_tally(self): self.assertEqual(shots, comp_shots) - @pytest.mark.qpu + @pytest.mark.api def test_expectations_in_init(self): """ @@ -124,7 +124,7 @@ def test_expectations_in_init(self): with self.assertRaises(Exception): QAOAQiskitQPUBackend(qaoa_descriptor, azure_device, shots, None, None, True) - @pytest.mark.qpu + @pytest.mark.api def test_remote_qubit_overflow(self): """ @@ -160,14 +160,14 @@ class TestingQAOAQiskitQPUBackend(unittest.TestCase): IBMQ Account has to be saved locally to run these tests. """ - @pytest.mark.qpu + @pytest.mark.api def setUp(self): self.HUB = "ibm-q" self.GROUP = "open" self.PROJECT = "main" - @pytest.mark.qpu + @pytest.mark.api def test_circuit_angle_assignment_qpu_backend(self): """ A tests that checks if the circuit created by the Qiskit Backend @@ -233,7 +233,7 @@ def test_circuit_angle_assignment_qpu_backend(self): assert qpu_circuit_operator.equiv(main_circuit_operator) - @pytest.mark.qpu + @pytest.mark.api def test_circuit_angle_assignment_qpu_backend_w_hadamard(self): """ Checks for consistent if init_hadamard is set to True. @@ -298,7 +298,7 @@ def test_circuit_angle_assignment_qpu_backend_w_hadamard(self): assert qpu_circuit_operator.equiv(main_circuit_operator) - @pytest.mark.qpu + @pytest.mark.api def test_prepend_circuit(self): """ Checks if prepended circuit has been prepended correctly. @@ -356,7 +356,7 @@ def test_prepend_circuit(self): assert qpu_circuit_operator.equiv(main_circuit_operator) - @pytest.mark.qpu + @pytest.mark.api def test_append_circuit(self): """ Checks if appended circuit is appropriately appended to the back of the @@ -415,7 +415,7 @@ def test_append_circuit(self): assert qpu_circuit_operator.equiv(main_circuit_operator) - @pytest.mark.qpu + @pytest.mark.api def test_expectations_in_init(self): """ @@ -483,7 +483,7 @@ def test_expectations_in_init(self): True, ) - @pytest.mark.qpu + @pytest.mark.sim def test_remote_integration_sim_run(self): """ Checks if Remote IBM QASM Simulator is similar/close to Local IBM @@ -534,7 +534,7 @@ def test_remote_integration_sim_run(self): qiskit_expectation, qiskit_statevec_expectation, delta=acceptable_delta ) - @pytest.mark.qpu + @pytest.mark.api def test_remote_qubit_overflow(self): """ From f179d5038b26a1f60e53d995d007b8d8c35eb46a Mon Sep 17 00:00:00 2001 From: Vishal Sharma <35625965+vishal-ph@users.noreply.github.com> Date: Tue, 21 Mar 2023 09:47:00 +0530 Subject: [PATCH 66/67] Update test_workflows.py --- tests/test_workflows.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_workflows.py b/tests/test_workflows.py index 678a03b61..e22a96b4a 100644 --- a/tests/test_workflows.py +++ b/tests/test_workflows.py @@ -52,7 +52,7 @@ from openqaoa.qaoa_components.variational_parameters.variational_params_factory import ( PARAMS_CLASSES_MAPPER, - +) ALLOWED_LOCAL_SIMUALTORS = SUPPORTED_LOCAL_SIMULATORS LOCAL_DEVICES = ALLOWED_LOCAL_SIMUALTORS + ["6q-qvm", "Aspen-11"] From fad417f34b16914c8491c2ca3458fa380cb5b093 Mon Sep 17 00:00:00 2001 From: Vishal Sharma Date: Tue, 21 Mar 2023 07:10:33 +0000 Subject: [PATCH 67/67] run test on PR draft conditional is false --- .github/workflows/test_dev.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test_dev.yml b/.github/workflows/test_dev.yml index 91935a1c6..68dbeec23 100644 --- a/.github/workflows/test_dev.yml +++ b/.github/workflows/test_dev.yml @@ -3,7 +3,6 @@ name: test_dev # Controls when the workflow will run on: pull_request: - types: [review_requested, ready_for_review] branches: - dev # Manual trigger @@ -13,6 +12,7 @@ on: jobs: # This workflow contains a single job called "build" build: + if : github.event.pull_request.draft == false strategy: fail-fast: false matrix: @@ -79,6 +79,7 @@ jobs: files: ./coverage.xml docs: + if : github.event.pull_request.draft == false runs-on: ubuntu-latest steps: - name: Check out openqaoa