Skip to content

Commit 2fdb447

Browse files
authored
Remove dummy from cirq-core (#6356)
* Remove dummy from cirq-core - Latest best practice advice is to remove all mentions of the word 'dummy' as it is problematic terminology.
1 parent 3a64ef1 commit 2fdb447

26 files changed

+120
-123
lines changed

cirq-core/cirq/circuits/qasm_output_test.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -248,26 +248,26 @@ class UnsupportedOperation(cirq.Operation):
248248

249249

250250
def _all_operations(q0, q1, q2, q3, q4, include_measurements=True):
251-
class DummyOperation(cirq.Operation):
251+
class ExampleOperation(cirq.Operation):
252252
qubits = (q0,)
253253
with_qubits = NotImplemented
254254

255255
def _qasm_(self, args: cirq.QasmArgs) -> str:
256-
return '// Dummy operation\n'
256+
return '// Example operation\n'
257257

258258
def _decompose_(self):
259259
# Only used by test_output_unitary_same_as_qiskit
260260
return () # pragma: no cover
261261

262-
class DummyCompositeOperation(cirq.Operation):
262+
class ExampleCompositeOperation(cirq.Operation):
263263
qubits = (q0,)
264264
with_qubits = NotImplemented
265265

266266
def _decompose_(self):
267267
return cirq.X(self.qubits[0])
268268

269269
def __repr__(self):
270-
return 'DummyCompositeOperation()'
270+
return 'ExampleCompositeOperation()'
271271

272272
return (
273273
cirq.I(q0),
@@ -328,8 +328,8 @@ def __repr__(self):
328328
)
329329
if include_measurements
330330
else (),
331-
DummyOperation(),
332-
DummyCompositeOperation(),
331+
ExampleOperation(),
332+
ExampleCompositeOperation(),
333333
)
334334

335335

@@ -539,9 +539,9 @@ def filter_unpredictable_numbers(text):
539539
x q[2]; // Undo the inversion
540540
measure q[3] -> m_multi[2];
541541
542-
// Dummy operation
542+
// Example operation
543543
544-
// Operation: DummyCompositeOperation()
544+
// Operation: ExampleCompositeOperation()
545545
x q[0];
546546
"""
547547
)

cirq-core/cirq/contrib/paulistring/clifford_target_gateset_test.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -182,23 +182,23 @@ def test_already_converted():
182182

183183

184184
def test_ignore_unsupported_gate():
185-
class UnsupportedDummy(cirq.testing.TwoQubitGate):
185+
class UnsupportedGate(cirq.testing.TwoQubitGate):
186186
pass
187187

188188
q0, q1 = cirq.LineQubit.range(2)
189-
c_orig = cirq.Circuit(UnsupportedDummy()(q0, q1), cirq.X(q0) ** sympy.Symbol("theta"))
189+
c_orig = cirq.Circuit(UnsupportedGate()(q0, q1), cirq.X(q0) ** sympy.Symbol("theta"))
190190
c_new = cirq.optimize_for_target_gateset(
191191
c_orig, gateset=CliffordTargetGateset(), ignore_failures=True
192192
)
193193
assert c_new == c_orig
194194

195195

196196
def test_fail_unsupported_gate():
197-
class UnsupportedDummy(cirq.testing.TwoQubitGate):
197+
class UnsupportedGate(cirq.testing.TwoQubitGate):
198198
pass
199199

200200
q0, q1 = cirq.LineQubit.range(2)
201-
c_orig = cirq.Circuit(UnsupportedDummy()(q0, q1))
201+
c_orig = cirq.Circuit(UnsupportedGate()(q0, q1))
202202
with pytest.raises(ValueError):
203203
_ = cirq.optimize_for_target_gateset(
204204
c_orig, gateset=CliffordTargetGateset(), ignore_failures=False

cirq-core/cirq/experiments/xeb_fitting_test.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ def test_benchmark_2q_xeb_fidelities_parallel():
129129

130130
def test_benchmark_2q_xeb_fidelities_vectorized():
131131
rs = np.random.RandomState(52)
132-
dummy_records = [{'pure_probs': rs.rand(4), 'sampled_probs': rs.rand(4)} for _ in range(100)]
133-
df = pd.DataFrame(dummy_records)
132+
mock_records = [{'pure_probs': rs.rand(4), 'sampled_probs': rs.rand(4)} for _ in range(100)]
133+
df = pd.DataFrame(mock_records)
134134

135135
# Using `df.apply` is wayyyy slower than the new implementation!
136136
# but they should give the same results

cirq-core/cirq/experiments/xeb_sampling.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def _verify_two_line_qubits_from_circuits(circuits: Sequence['cirq.Circuit']):
130130

131131

132132
class _NoProgress:
133-
"""Dummy (lack of) tqdm-style progress bar."""
133+
"""Lack of tqdm-style progress bar."""
134134

135135
def __init__(self, total: int):
136136
pass

cirq-core/cirq/ops/clifford_gate_test.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import pytest
2121

2222
import cirq
23-
from cirq.protocols.act_on_protocol_test import DummySimulationState
23+
from cirq.protocols.act_on_protocol_test import ExampleSimulationState
2424
from cirq.testing import EqualsTester, assert_allclose_up_to_global_phase
2525

2626
_bools = (False, True)
@@ -47,7 +47,7 @@ def _assert_no_collision(gate) -> None:
4747

4848

4949
def _all_rotations():
50-
for (pauli, flip) in itertools.product(_paulis, _bools):
50+
for pauli, flip in itertools.product(_paulis, _bools):
5151
yield (pauli, flip)
5252

5353

@@ -490,7 +490,6 @@ def test_commutes_pauli(gate, pauli, half_turns):
490490

491491

492492
def test_to_clifford_tableau_util_function():
493-
494493
tableau = cirq.ops.clifford_gate._to_clifford_tableau(
495494
x_to=(cirq.X, False), z_to=(cirq.Z, False)
496495
)
@@ -879,7 +878,7 @@ def test_clifford_gate_act_on_ch_form():
879878

880879
def test_clifford_gate_act_on_fail():
881880
with pytest.raises(TypeError, match="Failed to act"):
882-
cirq.act_on(cirq.CliffordGate.X, DummySimulationState(), qubits=())
881+
cirq.act_on(cirq.CliffordGate.X, ExampleSimulationState(), qubits=())
883882

884883

885884
def test_all_single_qubit_clifford_unitaries():

cirq-core/cirq/ops/common_channels_test.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import pytest
1919

2020
import cirq
21-
from cirq.protocols.act_on_protocol_test import DummySimulationState
21+
from cirq.protocols.act_on_protocol_test import ExampleSimulationState
2222

2323
X = np.array([[0, 1], [1, 0]])
2424
Y = np.array([[0, -1j], [1j, 0]])
@@ -87,7 +87,6 @@ def test_asymmetric_depolarizing_channel_str():
8787

8888

8989
def test_asymmetric_depolarizing_channel_eq():
90-
9190
a = cirq.asymmetric_depolarize(0.0099999, 0.01)
9291
b = cirq.asymmetric_depolarize(0.01, 0.0099999)
9392
c = cirq.asymmetric_depolarize(0.0, 0.0, 0.0)
@@ -492,7 +491,7 @@ def test_reset_channel_text_diagram():
492491

493492
def test_reset_act_on():
494493
with pytest.raises(TypeError, match="Failed to act"):
495-
cirq.act_on(cirq.ResetChannel(), DummySimulationState(), qubits=())
494+
cirq.act_on(cirq.ResetChannel(), ExampleSimulationState(), qubits=())
496495

497496
args = cirq.StateVectorSimulationState(
498497
available_buffer=np.empty(shape=(2, 2, 2, 2, 2), dtype=np.complex64),
@@ -697,7 +696,6 @@ def test_bit_flip_channel_str():
697696

698697

699698
def test_bit_flip_channel_eq():
700-
701699
a = cirq.bit_flip(0.0099999)
702700
b = cirq.bit_flip(0.01)
703701
c = cirq.bit_flip(0.0)
@@ -735,7 +733,7 @@ def test_bit_flip_channel_text_diagram():
735733
def test_stabilizer_supports_depolarize():
736734
with pytest.raises(TypeError, match="act_on"):
737735
for _ in range(100):
738-
cirq.act_on(cirq.depolarize(3 / 4), DummySimulationState(), qubits=())
736+
cirq.act_on(cirq.depolarize(3 / 4), ExampleSimulationState(), qubits=())
739737

740738
q = cirq.LineQubit(0)
741739
c = cirq.Circuit(cirq.depolarize(3 / 4).on(q), cirq.measure(q, key='m'))

cirq-core/cirq/ops/common_gates_test.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import sympy
1818

1919
import cirq
20-
from cirq.protocols.act_on_protocol_test import DummySimulationState
20+
from cirq.protocols.act_on_protocol_test import ExampleSimulationState
2121

2222
H = np.array([[1, 1], [1, -1]]) * np.sqrt(0.5)
2323
HH = cirq.kron(H, H)
@@ -310,7 +310,7 @@ def test_h_str():
310310

311311
def test_x_act_on_tableau():
312312
with pytest.raises(TypeError, match="Failed to act"):
313-
cirq.act_on(cirq.X, DummySimulationState(), qubits=())
313+
cirq.act_on(cirq.X, ExampleSimulationState(), qubits=())
314314
original_tableau = cirq.CliffordTableau(num_qubits=5, initial_state=31)
315315
flipped_tableau = cirq.CliffordTableau(num_qubits=5, initial_state=23)
316316

@@ -359,7 +359,7 @@ def _unitary_(self):
359359

360360
def test_y_act_on_tableau():
361361
with pytest.raises(TypeError, match="Failed to act"):
362-
cirq.act_on(cirq.Y, DummySimulationState(), qubits=())
362+
cirq.act_on(cirq.Y, ExampleSimulationState(), qubits=())
363363
original_tableau = cirq.CliffordTableau(num_qubits=5, initial_state=31)
364364
flipped_tableau = cirq.CliffordTableau(num_qubits=5, initial_state=23)
365365

@@ -397,9 +397,9 @@ def test_y_act_on_tableau():
397397

398398
def test_z_h_act_on_tableau():
399399
with pytest.raises(TypeError, match="Failed to act"):
400-
cirq.act_on(cirq.Z, DummySimulationState(), qubits=())
400+
cirq.act_on(cirq.Z, ExampleSimulationState(), qubits=())
401401
with pytest.raises(TypeError, match="Failed to act"):
402-
cirq.act_on(cirq.H, DummySimulationState(), qubits=())
402+
cirq.act_on(cirq.H, ExampleSimulationState(), qubits=())
403403
original_tableau = cirq.CliffordTableau(num_qubits=5, initial_state=31)
404404
flipped_tableau = cirq.CliffordTableau(num_qubits=5, initial_state=23)
405405

@@ -450,7 +450,7 @@ def test_z_h_act_on_tableau():
450450

451451
def test_cx_act_on_tableau():
452452
with pytest.raises(TypeError, match="Failed to act"):
453-
cirq.act_on(cirq.CX, DummySimulationState(), qubits=())
453+
cirq.act_on(cirq.CX, ExampleSimulationState(), qubits=())
454454
original_tableau = cirq.CliffordTableau(num_qubits=5, initial_state=31)
455455

456456
state = cirq.CliffordTableauSimulationState(
@@ -494,7 +494,7 @@ def test_cx_act_on_tableau():
494494

495495
def test_cz_act_on_tableau():
496496
with pytest.raises(TypeError, match="Failed to act"):
497-
cirq.act_on(cirq.CZ, DummySimulationState(), qubits=())
497+
cirq.act_on(cirq.CZ, ExampleSimulationState(), qubits=())
498498
original_tableau = cirq.CliffordTableau(num_qubits=5, initial_state=31)
499499

500500
state = cirq.CliffordTableauSimulationState(

cirq-core/cirq/ops/gate_features_test.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def test_qasm_output_args_format():
5353

5454

5555
def test_multi_qubit_gate_validate():
56-
class Dummy(cirq.Gate):
56+
class Example(cirq.Gate):
5757
def _num_qubits_(self) -> int:
5858
return self._num_qubits
5959

@@ -62,7 +62,7 @@ def __init__(self, num_qubits):
6262

6363
a, b, c, d = cirq.LineQubit.range(4)
6464

65-
g = Dummy(3)
65+
g = Example(3)
6666

6767
assert g.num_qubits() == 3
6868
g.validate_args([a, b, c])

cirq-core/cirq/ops/pauli_string_raw_types_test.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ def map_qubits(self, qubit_map):
4848
def test_on_wrong_number_qubits():
4949
q0, q1, q2 = _make_qubits(3)
5050

51-
class DummyGate(cirq.PauliStringGateOperation):
51+
class ExampleGate(cirq.PauliStringGateOperation):
5252
def map_qubits(self, qubit_map):
5353
ps = self.pauli_string.map_qubits(qubit_map)
54-
return DummyGate(ps)
54+
return ExampleGate(ps)
5555

56-
g = DummyGate(cirq.PauliString({q0: cirq.X, q1: cirq.Y}))
56+
g = ExampleGate(cirq.PauliString({q0: cirq.X, q1: cirq.Y}))
5757

5858
_ = g.with_qubits(q1, q2)
5959
with pytest.raises(ValueError):

cirq-core/cirq/ops/pauli_string_test.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -732,11 +732,11 @@ def test_pass_operations_over_cz():
732732

733733

734734
def test_pass_operations_over_no_common_qubits():
735-
class DummyGate(cirq.testing.SingleQubitGate):
735+
class ExampleGate(cirq.testing.SingleQubitGate):
736736
pass
737737

738738
q0, q1 = _make_qubits(2)
739-
op0 = DummyGate()(q1)
739+
op0 = ExampleGate()(q1)
740740
ps_before = cirq.PauliString({q0: cirq.Z})
741741
ps_after = cirq.PauliString({q0: cirq.Z})
742742
_assert_pass_over([op0], ps_before, ps_after)

cirq-core/cirq/ops/random_gate_channel_test.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -219,13 +219,13 @@ def test_stabilizer_supports_probability():
219219

220220

221221
def test_unsupported_stabilizer_safety():
222-
from cirq.protocols.act_on_protocol_test import DummySimulationState
222+
from cirq.protocols.act_on_protocol_test import ExampleSimulationState
223223

224224
with pytest.raises(TypeError, match="act_on"):
225225
for _ in range(100):
226-
cirq.act_on(cirq.X.with_probability(0.5), DummySimulationState(), qubits=())
226+
cirq.act_on(cirq.X.with_probability(0.5), ExampleSimulationState(), qubits=())
227227
with pytest.raises(TypeError, match="act_on"):
228-
cirq.act_on(cirq.X.with_probability(sympy.Symbol('x')), DummySimulationState(), qubits=())
228+
cirq.act_on(cirq.X.with_probability(sympy.Symbol('x')), ExampleSimulationState(), qubits=())
229229

230230
q = cirq.LineQubit(0)
231231
c = cirq.Circuit((cirq.X(q) ** 0.25).with_probability(0.5), cirq.measure(q, key='m'))

cirq-core/cirq/ops/raw_types_test.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -787,9 +787,9 @@ def qubits(self):
787787
pass
788788

789789
q = cirq.LineQubit(1)
790-
from cirq.protocols.act_on_protocol_test import DummySimulationState
790+
from cirq.protocols.act_on_protocol_test import ExampleSimulationState
791791

792-
args = DummySimulationState()
792+
args = ExampleSimulationState()
793793
cirq.act_on(YesActOn()(q).with_tags("test"), args)
794794
with pytest.raises(TypeError, match="Failed to act"):
795795
cirq.act_on(NoActOn()(q).with_tags("test"), args)
@@ -798,11 +798,11 @@ def qubits(self):
798798

799799

800800
def test_single_qubit_gate_validates_on_each():
801-
class Dummy(cirq.testing.SingleQubitGate):
801+
class Example(cirq.testing.SingleQubitGate):
802802
def matrix(self):
803803
pass
804804

805-
g = Dummy()
805+
g = Example()
806806
assert g.num_qubits() == 1
807807

808808
test_qubits = [cirq.NamedQubit(str(i)) for i in range(3)]

cirq-core/cirq/protocols/act_on_protocol_test.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@
2020
import cirq
2121

2222

23-
class DummyQuantumState(cirq.QuantumStateRepresentation):
23+
class ExampleQuantumState(cirq.QuantumStateRepresentation):
2424
def copy(self, deep_copy_buffers=True):
2525
pass
2626

2727
def measure(self, axes, seed=None):
2828
pass
2929

3030

31-
class DummySimulationState(cirq.SimulationState):
31+
class ExampleSimulationState(cirq.SimulationState):
3232
def __init__(self, fallback_result: Any = NotImplemented):
33-
super().__init__(prng=np.random.RandomState(), state=DummyQuantumState())
33+
super().__init__(prng=np.random.RandomState(), state=ExampleQuantumState())
3434
self.fallback_result = fallback_result
3535

3636
def _act_on_fallback_(
@@ -43,18 +43,18 @@ def _act_on_fallback_(
4343

4444

4545
def test_act_on_fallback_succeeds():
46-
state = DummySimulationState(fallback_result=True)
46+
state = ExampleSimulationState(fallback_result=True)
4747
cirq.act_on(op, state)
4848

4949

5050
def test_act_on_fallback_fails():
51-
state = DummySimulationState(fallback_result=NotImplemented)
51+
state = ExampleSimulationState(fallback_result=NotImplemented)
5252
with pytest.raises(TypeError, match='Failed to act'):
5353
cirq.act_on(op, state)
5454

5555

5656
def test_act_on_fallback_errors():
57-
state = DummySimulationState(fallback_result=False)
57+
state = ExampleSimulationState(fallback_result=False)
5858
with pytest.raises(ValueError, match='_act_on_fallback_ must return True or NotImplemented'):
5959
cirq.act_on(op, state)
6060

@@ -71,7 +71,7 @@ def with_qubits(self, *new_qubits: 'cirq.Qid') -> Self: # type: ignore[empty-bo
7171
def _act_on_(self, sim_state):
7272
return False
7373

74-
state = DummySimulationState(fallback_result=True)
74+
state = ExampleSimulationState(fallback_result=True)
7575
with pytest.raises(ValueError, match='_act_on_ must return True or NotImplemented'):
7676
cirq.act_on(Op(), state)
7777

@@ -85,14 +85,14 @@ def qubits(self) -> Tuple['cirq.Qid', ...]: # type: ignore[empty-body]
8585
def with_qubits(self, *new_qubits: 'cirq.Qid') -> Self: # type: ignore[empty-body]
8686
pass
8787

88-
state = DummySimulationState()
88+
state = ExampleSimulationState()
8989
with pytest.raises(
9090
ValueError, match='Calls to act_on should not supply qubits if the action is an Operation'
9191
):
9292
cirq.act_on(Op(), state, qubits=[])
9393

9494

9595
def test_qubits_should_be_defined_for_operations():
96-
state = DummySimulationState()
96+
state = ExampleSimulationState()
9797
with pytest.raises(ValueError, match='Calls to act_on should'):
9898
cirq.act_on(cirq.KrausChannel([np.array([[1, 0], [0, 0]])]), state, qubits=None)

0 commit comments

Comments
 (0)