From f5a21cbe8be524bcd47021f16d794e207a56aa2d Mon Sep 17 00:00:00 2001 From: Victory Omole Date: Sat, 16 Oct 2021 19:34:19 -0500 Subject: [PATCH 01/10] Bump cirq version from `0.10.0` to `0.13.0` Replacing https://github.com/unitaryfund/mitiq/pull/915 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 7c4110215..a12fe75f2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ numpy~=1.20.1 scipy~=1.7.1 -cirq~=0.10.0 +cirq~=0.13.0 From c553e852380068fec31257a917f002e36771b6af Mon Sep 17 00:00:00 2001 From: vtomole Date: Tue, 19 Oct 2021 09:57:37 -0500 Subject: [PATCH 02/10] channel -> kraus --- docs/source/examples/pec-tutorial.myst | 2 +- mitiq/pec/representations/damping.py | 4 ++-- mitiq/pec/representations/depolarizing.py | 4 ++-- mitiq/pec/representations/optimal.py | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/source/examples/pec-tutorial.myst b/docs/source/examples/pec-tutorial.myst index ab89cd405..6bc3a6c7f 100644 --- a/docs/source/examples/pec-tutorial.myst +++ b/docs/source/examples/pec-tutorial.myst @@ -49,7 +49,7 @@ from IPython.display import display as ipython_display from matplotlib import pyplot as plt import numpy as np -from cirq import LineQubit, NamedQubit, Circuit, X, Y, Z, channel, H, CNOT, depolarize, DensityMatrixSimulator +from cirq import LineQubit, NamedQubit, Circuit, X, Y, Z, kraus, H, CNOT, depolarize, DensityMatrixSimulator from mitiq import pec from mitiq.pec import NoisyOperation, OperationRepresentation diff --git a/mitiq/pec/representations/damping.py b/mitiq/pec/representations/damping.py index 71208cf22..ae0c15e98 100644 --- a/mitiq/pec/representations/damping.py +++ b/mitiq/pec/representations/damping.py @@ -22,7 +22,7 @@ from cirq import ( Circuit, Z, - channel, + kraus, AmplitudeDampingChannel, reset, ) @@ -102,7 +102,7 @@ def amplitude_damping_kraus( depolarizing channels acting on each qubit. """ local_noisy_op = AmplitudeDampingChannel(noise_level) - local_kraus = list(channel(local_noisy_op)) + local_kraus = list(kraus(local_noisy_op)) return [ tensor_product(*kraus_string) for kraus_string in product(local_kraus, repeat=num_qubits) diff --git a/mitiq/pec/representations/depolarizing.py b/mitiq/pec/representations/depolarizing.py index 881a69e6a..8361414b5 100644 --- a/mitiq/pec/representations/depolarizing.py +++ b/mitiq/pec/representations/depolarizing.py @@ -27,7 +27,7 @@ Circuit, is_measurement, DepolarizingChannel, - channel, + kraus, ) from mitiq import QPROGRAM @@ -339,7 +339,7 @@ def global_depolarizing_kraus( given noise level. """ noisy_op = DepolarizingChannel(noise_level, num_qubits) - return list(channel(noisy_op)) + return list(kraus(noisy_op)) def local_depolarizing_kraus( diff --git a/mitiq/pec/representations/optimal.py b/mitiq/pec/representations/optimal.py index 59820965d..241c627cc 100644 --- a/mitiq/pec/representations/optimal.py +++ b/mitiq/pec/representations/optimal.py @@ -20,7 +20,7 @@ import numpy as np from scipy.optimize import minimize, LinearConstraint -from cirq import channel +from cirq import kraus from mitiq import QPROGRAM from mitiq.interface import convert_to_mitiq @@ -127,7 +127,7 @@ def find_optimal_representation( """ ideal_cirq_circuit, _ = convert_to_mitiq(ideal_operation) ideal_matrix = kraus_to_super( - cast(List[np.ndarray], channel(ideal_cirq_circuit)) + cast(List[np.ndarray], kraus(ideal_cirq_circuit)) ) basis_set = noisy_basis.elements From 33dd69729ef5628b4ebd2a94c9ea31a0af3be769 Mon Sep 17 00:00:00 2001 From: vtomole Date: Fri, 22 Oct 2021 15:36:07 -0500 Subject: [PATCH 03/10] Change other stuff to channel --- .../pec/representations/tests/test_optimal.py | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/mitiq/pec/representations/tests/test_optimal.py b/mitiq/pec/representations/tests/test_optimal.py index 154331b6c..f83fe4312 100644 --- a/mitiq/pec/representations/tests/test_optimal.py +++ b/mitiq/pec/representations/tests/test_optimal.py @@ -28,7 +28,7 @@ CZ, Circuit, DepolarizingChannel, - channel, + kraus, AmplitudeDampingChannel, ResetChannel, reset, @@ -91,9 +91,9 @@ def test_minimize_one_norm_with_depolarized_superoperators(): for noise_level in [0.01, 0.02, 0.03]: depo_kraus = global_depolarizing_kraus(noise_level, num_qubits=1) depo_super = kraus_to_super(depo_kraus) - ideal_matrix = kraus_to_super(channel(H)) + ideal_matrix = kraus_to_super(kraus(H)) basis_matrices = [ - depo_super @ kraus_to_super(channel(gate)) @ ideal_matrix + depo_super @ kraus_to_super(kraus(gate)) @ ideal_matrix for gate in [I, X, Y, Z, H] ] optimal_coeffs = minimize_one_norm(ideal_matrix, basis_matrices) @@ -119,7 +119,7 @@ def test_minimize_one_norm_with_amp_damp_choi(): for gate in [I, Z] ] # Append reset channel - reset_kraus = channel(ResetChannel()) + reset_kraus = kraus(ResetChannel()) basis_matrices.append(kraus_to_choi(reset_kraus)) optimal_coeffs = minimize_one_norm(ideal_matrix, basis_matrices) represented_mat = sum( @@ -136,13 +136,13 @@ def test_minimize_one_norm_with_amp_damp_superoperators(): for noise_level in [0.01, 0.02, 0.03]: damp_kraus = amplitude_damping_kraus(noise_level, num_qubits=1) damp_super = kraus_to_super(damp_kraus) - ideal_matrix = kraus_to_super(channel(H)) + ideal_matrix = kraus_to_super(kraus(H)) basis_matrices = [ - damp_super @ kraus_to_super(channel(gate)) @ ideal_matrix + damp_super @ kraus_to_super(kraus(gate)) @ ideal_matrix for gate in [I, Z] ] # Append reset channel - reset_kraus = channel(ResetChannel()) + reset_kraus = kraus(ResetChannel()) basis_matrices.append(kraus_to_super(reset_kraus)) optimal_coeffs = minimize_one_norm( ideal_matrix, basis_matrices, tol=1.0e-6 @@ -160,9 +160,9 @@ def test_minimize_one_norm_with_amp_damp_superoperators(): def test_minimize_one_norm_tolerance(): depo_kraus = global_depolarizing_kraus(noise_level=0.1, num_qubits=1) depo_super = kraus_to_super(depo_kraus) - ideal_matrix = kraus_to_super(channel(H)) + ideal_matrix = kraus_to_super(kraus(H)) basis_matrices = [ - depo_super @ kraus_to_super(channel(gate)) @ ideal_matrix + depo_super @ kraus_to_super(kraus(gate)) @ ideal_matrix for gate in [I, X, Y, Z] ] previous_minimum = 0.0 @@ -332,9 +332,9 @@ def test_initial_guess_in_minimize_one_norm(): for noise_level in [0.7, 0.9]: depo_kraus = global_depolarizing_kraus(noise_level, num_qubits=1) depo_super = kraus_to_super(depo_kraus) - ideal_matrix = kraus_to_super(channel(H)) + ideal_matrix = kraus_to_super(kraus(H)) basis_matrices = [ - depo_super @ kraus_to_super(channel(gate)) @ ideal_matrix + depo_super @ kraus_to_super(kraus(gate)) @ ideal_matrix for gate in [I, X, Y, Z, H] ] optimal_coeffs = minimize_one_norm( From e35c42d032a076412aef974f65b372c98a8d59d0 Mon Sep 17 00:00:00 2001 From: vtomole Date: Fri, 22 Oct 2021 15:38:35 -0500 Subject: [PATCH 04/10] Change to kraus as well --- mitiq/pec/tests/test_channels.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mitiq/pec/tests/test_channels.py b/mitiq/pec/tests/test_channels.py index b043eb107..c05eb9d5f 100644 --- a/mitiq/pec/tests/test_channels.py +++ b/mitiq/pec/tests/test_channels.py @@ -21,7 +21,7 @@ LineQubit, depolarize, Circuit, - channel, + kraus, AmplitudeDampingChannel, Y, ) @@ -151,7 +151,7 @@ def test_super_to_choi(): for noise_level in [0, 0.3, 1]: super_damping = kraus_to_super(amplitude_damping_kraus(noise_level, 1)) # Apply Pauli Y to get some complex numbers - super_op = np.kron(channel(Y)[0], channel(Y)[0].conj()) @ super_damping + super_op = np.kron(kraus(Y)[0], kraus(Y)[0].conj()) @ super_damping choi_state = super_to_choi(super_op) # expected result q = LineQubit(0) From bee340b4ea622d07062ffba305b79bda4e6b55d6 Mon Sep 17 00:00:00 2001 From: Victory Omole Date: Tue, 14 Dec 2021 11:57:17 -0600 Subject: [PATCH 05/10] Update dev_requirements.txt --- dev_requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev_requirements.txt b/dev_requirements.txt index 7a30a2d56..fe0b146ac 100644 --- a/dev_requirements.txt +++ b/dev_requirements.txt @@ -3,7 +3,7 @@ qiskit-terra~=0.18.2 qiskit-aer~=0.8.2 qiskit-ibmq-provider~=0.16.0 pyquil~=3.0.0 -pennylane-qiskit~=0.18.0 +pennylane-qiskit~=0.20.0 pennylane~=0.18.0 amazon-braket-sdk~=1.9.5 From 8f7cf6cd9f0094b1ec9cc685635a70c5d53b5c8f Mon Sep 17 00:00:00 2001 From: Victory Omole Date: Tue, 14 Dec 2021 12:07:54 -0600 Subject: [PATCH 06/10] Update dev_requirements.txt --- dev_requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev_requirements.txt b/dev_requirements.txt index 8e693dd29..047365797 100644 --- a/dev_requirements.txt +++ b/dev_requirements.txt @@ -2,7 +2,7 @@ qiskit~=0.32.1 pyquil~=3.0.0 pennylane-qiskit~=0.20.0 -pennylane~=0.19.1 +pennylane~=0.20.0 amazon-braket-sdk~=1.11.0 # Unit tests, coverage, and formatting/style. From 272d52772588e1d550bb4053d29a7c1b95868e94 Mon Sep 17 00:00:00 2001 From: vtomole Date: Wed, 15 Dec 2021 15:29:43 -0600 Subject: [PATCH 07/10] Small changes to check if things pass --- mitiq/benchmarks/tests/test_mirror_circuits.py | 2 +- .../tests/test_conversions_pennylane.py | 11 +---------- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/mitiq/benchmarks/tests/test_mirror_circuits.py b/mitiq/benchmarks/tests/test_mirror_circuits.py index 69f25b02d..a71450ed7 100644 --- a/mitiq/benchmarks/tests/test_mirror_circuits.py +++ b/mitiq/benchmarks/tests/test_mirror_circuits.py @@ -137,7 +137,7 @@ def test_generate_mirror_circuit(depth_twoqprob_graph): result = ( cirq.Simulator() .run(circ, repetitions=1_000) - .multi_measurement_histogram(keys=circ.all_measurement_keys()) + .multi_measurement_histogram(keys=circ.all_measurement_key_names()) ) assert ( len(result.keys()) == 1 diff --git a/mitiq/interface/mitiq_pennylane/tests/test_conversions_pennylane.py b/mitiq/interface/mitiq_pennylane/tests/test_conversions_pennylane.py index b4bfe2d8e..125c7d043 100644 --- a/mitiq/interface/mitiq_pennylane/tests/test_conversions_pennylane.py +++ b/mitiq/interface/mitiq_pennylane/tests/test_conversions_pennylane.py @@ -137,16 +137,7 @@ def test_integration(): np.random.seed(1967) for gates in gates_per_layers: for gate in gates: - params = list(np.pi * np.random.rand(gate.num_params)) - rnd_wires = np.random.choice( - range(n_wires), size=gate.num_wires, replace=False - ) - gate( - *params, - wires=[ - int(w) for w in rnd_wires - ], # make sure we do not address wires as 0-d arrays - ) + qml.apply(gate) base_circ = from_pennylane(tape) tape_recovered = to_pennylane(base_circ) From 663c7dffaa54522df0766077cff2ea20190b20bc Mon Sep 17 00:00:00 2001 From: vtomole Date: Sat, 22 Jan 2022 00:50:03 -0600 Subject: [PATCH 08/10] Check for global phase --- .../tests/test_conversions_pennylane.py | 49 +++++++++---------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/mitiq/interface/mitiq_pennylane/tests/test_conversions_pennylane.py b/mitiq/interface/mitiq_pennylane/tests/test_conversions_pennylane.py index 125c7d043..db21d12d8 100644 --- a/mitiq/interface/mitiq_pennylane/tests/test_conversions_pennylane.py +++ b/mitiq/interface/mitiq_pennylane/tests/test_conversions_pennylane.py @@ -98,35 +98,34 @@ def test_non_consecutive_wires_error(): with qml.tape.QuantumTape() as tape: qml.CNOT(wires=[0, 2]) with pytest.raises( - UnsupportedQuantumTapeError, match="contiguously pack", + UnsupportedQuantumTapeError, + match="contiguously pack", ): from_pennylane(tape) def test_integration(): - n_wires = 4 - gates = [ - qml.PauliX, - qml.PauliY, - qml.PauliZ, - qml.S, - qml.T, - qml.RX, - qml.RY, - qml.RZ, - qml.Hadamard, - qml.Rot, - qml.CRot, - qml.Toffoli, - qml.SWAP, - qml.CSWAP, - qml.U1, - qml.U2, - qml.U3, - qml.CRX, - qml.CRY, - qml.CRZ, + qml.PauliX(wires=0), + qml.PauliY(wires=0), + qml.PauliZ(wires=0), + qml.S(wires=0), + qml.T(wires=0), + qml.RX(0.4, wires=0), + qml.RY(0.4, wires=0), + qml.RZ(0.4, wires=0), + qml.Hadamard(wires=0), + qml.Rot(0.4, 0.5, 0.6, wires=1), + qml.CRot(0.4, 0.5, 0.6, wires=(0, 1)), + qml.Toffoli(wires=(0, 1, 2)), + qml.SWAP(wires=(0, 1)), + qml.CSWAP(wires=(0, 1, 2)), + qml.U1(0.4, wires=0), + qml.U2(0.4, 0.5, wires=0), + qml.U3(0.4, 0.5, 0.6, wires=0), + qml.CRX(0, wires=(0, 1)), + qml.CRY(0.4, wires=(0, 1)), + qml.CRZ(0.4, wires=(0, 1)), ] layers = 3 @@ -142,8 +141,6 @@ def test_integration(): base_circ = from_pennylane(tape) tape_recovered = to_pennylane(base_circ) circ_recovered = from_pennylane(tape_recovered) - u_1 = cirq.unitary(base_circ) u_2 = cirq.unitary(circ_recovered) - - assert np.allclose(u_1, u_2) + cirq.testing.assert_allclose_up_to_global_phase(u_1, u_2, atol=0) From d9b05d4a3e892d767b24a0563a8d647a4d912e42 Mon Sep 17 00:00:00 2001 From: vtomole Date: Thu, 27 Jan 2022 12:11:40 -0600 Subject: [PATCH 09/10] Format --- .../mitiq_pennylane/tests/test_conversions_pennylane.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mitiq/interface/mitiq_pennylane/tests/test_conversions_pennylane.py b/mitiq/interface/mitiq_pennylane/tests/test_conversions_pennylane.py index db21d12d8..22a975a21 100644 --- a/mitiq/interface/mitiq_pennylane/tests/test_conversions_pennylane.py +++ b/mitiq/interface/mitiq_pennylane/tests/test_conversions_pennylane.py @@ -98,8 +98,7 @@ def test_non_consecutive_wires_error(): with qml.tape.QuantumTape() as tape: qml.CNOT(wires=[0, 2]) with pytest.raises( - UnsupportedQuantumTapeError, - match="contiguously pack", + UnsupportedQuantumTapeError, match="contiguously pack", ): from_pennylane(tape) From d9a8cd13904b3aa2c2f7f93a2184aec5a338754c Mon Sep 17 00:00:00 2001 From: Victory Omole Date: Fri, 28 Jan 2022 11:11:03 -0600 Subject: [PATCH 10/10] Update mitiq/interface/mitiq_pennylane/tests/test_conversions_pennylane.py Co-authored-by: Andrea Mari <46054446+andreamari@users.noreply.github.com> --- .../mitiq_pennylane/tests/test_conversions_pennylane.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mitiq/interface/mitiq_pennylane/tests/test_conversions_pennylane.py b/mitiq/interface/mitiq_pennylane/tests/test_conversions_pennylane.py index 22a975a21..decc4ea82 100644 --- a/mitiq/interface/mitiq_pennylane/tests/test_conversions_pennylane.py +++ b/mitiq/interface/mitiq_pennylane/tests/test_conversions_pennylane.py @@ -122,7 +122,7 @@ def test_integration(): qml.U1(0.4, wires=0), qml.U2(0.4, 0.5, wires=0), qml.U3(0.4, 0.5, 0.6, wires=0), - qml.CRX(0, wires=(0, 1)), + qml.CRX(0.4, wires=(0, 1)), qml.CRY(0.4, wires=(0, 1)), qml.CRZ(0.4, wires=(0, 1)), ]