From 488e7ece8835f2b02ba7caad811e44076ee76554 Mon Sep 17 00:00:00 2001 From: KilianPoirier Date: Tue, 28 May 2024 03:24:40 +0000 Subject: [PATCH 1/8] Remove outdated folding functions in mitiq --- examples/15_Zero_Noise_Extrapolation.ipynb | 2 +- .../openqaoa/algorithms/baseworkflow.py | 2 +- .../openqaoa/algorithms/workflow_properties.py | 2 +- src/openqaoa-core/openqaoa/backends/wrapper.py | 16 +++++++--------- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/examples/15_Zero_Noise_Extrapolation.ipynb b/examples/15_Zero_Noise_Extrapolation.ipynb index 4225b393..5a6c5430 100644 --- a/examples/15_Zero_Noise_Extrapolation.ipynb +++ b/examples/15_Zero_Noise_Extrapolation.ipynb @@ -336,7 +336,7 @@ "Available options to set up the ZNE with `set_error_mitigation_properties`:\n", "\n", "- **factory**: The name of the zero-noise extrapolation method. Supported values: \"Richardson\", \"Linear\", \"Poly\", \"Exp\", \"PolyExp\", \"AdaExp\", \"FakeNodes\".\n", - "- **scaling**: The name of the function for scaling the noise of a quantum circuit. Supported values: \"fold_gates_at_random\", \"fold_gates_from_right\", \"fold_gates_from_left\".\n", + "- **scaling**: The name of the function for scaling the noise of a quantum circuit. Supported values: \"fold_gates_at_random\" (\"fold_gates_from_right\", \"fold_gates_from_left\" not supported as version 0.8).\n", "- **scale_factors**: List[int] Sequence of noise scale factors at which expectation values should be measured. For factory = \"AdaExp\", just the first element of the list will be considered.\n", "- **order**: Extrapolation order (degree of the polynomial fit). It cannot exceed len(scale_factors) - 1. Only used for factory = \"Poly\" or \"PolyExp\".\n", "- **steps**: The number of optimization steps. At least 3 are necessary. Only used for factory = \"AdaExp\"." diff --git a/src/openqaoa-core/openqaoa/algorithms/baseworkflow.py b/src/openqaoa-core/openqaoa/algorithms/baseworkflow.py index ab2c43ab..f31b33d2 100644 --- a/src/openqaoa-core/openqaoa/algorithms/baseworkflow.py +++ b/src/openqaoa-core/openqaoa/algorithms/baseworkflow.py @@ -283,7 +283,7 @@ def set_error_mitigation_properties(self, **kwargs): factory: str Used in "mitiq_zne". The name of the zero-noise extrapolation method. Supported values: "Richardson", "Linear", "Poly", "Exp", "PolyExp", "AdaExp", "FakeNodes". scaling: str - Used in "mitiq_zne". The name of the function for scaling the noise of a quantum circuit. Supported values: "fold_gates_at_random", "fold_gates_from_right", "fold_gates_from_left". + Used in "mitiq_zne". The name of the function for scaling the noise of a quantum circuit. Supported values: "fold_gates_at_random" ("fold_gates_from_right", "fold_gates_from_left" not supported as version 0.8) scale_factors: List[int] Used in "mitiq_zne". Sequence of noise scale factors at which expectation values should be measured. For factory = "AdaExp", just the first element of the list will be considered. diff --git a/src/openqaoa-core/openqaoa/algorithms/workflow_properties.py b/src/openqaoa-core/openqaoa/algorithms/workflow_properties.py index a49a1a17..4720e9c5 100644 --- a/src/openqaoa-core/openqaoa/algorithms/workflow_properties.py +++ b/src/openqaoa-core/openqaoa/algorithms/workflow_properties.py @@ -354,7 +354,7 @@ class MitiqZNEProperties(ErrorMitigationProperties): factory: str The name of the zero-noise extrapolation method. Supported values: "Richardson", "Linear", "Poly", "Exp", "PolyExp", "AdaExp", "FakeNodes". scaling: str - The name of the function for scaling the noise of a quantum circuit. Supported values: "fold_gates_at_random", "fold_gates_from_right", "fold_gates_from_left". + The name of the function for scaling the noise of a quantum circuit. Supported values: "fold_gates_at_random" ("fold_gates_from_right", "fold_gates_from_left" not supported as version 0.8). scale_factors: List[int] Sequence of noise scale factors at which expectation values should be measured. For factory = "AdaExp", just the first element of the list will be considered. diff --git a/src/openqaoa-core/openqaoa/backends/wrapper.py b/src/openqaoa-core/openqaoa/backends/wrapper.py index 14d90a4e..4257ff0e 100644 --- a/src/openqaoa-core/openqaoa/backends/wrapper.py +++ b/src/openqaoa-core/openqaoa/backends/wrapper.py @@ -3,7 +3,7 @@ import json from mitiq.zne.inference import RichardsonFactory, LinearFactory, PolyExpFactory, PolyFactory, AdaExpFactory, FakeNodesFactory, ExpFactory -from mitiq.zne.scaling import fold_gates_at_random, fold_gates_from_left, fold_gates_from_right +from mitiq.zne.scaling import fold_gates_at_random from mitiq.zne import execute_with_zne import copy @@ -75,8 +75,6 @@ def exact_solution(self, *args, **kwargs): ] available_scaling = [ "fold_gates_at_random", - "fold_gates_from_right", - "fold_gates_from_left" ] class ZNEWrapper(BaseWrapper): """ @@ -92,7 +90,7 @@ class ZNEWrapper(BaseWrapper): factory: str The name of the zero-noise extrapolation method. Supported values: "Richardson", "Linear", "Poly", "Exp", "PolyExp", "AdaExp", "FakeNodes". scaling: str - The name of the function for scaling the noise of a quantum circuit. Supported values: "fold_gates_at_random", "fold_gates_from_right", "fold_gates_from_left". + The name of the function for scaling the noise of a quantum circuit. Supported values: "fold_gates_at_random" ("fold_gates_from_right", "fold_gates_from_left" not supported as version 0.8). scale_factors: List[int] Sequence of noise scale factors at which expectation values should be measured. For factory = "AdaExp", just the first element of the list will be considered. @@ -116,7 +114,7 @@ def __init__(self, backend, factory, scaling, scale_factors, order, steps): if(factory not in available_factories): raise ValueError("Supported factories are: Poly, Richardson, Exp, FakeNodes, Linear, PolyExp, AdaExp") if(scaling not in available_scaling): - raise ValueError("Supported scaling methods are: fold_gates_at_random, fold_gates_from_right, fold_gates_from_left") + raise ValueError("Supported scaling methods are: fold_gates_at_random") if(not isinstance(scale_factors, list) or not all(isinstance(x, int) and x >= 1 for x in scale_factors)): raise ValueError("Scale factor must be a list of ints greater than or equal to 1") if(type(order) != int or order < 1): @@ -145,10 +143,10 @@ def __init__(self, backend, factory, scaling, scale_factors, order, steps): self.scale_noise = None if scaling == "fold_gates_at_random": self.scale_noise = fold_gates_at_random - elif scaling == "fold_gates_from_left": - self.scale_noise = fold_gates_from_left - elif scaling == "fold_gates_from_right": - self.scale_noise = fold_gates_from_right + # elif scaling == "fold_gates_from_left": + # self.scale_noise = fold_gates_from_left + # elif scaling == "fold_gates_from_right": + # self.scale_noise = fold_gates_from_right #setting the scale_factors self.scale_factors = scale_factors From 755fa6e3941531ea969681db2d9a8980b1d09d08 Mon Sep 17 00:00:00 2001 From: KilianPoirier Date: Tue, 28 May 2024 05:54:36 +0000 Subject: [PATCH 2/8] Changed qiskit backend for tests to ibm_kyoto with single shot after removal of simulators --- src/openqaoa-qiskit/tests/test_qpu_qiskit.py | 52 ++++++++++++-------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/src/openqaoa-qiskit/tests/test_qpu_qiskit.py b/src/openqaoa-qiskit/tests/test_qpu_qiskit.py index 78707b72..8d024868 100644 --- a/src/openqaoa-qiskit/tests/test_qpu_qiskit.py +++ b/src/openqaoa-qiskit/tests/test_qpu_qiskit.py @@ -82,7 +82,7 @@ def test_circuit_angle_assignment_qpu_backend(self): weights = [1, 1, 1] gammas = [0, 1 / 8 * np.pi] betas = [1 / 2 * np.pi, 3 / 8 * np.pi] - shots = 10000 + shots = 1 cost_hamil = Hamiltonian( [PauliOp("ZZ", (0, 1)), PauliOp("ZZ", (1, 2)), PauliOp("ZZ", (0, 2))], @@ -94,7 +94,7 @@ def test_circuit_angle_assignment_qpu_backend(self): variate_params = QAOAVariationalStandardParams(qaoa_descriptor, betas, gammas) qiskit_device = DeviceQiskit( - "ibmq_qasm_simulator", self.HUB, self.GROUP, self.PROJECT + "ibm_kyoto", self.HUB, self.GROUP, self.PROJECT ) qiskit_backend = QAOAQiskitQPUBackend( @@ -147,7 +147,7 @@ def test_circuit_angle_assignment_qpu_backend_w_hadamard(self): weights = [1, 1, 1] gammas = [0, 1 / 8 * np.pi] betas = [1 / 2 * np.pi, 3 / 8 * np.pi] - shots = 10000 + shots = 1 cost_hamil = Hamiltonian( [PauliOp("ZZ", (0, 1)), PauliOp("ZZ", (1, 2)), PauliOp("ZZ", (0, 2))], @@ -159,7 +159,7 @@ def test_circuit_angle_assignment_qpu_backend_w_hadamard(self): variate_params = QAOAVariationalStandardParams(qaoa_descriptor, betas, gammas) qiskit_device = DeviceQiskit( - "ibmq_qasm_simulator", self.HUB, self.GROUP, self.PROJECT + "ibm_kyoto", self.HUB, self.GROUP, self.PROJECT ) qiskit_backend = QAOAQiskitQPUBackend( @@ -213,7 +213,7 @@ def test_prepend_circuit(self): weights = [1, 1, 1] gammas = [1 / 8 * np.pi] betas = [1 / 8 * np.pi] - shots = 10000 + shots = 1 # Prepended Circuit prepend_circuit = QuantumCircuit(3) @@ -229,7 +229,7 @@ def test_prepend_circuit(self): variate_params = QAOAVariationalStandardParams(qaoa_descriptor, betas, gammas) qiskit_device = DeviceQiskit( - "ibmq_qasm_simulator", self.HUB, self.GROUP, self.PROJECT + "ibm_kyoto", self.HUB, self.GROUP, self.PROJECT ) qiskit_backend = QAOAQiskitQPUBackend( @@ -273,7 +273,7 @@ def test_append_circuit(self): weights = [1, 1, 1] gammas = [1 / 8 * np.pi] betas = [1 / 8 * np.pi] - shots = 10000 + shots = 1 # Appended Circuit append_circuit = QuantumCircuit(3) @@ -289,7 +289,7 @@ def test_append_circuit(self): variate_params = QAOAVariationalStandardParams(qaoa_descriptor, betas, gammas) qiskit_device = DeviceQiskit( - "ibmq_qasm_simulator", self.HUB, self.GROUP, self.PROJECT + "ibm_kyoto", self.HUB, self.GROUP, self.PROJECT ) qiskit_backend = QAOAQiskitQPUBackend( @@ -450,10 +450,10 @@ def test_remote_qubit_overflow(self): shots = 100 - set_of_numbers = np.random.randint(1, 10, 8).tolist() + set_of_numbers = np.random.randint(1, 10, 129).tolist() qubo = NumberPartition(set_of_numbers).qubo - mixer_hamil = X_mixer_hamiltonian(n_qubits=8) + mixer_hamil = X_mixer_hamiltonian(n_qubits=129) qaoa_descriptor = QAOADescriptor(qubo.hamiltonian, mixer_hamil, p=1) # Check the creation of the varitional parms @@ -461,15 +461,25 @@ def test_remote_qubit_overflow(self): qiskit_device = DeviceQiskit("ibm_kyoto", self.HUB, self.GROUP, self.PROJECT) - try: - QAOAQiskitQPUBackend( - qaoa_descriptor, qiskit_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.", - ) + self.assertRaises( + Exception, + QAOAQiskitQPUBackend, + qaoa_descriptor, + qiskit_device, + shots, + None, + None, + True, + ) + # try: + # QAOAQiskitQPUBackend( + # qaoa_descriptor, qiskit_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.", + # ) @pytest.mark.qpu def test_integration_on_emulator(self): @@ -483,7 +493,7 @@ def test_integration_on_emulator(self): weights = [1, 1, 1] gammas = [[1 / 8 * np.pi]] betas = [[1 / 8 * np.pi]] - shots = 10000 + shots = 1 cost_hamil = Hamiltonian( [PauliOp("ZZ", (0, 1)), PauliOp("ZZ", (1, 2)), PauliOp("ZZ", (0, 2))], @@ -520,7 +530,7 @@ def test_remote_integration_qpu_run(self): weights = [1, 1, 1] gammas = [[1 / 8 * np.pi]] betas = [[1 / 8 * np.pi]] - shots = 10000 + shots = 1 cost_hamil = Hamiltonian( [PauliOp("ZZ", (0, 1)), PauliOp("ZZ", (1, 2)), PauliOp("ZZ", (0, 2))], From dc9d6854b84f0967269356133c318c2222de3b04 Mon Sep 17 00:00:00 2001 From: KilianPoirier Date: Mon, 3 Jun 2024 02:44:38 +0000 Subject: [PATCH 3/8] Updated qiskit qpu tests removing ibm_qasm_simulator and replacing with ibm_kyoto when possible --- src/openqaoa-qiskit/tests/test_qpu_qiskit.py | 152 ++++++++++--------- 1 file changed, 77 insertions(+), 75 deletions(-) diff --git a/src/openqaoa-qiskit/tests/test_qpu_qiskit.py b/src/openqaoa-qiskit/tests/test_qpu_qiskit.py index 8d024868..70a9ae50 100644 --- a/src/openqaoa-qiskit/tests/test_qpu_qiskit.py +++ b/src/openqaoa-qiskit/tests/test_qpu_qiskit.py @@ -79,13 +79,13 @@ def test_circuit_angle_assignment_qpu_backend(self): nqubits = 3 p = 2 - weights = [1, 1, 1] + weights = [1, 1] gammas = [0, 1 / 8 * np.pi] betas = [1 / 2 * np.pi, 3 / 8 * np.pi] shots = 1 cost_hamil = Hamiltonian( - [PauliOp("ZZ", (0, 1)), PauliOp("ZZ", (1, 2)), PauliOp("ZZ", (0, 2))], + [PauliOp("ZZ", (0, 1)), PauliOp("ZZ", (1, 2))], weights, 1, ) @@ -101,6 +101,7 @@ def test_circuit_angle_assignment_qpu_backend(self): qaoa_descriptor, qiskit_device, shots, None, None, False ) qpu_circuit = qiskit_backend.qaoa_circuit(variate_params) + qpu_circuit.draw() # Standard Decomposition main_circuit = QuantumCircuit(3) @@ -110,9 +111,9 @@ def test_circuit_angle_assignment_qpu_backend(self): main_circuit.cx(1, 2) main_circuit.rz(2 * gammas[0], 2) main_circuit.cx(1, 2) - main_circuit.cx(0, 2) - main_circuit.rz(2 * gammas[0], 2) - main_circuit.cx(0, 2) + # main_circuit.cx(0, 2) + # main_circuit.rz(2 * gammas[0], 2) + # main_circuit.cx(0, 2) main_circuit.rx(-2 * betas[0], 0) main_circuit.rx(-2 * betas[0], 1) main_circuit.rx(-2 * betas[0], 2) @@ -122,9 +123,9 @@ def test_circuit_angle_assignment_qpu_backend(self): main_circuit.cx(1, 2) main_circuit.rz(2 * gammas[1], 2) main_circuit.cx(1, 2) - main_circuit.cx(0, 2) - main_circuit.rz(2 * gammas[1], 2) - main_circuit.cx(0, 2) + # main_circuit.cx(0, 2) + # main_circuit.rz(2 * gammas[1], 2) + # main_circuit.cx(0, 2) main_circuit.rx(-2 * betas[1], 0) main_circuit.rx(-2 * betas[1], 1) main_circuit.rx(-2 * betas[1], 2) @@ -144,13 +145,13 @@ def test_circuit_angle_assignment_qpu_backend_w_hadamard(self): nqubits = 3 p = 2 - weights = [1, 1, 1] + weights = [1, 1] gammas = [0, 1 / 8 * np.pi] betas = [1 / 2 * np.pi, 3 / 8 * np.pi] shots = 1 cost_hamil = Hamiltonian( - [PauliOp("ZZ", (0, 1)), PauliOp("ZZ", (1, 2)), PauliOp("ZZ", (0, 2))], + [PauliOp("ZZ", (0, 1)), PauliOp("ZZ", (1, 2))], weights, 1, ) @@ -173,9 +174,9 @@ def test_circuit_angle_assignment_qpu_backend_w_hadamard(self): main_circuit.cx(0, 1) main_circuit.rz(2 * gammas[0], 1) main_circuit.cx(0, 1) - main_circuit.cx(1, 2) - main_circuit.rz(2 * gammas[0], 2) - main_circuit.cx(1, 2) + # main_circuit.cx(1, 2) + # main_circuit.rz(2 * gammas[0], 2) + # main_circuit.cx(1, 2) main_circuit.cx(0, 2) main_circuit.rz(2 * gammas[0], 2) main_circuit.cx(0, 2) @@ -188,9 +189,9 @@ def test_circuit_angle_assignment_qpu_backend_w_hadamard(self): main_circuit.cx(1, 2) main_circuit.rz(2 * gammas[1], 2) main_circuit.cx(1, 2) - main_circuit.cx(0, 2) - main_circuit.rz(2 * gammas[1], 2) - main_circuit.cx(0, 2) + # main_circuit.cx(0, 2) + # main_circuit.rz(2 * gammas[1], 2) + # main_circuit.cx(0, 2) main_circuit.rx(-2 * betas[1], 0) main_circuit.rx(-2 * betas[1], 1) main_circuit.rx(-2 * betas[1], 2) @@ -210,7 +211,7 @@ def test_prepend_circuit(self): nqubits = 3 p = 1 - weights = [1, 1, 1] + weights = [1, 1] gammas = [1 / 8 * np.pi] betas = [1 / 8 * np.pi] shots = 1 @@ -220,7 +221,7 @@ def test_prepend_circuit(self): prepend_circuit.x([0, 1, 2]) cost_hamil = Hamiltonian( - [PauliOp("ZZ", (0, 1)), PauliOp("ZZ", (1, 2)), PauliOp("ZZ", (0, 2))], + [PauliOp("ZZ", (0, 1)), PauliOp("ZZ", (1, 2))], weights, 1, ) @@ -247,9 +248,9 @@ def test_prepend_circuit(self): main_circuit.cx(1, 2) main_circuit.rz(2 * gammas[0], 2) main_circuit.cx(1, 2) - main_circuit.cx(0, 2) - main_circuit.rz(2 * gammas[0], 2) - main_circuit.cx(0, 2) + # main_circuit.cx(0, 2) + # main_circuit.rz(2 * gammas[0], 2) + # main_circuit.cx(0, 2) main_circuit.rx(-2 * betas[0], 0) main_circuit.rx(-2 * betas[0], 1) main_circuit.rx(-2 * betas[0], 2) @@ -270,7 +271,7 @@ def test_append_circuit(self): nqubits = 3 p = 1 - weights = [1, 1, 1] + weights = [1, 1] gammas = [1 / 8 * np.pi] betas = [1 / 8 * np.pi] shots = 1 @@ -280,7 +281,7 @@ def test_append_circuit(self): append_circuit.x([0, 1, 2]) cost_hamil = Hamiltonian( - [PauliOp("ZZ", (0, 1)), PauliOp("ZZ", (1, 2)), PauliOp("ZZ", (0, 2))], + [PauliOp("ZZ", (0, 1)), PauliOp("ZZ", (1, 2))], weights, 1, ) @@ -306,9 +307,9 @@ def test_append_circuit(self): main_circuit.cx(1, 2) main_circuit.rz(2 * gammas[0], 2) main_circuit.cx(1, 2) - main_circuit.cx(0, 2) - main_circuit.rz(2 * gammas[0], 2) - main_circuit.cx(0, 2) + # main_circuit.cx(0, 2) + # main_circuit.rz(2 * gammas[0], 2) + # main_circuit.cx(0, 2) main_circuit.rx(-2 * betas[0], 0) main_circuit.rx(-2 * betas[0], 1) main_circuit.rx(-2 * betas[0], 2) @@ -390,55 +391,56 @@ def test_expectations_in_init(self): True, ) - @pytest.mark.sim - def test_remote_integration_sim_run(self): - """ - Checks if Remote IBM QASM Simulator is similar/close to Local IBM - Statevector Simulator. - This test also serves as an integration test for the IBMQPU Backend. - - This test takes a long time to complete. - """ - - nqubits = 3 - p = 1 - weights = [1, 1, 1] - gammas = [[0], [1 / 8 * np.pi], [0], [1 / 8 * np.pi]] - betas = [[0], [0], [1 / 8 * np.pi], [1 / 8 * np.pi]] - shots = 10000 - - for i in range(4): - 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[i], gammas[i] - ) - - qiskit_device = DeviceQiskit( - "ibmq_qasm_simulator", self.HUB, self.GROUP, self.PROJECT - ) - - qiskit_backend = QAOAQiskitQPUBackend( - qaoa_descriptor, qiskit_device, shots, None, None, False - ) - qiskit_expectation = qiskit_backend.expectation(variate_params) - - qiskit_statevec_backend = QAOAQiskitBackendStatevecSimulator( - qaoa_descriptor, None, None, False - ) - qiskit_statevec_expectation = qiskit_statevec_backend.expectation( - variate_params - ) - - acceptable_delta = 0.05 * qiskit_statevec_expectation - self.assertAlmostEqual( - qiskit_expectation, qiskit_statevec_expectation, delta=acceptable_delta - ) + # Removed after removal of ibm_qasm_simulator backend + # @pytest.mark.sim + # def test_remote_integration_sim_run(self): + # """ + # Checks if Remote IBM QASM Simulator is similar/close to Local IBM + # Statevector Simulator. + # This test also serves as an integration test for the IBMQPU Backend. + + # This test takes a long time to complete. + # """ + + # nqubits = 3 + # p = 1 + # weights = [1, 1] + # gammas = [[0], [1 / 8 * np.pi], [0], [1 / 8 * np.pi]] + # betas = [[0], [0], [1 / 8 * np.pi], [1 / 8 * np.pi]] + # shots = 1 + + # for i in range(4): + # cost_hamil = Hamiltonian( + # [PauliOp("ZZ", (0, 1)), PauliOp("ZZ", (1, 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[i], gammas[i] + # ) + + # qiskit_device = DeviceQiskit( + # "ibmq_qasm_simulator", self.HUB, self.GROUP, self.PROJECT + # ) + + # qiskit_backend = QAOAQiskitQPUBackend( + # qaoa_descriptor, qiskit_device, shots, None, None, False + # ) + # qiskit_expectation = qiskit_backend.expectation(variate_params) + + # qiskit_statevec_backend = QAOAQiskitBackendStatevecSimulator( + # qaoa_descriptor, None, None, False + # ) + # qiskit_statevec_expectation = qiskit_statevec_backend.expectation( + # variate_params + # ) + + # acceptable_delta = 0.05 * qiskit_statevec_expectation + # self.assertAlmostEqual( + # qiskit_expectation, qiskit_statevec_expectation, delta=acceptable_delta + # ) @pytest.mark.api def test_remote_qubit_overflow(self): From 49727e767a40e0cfa60afe2c8f40fd0e54f541d3 Mon Sep 17 00:00:00 2001 From: KilianPoirier Date: Mon, 3 Jun 2024 03:18:28 +0000 Subject: [PATCH 4/8] [skip ci] Clean up docstrings and removed commented code --- examples/15_Zero_Noise_Extrapolation.ipynb | 2 +- .../openqaoa/algorithms/baseworkflow.py | 2 +- .../openqaoa/algorithms/workflow_properties.py | 2 +- src/openqaoa-core/openqaoa/backends/wrapper.py | 6 +----- src/openqaoa-qiskit/tests/test_qpu_qiskit.py | 18 ------------------ 5 files changed, 4 insertions(+), 26 deletions(-) diff --git a/examples/15_Zero_Noise_Extrapolation.ipynb b/examples/15_Zero_Noise_Extrapolation.ipynb index 5a6c5430..25b938a4 100644 --- a/examples/15_Zero_Noise_Extrapolation.ipynb +++ b/examples/15_Zero_Noise_Extrapolation.ipynb @@ -336,7 +336,7 @@ "Available options to set up the ZNE with `set_error_mitigation_properties`:\n", "\n", "- **factory**: The name of the zero-noise extrapolation method. Supported values: \"Richardson\", \"Linear\", \"Poly\", \"Exp\", \"PolyExp\", \"AdaExp\", \"FakeNodes\".\n", - "- **scaling**: The name of the function for scaling the noise of a quantum circuit. Supported values: \"fold_gates_at_random\" (\"fold_gates_from_right\", \"fold_gates_from_left\" not supported as version 0.8).\n", + "- **scaling**: The name of the function for scaling the noise of a quantum circuit. Supported values: \"fold_gates_at_random\" (\"fold_gates_from_right\", \"fold_gates_from_left\" not supported as of version 0.8).\n", "- **scale_factors**: List[int] Sequence of noise scale factors at which expectation values should be measured. For factory = \"AdaExp\", just the first element of the list will be considered.\n", "- **order**: Extrapolation order (degree of the polynomial fit). It cannot exceed len(scale_factors) - 1. Only used for factory = \"Poly\" or \"PolyExp\".\n", "- **steps**: The number of optimization steps. At least 3 are necessary. Only used for factory = \"AdaExp\"." diff --git a/src/openqaoa-core/openqaoa/algorithms/baseworkflow.py b/src/openqaoa-core/openqaoa/algorithms/baseworkflow.py index f31b33d2..454a06c3 100644 --- a/src/openqaoa-core/openqaoa/algorithms/baseworkflow.py +++ b/src/openqaoa-core/openqaoa/algorithms/baseworkflow.py @@ -283,7 +283,7 @@ def set_error_mitigation_properties(self, **kwargs): factory: str Used in "mitiq_zne". The name of the zero-noise extrapolation method. Supported values: "Richardson", "Linear", "Poly", "Exp", "PolyExp", "AdaExp", "FakeNodes". scaling: str - Used in "mitiq_zne". The name of the function for scaling the noise of a quantum circuit. Supported values: "fold_gates_at_random" ("fold_gates_from_right", "fold_gates_from_left" not supported as version 0.8) + Used in "mitiq_zne". The name of the function for scaling the noise of a quantum circuit. Supported values: "fold_gates_at_random" ("fold_gates_from_right", "fold_gates_from_left" not supported as of version 0.8) scale_factors: List[int] Used in "mitiq_zne". Sequence of noise scale factors at which expectation values should be measured. For factory = "AdaExp", just the first element of the list will be considered. diff --git a/src/openqaoa-core/openqaoa/algorithms/workflow_properties.py b/src/openqaoa-core/openqaoa/algorithms/workflow_properties.py index 4720e9c5..57d549e4 100644 --- a/src/openqaoa-core/openqaoa/algorithms/workflow_properties.py +++ b/src/openqaoa-core/openqaoa/algorithms/workflow_properties.py @@ -354,7 +354,7 @@ class MitiqZNEProperties(ErrorMitigationProperties): factory: str The name of the zero-noise extrapolation method. Supported values: "Richardson", "Linear", "Poly", "Exp", "PolyExp", "AdaExp", "FakeNodes". scaling: str - The name of the function for scaling the noise of a quantum circuit. Supported values: "fold_gates_at_random" ("fold_gates_from_right", "fold_gates_from_left" not supported as version 0.8). + The name of the function for scaling the noise of a quantum circuit. Supported values: "fold_gates_at_random" ("fold_gates_from_right", "fold_gates_from_left" not supported as of version 0.8). scale_factors: List[int] Sequence of noise scale factors at which expectation values should be measured. For factory = "AdaExp", just the first element of the list will be considered. diff --git a/src/openqaoa-core/openqaoa/backends/wrapper.py b/src/openqaoa-core/openqaoa/backends/wrapper.py index 4257ff0e..a8be6d1c 100644 --- a/src/openqaoa-core/openqaoa/backends/wrapper.py +++ b/src/openqaoa-core/openqaoa/backends/wrapper.py @@ -90,7 +90,7 @@ class ZNEWrapper(BaseWrapper): factory: str The name of the zero-noise extrapolation method. Supported values: "Richardson", "Linear", "Poly", "Exp", "PolyExp", "AdaExp", "FakeNodes". scaling: str - The name of the function for scaling the noise of a quantum circuit. Supported values: "fold_gates_at_random" ("fold_gates_from_right", "fold_gates_from_left" not supported as version 0.8). + The name of the function for scaling the noise of a quantum circuit. Supported values: "fold_gates_at_random" ("fold_gates_from_right", "fold_gates_from_left" not supported as of version 0.8). scale_factors: List[int] Sequence of noise scale factors at which expectation values should be measured. For factory = "AdaExp", just the first element of the list will be considered. @@ -143,10 +143,6 @@ def __init__(self, backend, factory, scaling, scale_factors, order, steps): self.scale_noise = None if scaling == "fold_gates_at_random": self.scale_noise = fold_gates_at_random - # elif scaling == "fold_gates_from_left": - # self.scale_noise = fold_gates_from_left - # elif scaling == "fold_gates_from_right": - # self.scale_noise = fold_gates_from_right #setting the scale_factors self.scale_factors = scale_factors diff --git a/src/openqaoa-qiskit/tests/test_qpu_qiskit.py b/src/openqaoa-qiskit/tests/test_qpu_qiskit.py index 70a9ae50..6f3a9b42 100644 --- a/src/openqaoa-qiskit/tests/test_qpu_qiskit.py +++ b/src/openqaoa-qiskit/tests/test_qpu_qiskit.py @@ -111,9 +111,6 @@ def test_circuit_angle_assignment_qpu_backend(self): main_circuit.cx(1, 2) main_circuit.rz(2 * gammas[0], 2) main_circuit.cx(1, 2) - # main_circuit.cx(0, 2) - # main_circuit.rz(2 * gammas[0], 2) - # main_circuit.cx(0, 2) main_circuit.rx(-2 * betas[0], 0) main_circuit.rx(-2 * betas[0], 1) main_circuit.rx(-2 * betas[0], 2) @@ -123,9 +120,6 @@ def test_circuit_angle_assignment_qpu_backend(self): main_circuit.cx(1, 2) main_circuit.rz(2 * gammas[1], 2) main_circuit.cx(1, 2) - # main_circuit.cx(0, 2) - # main_circuit.rz(2 * gammas[1], 2) - # main_circuit.cx(0, 2) main_circuit.rx(-2 * betas[1], 0) main_circuit.rx(-2 * betas[1], 1) main_circuit.rx(-2 * betas[1], 2) @@ -174,9 +168,6 @@ def test_circuit_angle_assignment_qpu_backend_w_hadamard(self): main_circuit.cx(0, 1) main_circuit.rz(2 * gammas[0], 1) main_circuit.cx(0, 1) - # main_circuit.cx(1, 2) - # main_circuit.rz(2 * gammas[0], 2) - # main_circuit.cx(1, 2) main_circuit.cx(0, 2) main_circuit.rz(2 * gammas[0], 2) main_circuit.cx(0, 2) @@ -189,9 +180,6 @@ def test_circuit_angle_assignment_qpu_backend_w_hadamard(self): main_circuit.cx(1, 2) main_circuit.rz(2 * gammas[1], 2) main_circuit.cx(1, 2) - # main_circuit.cx(0, 2) - # main_circuit.rz(2 * gammas[1], 2) - # main_circuit.cx(0, 2) main_circuit.rx(-2 * betas[1], 0) main_circuit.rx(-2 * betas[1], 1) main_circuit.rx(-2 * betas[1], 2) @@ -248,9 +236,6 @@ def test_prepend_circuit(self): main_circuit.cx(1, 2) main_circuit.rz(2 * gammas[0], 2) main_circuit.cx(1, 2) - # main_circuit.cx(0, 2) - # main_circuit.rz(2 * gammas[0], 2) - # main_circuit.cx(0, 2) main_circuit.rx(-2 * betas[0], 0) main_circuit.rx(-2 * betas[0], 1) main_circuit.rx(-2 * betas[0], 2) @@ -307,9 +292,6 @@ def test_append_circuit(self): main_circuit.cx(1, 2) main_circuit.rz(2 * gammas[0], 2) main_circuit.cx(1, 2) - # main_circuit.cx(0, 2) - # main_circuit.rz(2 * gammas[0], 2) - # main_circuit.cx(0, 2) main_circuit.rx(-2 * betas[0], 0) main_circuit.rx(-2 * betas[0], 1) main_circuit.rx(-2 * betas[0], 2) From 0e12b0b893ebfa0fee14fca9abaebcf8346f4756 Mon Sep 17 00:00:00 2001 From: KilianPoirier Date: Mon, 3 Jun 2024 03:19:33 +0000 Subject: [PATCH 5/8] [skip ci] Removed another commented piece of code --- src/openqaoa-qiskit/tests/test_qpu_qiskit.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/openqaoa-qiskit/tests/test_qpu_qiskit.py b/src/openqaoa-qiskit/tests/test_qpu_qiskit.py index 6f3a9b42..88793669 100644 --- a/src/openqaoa-qiskit/tests/test_qpu_qiskit.py +++ b/src/openqaoa-qiskit/tests/test_qpu_qiskit.py @@ -455,15 +455,6 @@ def test_remote_qubit_overflow(self): None, True, ) - # try: - # QAOAQiskitQPUBackend( - # qaoa_descriptor, qiskit_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.", - # ) @pytest.mark.qpu def test_integration_on_emulator(self): From 544909b59e4c6f41bb0c8927f0f9861ef087ddc8 Mon Sep 17 00:00:00 2001 From: KilianPoirier Date: Tue, 4 Jun 2024 16:50:48 +0800 Subject: [PATCH 6/8] Updated get_cmap --- src/openqaoa-core/openqaoa/utilities.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/openqaoa-core/openqaoa/utilities.py b/src/openqaoa-core/openqaoa/utilities.py index c7ad03a7..30d900fd 100644 --- a/src/openqaoa-core/openqaoa/utilities.py +++ b/src/openqaoa-core/openqaoa/utilities.py @@ -436,7 +436,7 @@ def plot_graph(G: nx.Graph, ax=None, colormap="seismic") -> None: # extract minimum and maximum weights for side bar limits weights = list(edges_and_weights.values()) # Define color map - cmap = plt.cm.get_cmap(colormap) + cmap = plt.get_cmap(colormap) if len(set(weights)) > 1: edge_vmin = min(weights) From da6a48ba4474ae51d78873d3aad2e7a280b0d583 Mon Sep 17 00:00:00 2001 From: KilianPoirier Date: Tue, 4 Jun 2024 16:51:32 +0800 Subject: [PATCH 7/8] Remove unused import --- src/openqaoa-core/requirements_test.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/openqaoa-core/requirements_test.txt b/src/openqaoa-core/requirements_test.txt index 9ca19d8a..8fbde360 100644 --- a/src/openqaoa-core/requirements_test.txt +++ b/src/openqaoa-core/requirements_test.txt @@ -4,4 +4,4 @@ pytest-cov>=3.0.0 nbconvert>=6.5.1 pandas>=1.4.3 plotly>=5.9.0 -cplex>=22.1.0.0 \ No newline at end of file +# cplex>=22.1.0.0 \ No newline at end of file From 69de0e2c5ed5ec5871cb2cf099c338e2a9874a9b Mon Sep 17 00:00:00 2001 From: KilianPoirier Date: Tue, 4 Jun 2024 17:23:13 +0800 Subject: [PATCH 8/8] [skip ci] Revert cplex requirements removal --- src/openqaoa-core/requirements_test.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/openqaoa-core/requirements_test.txt b/src/openqaoa-core/requirements_test.txt index 8fbde360..9ca19d8a 100644 --- a/src/openqaoa-core/requirements_test.txt +++ b/src/openqaoa-core/requirements_test.txt @@ -4,4 +4,4 @@ pytest-cov>=3.0.0 nbconvert>=6.5.1 pandas>=1.4.3 plotly>=5.9.0 -# cplex>=22.1.0.0 \ No newline at end of file +cplex>=22.1.0.0 \ No newline at end of file