Skip to content

Commit 1b7a800

Browse files
Remove can_add_operation_into_moment deprecation. (#5379)
Yet more v0.15 device deprecation reomvals.
1 parent 0f4c10f commit 1b7a800

File tree

9 files changed

+1
-146
lines changed

9 files changed

+1
-146
lines changed

cirq-core/cirq/circuits/circuit_test.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,7 @@
2929

3030

3131
class _Foxy(ValidatingTestDevice):
32-
def can_add_operation_into_moment(
33-
self, operation: 'cirq.Operation', moment: 'cirq.Moment'
34-
) -> bool:
35-
if not super().can_add_operation_into_moment(operation, moment):
36-
return False
37-
# a fake rule for ensuring that no two CZs are executed at the same moment.
38-
# this will ensure that CZs are always in separate moments in this device
39-
return not (
40-
isinstance(operation.gate, ops.CZPowGate)
41-
and any(isinstance(op.gate, ops.CZPowGate) for op in moment.operations)
42-
)
32+
pass
4333

4434

4535
FOXY = _Foxy(

cirq-core/cirq/devices/device.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -77,28 +77,6 @@ def validate_moment(self, moment: 'cirq.Moment') -> None:
7777
for operation in moment.operations:
7878
self.validate_operation(operation)
7979

80-
@_compat.deprecated(
81-
deadline='v0.15',
82-
fix='can_add_operation_into_moment will be removed in the future.'
83-
' Consider using device.validate_circuit instead.',
84-
)
85-
def can_add_operation_into_moment(
86-
self, operation: 'cirq.Operation', moment: 'cirq.Moment'
87-
) -> bool:
88-
"""Determines if it's possible to add an operation into a moment.
89-
90-
For example, on the XmonDevice two CZs shouldn't be placed in the same
91-
moment if they are on adjacent qubits.
92-
93-
Args:
94-
operation: The operation being added.
95-
moment: The moment being transformed.
96-
97-
Returns:
98-
Whether or not the moment will validate after adding the operation.
99-
"""
100-
return not moment.operates_on(operation.qubits)
101-
10280

10381
@value.value_equality
10482
class DeviceMetadata:

cirq-core/cirq/ion/ion_device_test.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -165,24 +165,6 @@ def num_qubits(self):
165165
d.validate_operation(NotImplementedOperation())
166166

167167

168-
def test_can_add_operation_into_moment_device_deprecated():
169-
with cirq.testing.assert_deprecated('can_add_operation_into_moment', deadline='v0.15', count=6):
170-
d = ion_device(3)
171-
q0 = cirq.LineQubit(0)
172-
q1 = cirq.LineQubit(1)
173-
q2 = cirq.LineQubit(2)
174-
q3 = cirq.LineQubit(3)
175-
circuit = cirq.Circuit()
176-
circuit.append(cirq.XX(q0, q1))
177-
for moment in circuit:
178-
assert not d.can_add_operation_into_moment(cirq.XX(q2, q0), moment)
179-
assert not d.can_add_operation_into_moment(cirq.XX(q1, q2), moment)
180-
assert d.can_add_operation_into_moment(cirq.XX(q2, q3), moment)
181-
assert d.can_add_operation_into_moment(cirq.Z(q3), moment)
182-
circuit = cirq.Circuit([cirq.X(q0)])
183-
assert d.can_add_operation_into_moment(cirq.XX(q1, q2), circuit[0])
184-
185-
186168
def test_ion_device_eq():
187169
eq = cirq.testing.EqualsTester()
188170
eq.make_equality_group(lambda: ion_device(3))

cirq-core/cirq/neutral_atoms/neutral_atom_devices.py

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -250,31 +250,6 @@ def _are_qubit_lists_too_close(self, *qubit_lists: Iterable[raw_types.Qid]) -> b
250250
self._are_qubit_lists_too_close(a, b) for a, b in itertools.combinations(qubit_lists, 2)
251251
)
252252

253-
def can_add_operation_into_moment(
254-
self, operation: ops.Operation, moment: circuits.Moment
255-
) -> bool:
256-
"""Determines if it's possible to add an operation into a moment.
257-
258-
An operation can be added if the moment with the operation added is valid.
259-
260-
Args:
261-
operation: The operation being added.
262-
moment: The moment being transformed.
263-
264-
Returns:
265-
Whether or not the moment will validate after adding the operation.
266-
267-
Raises:
268-
ValueError: If either of the given moment or operation is invalid
269-
"""
270-
if not super().can_add_operation_into_moment(operation, moment):
271-
return False
272-
try:
273-
self.validate_moment(moment.with_operation(operation))
274-
except:
275-
return False
276-
return True
277-
278253
def validate_circuit(self, circuit: circuits.AbstractCircuit):
279254
"""Raises an error if the given circuit is invalid on this device.
280255

cirq-core/cirq/neutral_atoms/neutral_atom_devices_test.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -236,18 +236,6 @@ def test_validate_moment_errors():
236236
d2.validate_moment(m)
237237

238238

239-
def test_can_add_operation_into_moment_coverage_deprecated():
240-
with cirq.testing.assert_deprecated('can_add_operation_into_moment', deadline='v0.15', count=4):
241-
d = square_device(2, 2)
242-
q00 = cirq.GridQubit(0, 0)
243-
q01 = cirq.GridQubit(0, 1)
244-
q10 = cirq.GridQubit(1, 0)
245-
m = cirq.Moment([cirq.X.on(q00)])
246-
assert not d.can_add_operation_into_moment(cirq.X.on(q00), m)
247-
assert not d.can_add_operation_into_moment(cirq.CZ.on(q01, q10), m)
248-
assert d.can_add_operation_into_moment(cirq.Z.on(q01), m)
249-
250-
251239
def test_validate_circuit_errors():
252240
d = square_device(2, 2, max_controls=3)
253241
q00 = cirq.GridQubit(0, 0)

cirq-google/cirq_google/devices/xmon_device.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -186,18 +186,6 @@ def validate_moment(self, moment: cirq.Moment):
186186
):
187187
raise ValueError(f'Adjacent Exp11 operations: {moment}.')
188188

189-
def can_add_operation_into_moment(self, operation: cirq.Operation, moment: cirq.Moment) -> bool:
190-
self.validate_moment(moment)
191-
192-
if not super().can_add_operation_into_moment(operation, moment):
193-
return False
194-
if isinstance(operation.gate, cirq.CZPowGate):
195-
return not self._check_if_exp11_operation_interacts_with_any(
196-
cast(cirq.GateOperation, operation),
197-
cast(Iterable[cirq.GateOperation], moment.operations),
198-
)
199-
return True
200-
201189
def at(self, row: int, col: int) -> Optional[cirq.GridQubit]:
202190
"""Returns the qubit at the given position, if there is one, else None."""
203191
q = cirq.GridQubit(row, col)

cirq-google/cirq_google/devices/xmon_device_test.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -142,18 +142,6 @@ def test_repr():
142142
)
143143

144144

145-
@mock.patch.dict(os.environ, clear='CIRQ_TESTING')
146-
def test_can_add_operation_into_moment():
147-
148-
d = square_device(2, 2)
149-
q00 = cirq.GridQubit(0, 0)
150-
q01 = cirq.GridQubit(0, 1)
151-
q10 = cirq.GridQubit(1, 0)
152-
q11 = cirq.GridQubit(1, 1)
153-
m = cirq.Moment([cirq.CZ(q00, q01)])
154-
assert not d.can_add_operation_into_moment(cirq.CZ(q10, q11), m)
155-
156-
157145
@mock.patch.dict(os.environ, clear='CIRQ_TESTING')
158146
def test_validate_moment():
159147

cirq-pasqal/cirq_pasqal/pasqal_device.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -183,30 +183,6 @@ def validate_circuit(self, circuit: 'cirq.AbstractCircuit') -> None:
183183
if isinstance(operation.gate, cirq.MeasurementGate):
184184
has_measurement_occurred = True
185185

186-
def can_add_operation_into_moment(self, operation: cirq.Operation, moment: cirq.Moment) -> bool:
187-
"""Determines if it's possible to add an operation into a moment.
188-
189-
An operation can be added if the moment with the operation added is
190-
valid.
191-
192-
Args:
193-
operation: The operation being added.
194-
moment: The moment being transformed.
195-
196-
Returns:
197-
Whether or not the moment will validate after adding the operation.
198-
199-
Raises:
200-
ValueError: If either of the given moment or operation is invalid
201-
"""
202-
if not super().can_add_operation_into_moment(operation, moment):
203-
return False
204-
try:
205-
self.validate_moment(moment.with_operation(operation))
206-
except ValueError:
207-
return False
208-
return True
209-
210186
def __repr__(self):
211187
return f'pasqal.PasqalDevice(qubits={sorted(self.qubits)!r})'
212188

cirq-pasqal/cirq_pasqal/pasqal_device_test.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -193,16 +193,6 @@ def test_validate_circuit():
193193
d.validate_circuit(circuit1)
194194

195195

196-
def test_can_add_operation_into_moment_deprecated():
197-
d = square_virtual_device(control_r=1.0, num_qubits=2)
198-
with cirq.testing.assert_deprecated('can_add_operation_into_moment', deadline='v0.15', count=3):
199-
m1 = cirq.Moment([cirq.Z.on(TwoDQubit(0, 0))])
200-
assert not d.can_add_operation_into_moment(cirq.X.on(TwoDQubit(0, 0)), m1)
201-
assert not d.can_add_operation_into_moment(cirq.X.on(TwoDQubit(1, 1)), m1)
202-
m2 = cirq.Moment([cirq.measure(*d.qubits[:-1])])
203-
assert d.can_add_operation_into_moment(cirq.measure(TwoDQubit(1, 1)), m2)
204-
205-
206196
def test_minimal_distance():
207197
dev = square_virtual_device(control_r=1.0, num_qubits=1)
208198

0 commit comments

Comments
 (0)