Skip to content

Commit 42dacc0

Browse files
dstrain115rht
authored andcommitted
Remove deprecated SingleQubitGate (quantumlib#5686)
Note: cirq.testing.SingleQubitGate still exists for brevity when writing tests.)
1 parent 50eea14 commit 42dacc0

File tree

11 files changed

+17
-111
lines changed

11 files changed

+17
-111
lines changed

cirq-core/cirq/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,6 @@
301301
rz,
302302
S,
303303
SingleQubitCliffordGate,
304-
SingleQubitGate,
305304
SingleQubitPauliStringGateOperation,
306305
SQRT_ISWAP,
307306
SQRT_ISWAP_INV,

cirq-core/cirq/ops/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787

8888
from cirq.ops.fsim_gate import FSimGate, PhasedFSimGate
8989

90-
from cirq.ops.gate_features import InterchangeableQubitsGate, SingleQubitGate
90+
from cirq.ops.gate_features import InterchangeableQubitsGate
9191

9292
from cirq.ops.gate_operation import GateOperation
9393

cirq-core/cirq/ops/gate_features.py

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@
1818
"""
1919

2020
import abc
21-
import warnings
22-
23-
from cirq import value
24-
from cirq._compat import deprecated_class
25-
from cirq.ops import raw_types
2621

2722

2823
class InterchangeableQubitsGate(metaclass=abc.ABCMeta):
@@ -31,21 +26,3 @@ class InterchangeableQubitsGate(metaclass=abc.ABCMeta):
3126
def qubit_index_to_equivalence_group_key(self, index: int) -> int:
3227
"""Returns a key that differs between non-interchangeable qubits."""
3328
return 0
34-
35-
36-
class _SingleQubitGateMeta(value.ABCMetaImplementAnyOneOf):
37-
def __instancecheck__(cls, instance):
38-
warnings.warn(
39-
'isinstance(gate, SingleQubitGate) is deprecated. '
40-
'Use cirq.num_qubits(gate) == 1 instead',
41-
DeprecationWarning,
42-
)
43-
return isinstance(instance, raw_types.Gate) and instance._num_qubits_() == 1
44-
45-
46-
@deprecated_class(deadline='v1.0', fix='Define _num_qubits_ manually.')
47-
class SingleQubitGate(raw_types.Gate, metaclass=_SingleQubitGateMeta):
48-
"""A gate that must be applied to exactly one qubit."""
49-
50-
def _num_qubits_(self) -> int:
51-
return 1

cirq-core/cirq/ops/gate_features_test.py

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -15,71 +15,6 @@
1515
import pytest
1616

1717
import cirq
18-
from cirq.testing import assert_deprecated
19-
20-
21-
def test_single_qubit_gate_validate_args():
22-
class Dummy(cirq.SingleQubitGate):
23-
def matrix(self):
24-
pass
25-
26-
with assert_deprecated(deadline="v1.0"):
27-
g = Dummy()
28-
29-
with assert_deprecated(deadline="isinstance(gate, SingleQubitGate) is deprecated"):
30-
assert isinstance(g, cirq.SingleQubitGate)
31-
q1 = cirq.NamedQubit('q1')
32-
q2 = cirq.NamedQubit('q2')
33-
34-
assert g.num_qubits() == 1
35-
g.validate_args([q1])
36-
g.validate_args([q2])
37-
with pytest.raises(ValueError):
38-
g.validate_args([])
39-
with pytest.raises(ValueError):
40-
g.validate_args([q1, q2])
41-
42-
43-
def test_single_qubit_gate_validates_on_each():
44-
class Dummy(cirq.Gate):
45-
def matrix(self):
46-
pass
47-
48-
def _num_qubits_(self) -> int:
49-
return 1
50-
51-
g = Dummy()
52-
assert g.num_qubits() == 1
53-
54-
test_qubits = [cirq.NamedQubit(str(i)) for i in range(3)]
55-
56-
_ = g.on_each(*test_qubits)
57-
_ = g.on_each(test_qubits)
58-
59-
test_non_qubits = [str(i) for i in range(3)]
60-
with pytest.raises(ValueError):
61-
_ = g.on_each(*test_non_qubits)
62-
with pytest.raises(ValueError):
63-
_ = g.on_each(*test_non_qubits)
64-
65-
66-
def test_single_qubit_validates_on():
67-
class Dummy(cirq.Gate):
68-
def matrix(self):
69-
pass
70-
71-
def _num_qubits_(self) -> int:
72-
return 1
73-
74-
g = Dummy()
75-
assert g.num_qubits() == 1
76-
77-
test_qubits = [cirq.NamedQubit(str(i)) for i in range(3)]
78-
79-
with pytest.raises(ValueError):
80-
_ = g.on(*test_qubits)
81-
with pytest.raises(ValueError):
82-
_ = g.on(*test_qubits)
8318

8419

8520
def test_qasm_output_args_validate():

cirq-core/cirq/ops/gate_operation_test.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,8 +499,6 @@ def all_subclasses(cls):
499499
cirq.circuits.quil_output.QuilTwoQubitGate,
500500
cirq.circuits.quil_output.QuilOneQubitGate,
501501
cirq.ops.MSGate,
502-
# Gate features.
503-
cirq.SingleQubitGate,
504502
# Interop gates
505503
cirq.interop.quirk.QuirkQubitPermutationGate,
506504
cirq.interop.quirk.QuirkArithmeticGate,

cirq-core/cirq/ops/raw_types.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,7 @@ class Gate(metaclass=value.ABCMetaImplementAnyOneOf):
192192
193193
Gates operate on a certain number of qubits. All implementations of gate
194194
must implement the `num_qubits` method declaring how many qubits they
195-
act on. The gate feature classes `SingleQubitGate` and `TwoQubitGate`
196-
can be used to avoid writing this boilerplate.
195+
act on.
197196
198197
Linear combinations of gates can be created by adding gates together and
199198
multiplying them by scalars.

cirq-core/cirq/protocols/json_test_data/spec.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@
117117
'Device',
118118
'InterchangeableQubitsGate',
119119
'Pauli',
120-
'SingleQubitGate',
121120
'ABCMetaImplementAnyOneOf',
122121
'SimulatesAmplitudes',
123122
'SimulatesExpectationValues',

cirq-core/cirq/transformers/analytical_decompositions/single_qubit_decompositions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"""Utility methods related to optimizing quantum circuits."""
1616

1717
import math
18-
from typing import List, Optional, Tuple, cast
18+
from typing import List, Optional, Tuple
1919

2020
import numpy as np
2121
import sympy
@@ -111,7 +111,7 @@ def single_qubit_matrix_to_gates(mat: np.ndarray, tolerance: float = 0) -> List[
111111
operation.
112112
"""
113113
rotations = single_qubit_matrix_to_pauli_rotations(mat, tolerance)
114-
return [cast(ops.SingleQubitGate, pauli) ** ht for pauli, ht in rotations]
114+
return [pauli**ht for pauli, ht in rotations]
115115

116116

117117
def single_qubit_op_to_framed_phase_form(mat: np.ndarray) -> Tuple[np.ndarray, complex, complex]:

docs/build/custom_gates.ipynb

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -222,15 +222,6 @@
222222
"print(res)"
223223
]
224224
},
225-
{
226-
"cell_type": "markdown",
227-
"metadata": {
228-
"id": "874bdef876ed"
229-
},
230-
"source": [
231-
"An alternative to inheriting from `cirq.Gate` is to inherit from `cirq.SingleQubitGate`, in which case defining `_num_qubits_` is unnecessary. An example of a defining a two-qubit gate is shown below."
232-
]
233-
},
234225
{
235226
"cell_type": "code",
236227
"execution_count": null,

docs/simulate/noisy_simulation.ipynb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,9 @@
476476
"outputs": [],
477477
"source": [
478478
"\"\"\"Minimal example of defining a custom channel.\"\"\"\n",
479-
"class BitAndPhaseFlipChannel(cirq.SingleQubitGate):\n",
479+
"class BitAndPhaseFlipChannel(cirq.Gate):\n",
480+
" def _num_qubits_(self) -> int:\n",
481+
" return 1\n",
480482
" def __init__(self, p: float) -> None:\n",
481483
" self._p = p\n",
482484
" \n",

0 commit comments

Comments
 (0)