Skip to content

Commit

Permalink
Add coverage for OpId
Browse files Browse the repository at this point in the history
  • Loading branch information
95-martin-orion committed Dec 7, 2021
1 parent 046b884 commit 55069a9
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion cirq-core/cirq/devices/noise_utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,42 @@
)


def test_op_id():
def test_op_identifier():
op_id = OpIdentifier(cirq.XPowGate)
assert cirq.X(cirq.LineQubit(1)) in op_id
assert cirq.Rx(rads=1) in op_id


def test_op_identifier_subtypes():
gate_id = OpIdentifier(cirq.Gate)
xpow_id = OpIdentifier(cirq.XPowGate)
x_on_q0_id = OpIdentifier(cirq.XPowGate, cirq.LineQubit(0))
assert xpow_id.is_proper_subtype_of(gate_id)
assert x_on_q0_id.is_proper_subtype_of(xpow_id)
assert x_on_q0_id.is_proper_subtype_of(gate_id)
assert not xpow_id.is_proper_subtype_of(xpow_id)


def test_op_id_str():
op_id = OpIdentifier(cirq.XPowGate, cirq.LineQubit(0))
print(op_id)
print(repr(op_id))
assert str(op_id) == "<class 'cirq.ops.common_gates.XPowGate'>(cirq.LineQubit(0),)"
assert repr(op_id) == (
"cirq.devices.noise_utils.OpIdentifier(cirq.ops.common_gates.XPowGate, cirq.LineQubit(0))"
)


def test_op_id_swap():
q0, q1 = cirq.LineQubit.range(2)
base_id = OpIdentifier(cirq.CZPowGate, q0, q1)
swap_id = base_id.swapped()
assert cirq.CZ(q0, q1) in base_id
assert cirq.CZ(q0, q1) not in swap_id
assert cirq.CZ(q1, q0) not in base_id
assert cirq.CZ(q1, q0) in swap_id


@pytest.mark.parametrize(
'decay_constant,num_qubits,expected_output',
[
Expand Down

0 comments on commit 55069a9

Please sign in to comment.