Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump cirq version from 0.10.0 to 0.13.0 #988

Merged
merged 17 commits into from
Feb 2, 2022
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dev_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Third-party integration.
qiskit~=0.32.1
pyquil~=3.0.0
pennylane-qiskit~=0.18.0
pennylane~=0.19.1
pennylane-qiskit~=0.20.0
pennylane~=0.20.0
amazon-braket-sdk~=1.12.0

# Unit tests, coverage, and formatting/style.
Expand Down
2 changes: 1 addition & 1 deletion mitiq/benchmarks/tests/test_mirror_circuits.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,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
Expand Down
57 changes: 22 additions & 35 deletions mitiq/interface/mitiq_pennylane/tests/test_conversions_pennylane.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,29 +104,27 @@ def test_non_consecutive_wires_error():


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)),
vtomole marked this conversation as resolved.
Show resolved Hide resolved
qml.CRY(0.4, wires=(0, 1)),
qml.CRZ(0.4, wires=(0, 1)),
]

layers = 3
Expand All @@ -137,22 +135,11 @@ 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
)
Comment on lines -140 to -149
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you had to remove this for some tricky reason.
If not possible to re-introduce:

  • Can we restore the random rotation parameters only?
  • Can we restore the random wires only?

If not, it's fine. This is not a blocker for this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason for this change is because gate.num_params is now dynamic. Since this test is copied from pennylane, the following PR recommends re-writing the test this way. See https://github.com/PennyLaneAI/pennylane/pull/1898/files#r750946650.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see, very nice finding!

qml.apply(gate)

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

4 changes: 2 additions & 2 deletions mitiq/pec/representations/damping.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from cirq import (
Circuit,
Z,
channel,
kraus,
AmplitudeDampingChannel,
reset,
)
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions mitiq/pec/representations/depolarizing.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
Circuit,
is_measurement,
DepolarizingChannel,
channel,
kraus,
)

from mitiq import QPROGRAM
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions mitiq/pec/representations/optimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
22 changes: 11 additions & 11 deletions mitiq/pec/representations/tests/test_optimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
CZ,
Circuit,
DepolarizingChannel,
channel,
kraus,
AmplitudeDampingChannel,
ResetChannel,
reset,
Expand Down Expand Up @@ -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)
Expand All @@ -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(
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions mitiq/pec/tests/test_channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
LineQubit,
depolarize,
Circuit,
channel,
kraus,
AmplitudeDampingChannel,
Y,
)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
numpy~=1.20.1
scipy~=1.7.3
cirq~=0.10.0
cirq~=0.13.1