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

Remove special CXPowGate.on. #5471

Merged
merged 3 commits into from
Jun 8, 2022
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
13 changes: 0 additions & 13 deletions cirq-core/cirq/ops/common_gates.py
Original file line number Diff line number Diff line change
Expand Up @@ -1264,19 +1264,6 @@ def __repr__(self) -> str:
f'global_shift={self._global_shift!r})'
)

def on(self, *args: 'cirq.Qid', **kwargs: 'cirq.Qid') -> raw_types.Operation:
if not kwargs:
return super().on(*args)
if not args and set(kwargs.keys()) == {'control', 'target'}:
return super().on(kwargs['control'], kwargs['target'])
raise ValueError(
"Expected two positional argument or else 'target' AND 'control' "
"keyword arguments. But got args={!r}, kwargs={!r}.".format(args, kwargs)
)

def __call__(self, *qubits: 'cirq.Qid', **kwargs: 'cirq.Qid'):
return self.on(*qubits, **kwargs)


def rx(rads: value.TParamVal) -> Rx:
"""Returns a gate with the matrix e^{-i X rads / 2}."""
Expand Down
41 changes: 0 additions & 41 deletions cirq-core/cirq/ops/common_gates_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,47 +740,6 @@ def test_cnot_unitary():
)


def test_cnot_keyword_arguments():
a = cirq.NamedQubit('a')
b = cirq.NamedQubit('b')

eq_tester = cirq.testing.EqualsTester()
eq_tester.add_equality_group(cirq.CNOT(a, b), cirq.CNOT(control=a, target=b))
eq_tester.add_equality_group(cirq.CNOT(b, a), cirq.CNOT(control=b, target=a))


def test_cnot_keyword_not_equal():
a = cirq.NamedQubit('a')
b = cirq.NamedQubit('b')

with pytest.raises(AssertionError):
eq_tester = cirq.testing.EqualsTester()
eq_tester.add_equality_group(cirq.CNOT(a, b), cirq.CNOT(target=a, control=b))


def test_cnot_keyword_too_few_arguments():
a = cirq.NamedQubit('a')

with pytest.raises(ValueError):
_ = cirq.CNOT(control=a)


def test_cnot_mixed_keyword_and_positional_arguments():
a = cirq.NamedQubit('a')
b = cirq.NamedQubit('b')

with pytest.raises(ValueError):
_ = cirq.CNOT(a, target=b)


def test_cnot_unknown_keyword_argument():
a = cirq.NamedQubit('a')
b = cirq.NamedQubit('b')

with pytest.raises(ValueError):
_ = cirq.CNOT(target=a, controlled=b)


def test_cnot_decompose():
a = cirq.NamedQubit('a')
b = cirq.NamedQubit('b')
Expand Down