def test_identity_operation_init(): q = cirq.NamedQubit('q') I = cirq.IdentityOperation([q]) assert I.qubits == (q, ) I = cirq.IdentityOperation(q) assert I.qubits == (q, )
def test_identity_operation_repr(): a, b = cirq.LineQubit.range(2) assert repr(cirq.IdentityOperation( (a, ))) == ('cirq.I.on(cirq.LineQubit(0))') assert repr(cirq.IdentityOperation((a, b))) == ( 'cirq.IdentityOperation(qubits=[cirq.LineQubit(0), cirq.LineQubit(1)])' )
def test_invalid_identity_operation(): three_qubit_gate = cirq.ThreeQubitGate() with pytest.raises(ValueError, match="empty set of qubits"): cirq.IdentityOperation([]) with pytest.raises(ValueError, match="Gave non-Qid objects to IdentityOperation"): cirq.IdentityOperation([three_qubit_gate])
def test_identity_operation_deprecated(): a, b = cirq.LineQubit.range(2) with capture_logging() as log: actual = cirq.IdentityOperation([a, b]) assert len(log) == 1 # May fail if deprecated thing is used elsewhere. assert 'IdentityOperation' in log[0].getMessage() assert 'deprecated' in log[0].getMessage() assert actual == cirq.IdentityGate(2).on(a, b)
cirq.GridQubit(10, 11), 'H': cirq.H, 'HPowGate': [cirq.HPowGate(exponent=-8), cirq.H**0.123], 'I': cirq.I, 'ISWAP': cirq.ISWAP, 'ISwapPowGate': [cirq.ISwapPowGate(exponent=-8), cirq.ISWAP**0.123], 'IdentityGate': [ cirq.I, cirq.IdentityGate(num_qubits=5), cirq.IdentityGate(num_qubits=5, qid_shape=(3, ) * 5) ], 'IdentityOperation': [ cirq.IdentityOperation(cirq.LineQubit.range(2)), cirq.IdentityOperation(cirq.LineQubit.range(5)) ], 'LineQubit': [cirq.LineQubit(0), cirq.LineQubit(123)], 'LineQid': [cirq.LineQid(0, 1), cirq.LineQid(123, 2), cirq.LineQid(-4, 5)], 'MeasurementGate': [ cirq.MeasurementGate(num_qubits=3, key='z'), cirq.MeasurementGate(num_qubits=3, key='z', invert_mask=(True, False, True)), cirq.MeasurementGate(num_qubits=3, key='z', invert_mask=(True, False), qid_shape=(1, 2, 3)),
def test_identity_operation_str(): a, b = cirq.LineQubit.range(2) assert str(cirq.IdentityOperation((a, ))) == ('I(0)') assert str(cirq.IdentityOperation((a, b))) == ('I(0, 1)')
def test_with_qubits_and_transform_qubits(): op = cirq.IdentityOperation(cirq.LineQubit.range(3)) assert op.with_qubits(*cirq.LineQubit.range(3, 0, -1)) \ == cirq.IdentityOperation(cirq.LineQubit.range(3, 0, -1))