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

Deprecate device.decompose_operation in cirq_pasqal. #4927

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cirq-pasqal/cirq_pasqal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from cirq_pasqal.pasqal_device import (
PasqalDevice,
PasqalVirtualDevice,
PasqalConverter,
)

from cirq_pasqal.pasqal_noise_model import (
Expand Down
1 change: 1 addition & 0 deletions cirq-pasqal/cirq_pasqal/json_test_data/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
test_data_path=pathlib.Path(__file__).parent,
not_yet_serializable=[],
should_not_be_serialized=[
"PasqalConverter",
"PasqalNoiseModel",
"PasqalSampler",
],
Expand Down
3 changes: 3 additions & 0 deletions cirq-pasqal/cirq_pasqal/pasqal_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ def qubit_set(self) -> FrozenSet[cirq.Qid]:
def qubit_list(self):
return [qubit for qubit in self.qubits]

@_compat.deprecated(
fix='Use PasqalConverter() to decompose operation instead.', deadline='v0.15'
)
def decompose_operation(self, operation: cirq.ops.Operation) -> 'cirq.OP_TREE':

decomposition = [operation]
Expand Down
33 changes: 18 additions & 15 deletions cirq-pasqal/cirq_pasqal/pasqal_device_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,21 @@ def test_init_errors():
square_virtual_device(control_r=11.0, num_qubits=2)


def test_decompose_error():
def test_decompose_error_deprecated():
d = generic_device(2)
op = (cirq.ops.CZ).on(*(d.qubit_list()))
assert d.decompose_operation(op) == [op]
with cirq.testing.assert_deprecated('decompose', deadline='v0.15'):
assert d.decompose_operation(op) == [op]

op = op ** sympy.Symbol('exp')
with pytest.raises(TypeError, match="Don't know how to work with "):
d.decompose_operation(op)
with cirq.testing.assert_deprecated('decompose', deadline='v0.15'):
d.decompose_operation(op)

# MeasurementGate is not a GateOperation
with pytest.raises(TypeError):
d.decompose_operation(cirq.ops.MeasurementGate(num_qubits=2, key='a'))
with cirq.testing.assert_deprecated('decompose', deadline='v0.15'):
d.decompose_operation(cirq.ops.MeasurementGate(num_qubits=2, key='a'))
# It has to be made into one
assert d.is_pasqal_device_op(
cirq.ops.GateOperation(
Expand Down Expand Up @@ -118,28 +121,26 @@ def test_is_pasqal_device_op():
op2 = (cirq.ops.H ** sympy.Symbol('exp')).on(d.qubit_list()[0])
assert not d.is_pasqal_device_op(op2)

decomp = d.decompose_operation(op2)
for op_ in decomp:
assert d.is_pasqal_device_op(op_)

d2 = square_virtual_device(control_r=1.1, num_qubits=3)
assert d.is_pasqal_device_op(cirq.ops.X(TwoDQubit(0, 0)))
assert not d2.is_pasqal_device_op(op1(TwoDQubit(0, 0), TwoDQubit(0, 1)))


def test_decompose_operation():
def test_decompose_operation_deprecated():
d = generic_device(3)
for op in d.decompose_operation((cirq.CCZ ** 1.5).on(*(d.qubit_list()))):
d.validate_operation(op)
with cirq.testing.assert_deprecated('decompose', deadline='v0.15'):
for op in d.decompose_operation((cirq.CCZ ** 1.5).on(*(d.qubit_list()))):
d.validate_operation(op)

p_qubits = [cirq.LineQubit(3), cirq.LineQubit(4)]
d = PasqalVirtualDevice(1.0, p_qubits)
op = (cirq.ops.CNOT).on(*(d.qubit_list())) ** 2

assert d.decompose_operation(op) == []
with cirq.testing.assert_deprecated('decompose', deadline='v0.15'):
assert d.decompose_operation(op) == []


def test_pasqal_converter():
def test_pasqal_converter_deprecated():
q = cirq.NamedQubit.range(2, prefix='q')
g = cirq.testing.TwoQubitGate()

Expand All @@ -159,7 +160,8 @@ def with_qubits(self, *new_qubits):
d = PasqalDevice(q)

with pytest.raises(TypeError, match="Don't know how to work with"):
d.decompose_operation(op)
with cirq.testing.assert_deprecated('decompose', deadline='v0.15'):
d.decompose_operation(op)


def test_validate_operation_errors():
Expand Down Expand Up @@ -189,7 +191,8 @@ def test_validate_operation_errors_deprecated():
with pytest.raises(
NotImplementedError, match="Measurements on Pasqal devices don't support invert_mask."
):
circuit.append(cirq.measure(*d.qubits, invert_mask=(True, False, False)))
with cirq.testing.assert_deprecated('decompose', deadline='v0.15'):
circuit.append(cirq.measure(*d.qubits, invert_mask=(True, False, False)))


def test_validate_moment():
Expand Down