Example #1
0
def test_invalid_measurement_gate():
    with pytest.raises(ValueError, match='length'):
        _ = programs.gate_to_proto(
            cirq.MeasurementGate(3, 'test', invert_mask=(True, )),
            (cirq.GridQubit(2, 3), cirq.GridQubit(3, 4)),
            delay=0)
    with pytest.raises(ValueError, match='no qubits'):
        _ = programs.gate_to_proto(cirq.MeasurementGate(1, 'test'), (),
                                   delay=0)
Example #2
0
def test_invalid_to_proto_dict_qubit_number():
    with pytest.raises(ValueError, match='Wrong number of qubits'):
        _ = programs.gate_to_proto(cirq.CZ**0.5, (cirq.GridQubit(2, 3), ),
                                   delay=0)
    with pytest.raises(ValueError, match='Wrong number of qubits'):
        programs.gate_to_proto(cirq.Z**0.5,
                               (cirq.GridQubit(2, 3), cirq.GridQubit(3, 4)),
                               delay=0)
    with pytest.raises(ValueError, match='Wrong number of qubits'):
        programs.gate_to_proto(cirq.PhasedXPowGate(exponent=0.5,
                                                   phase_exponent=0),
                               (cirq.GridQubit(2, 3), cirq.GridQubit(3, 4)),
                               delay=0)
Example #3
0
def test_single_qubit_measurement_to_proto_pad_invert_mask():
    gate = cirq.MeasurementGate(2, 'test', invert_mask=(True, ))
    proto = operations_pb2.Operation(
        measurement=operations_pb2.Measurement(targets=[
            operations_pb2.Qubit(row=2, col=3),
            operations_pb2.Qubit(row=2, col=4)
        ],
                                               key='test',
                                               invert_mask=[True, False]))
    assert programs.gate_to_proto(gate,
                                  (cirq.GridQubit(2, 3), cirq.GridQubit(2, 4)),
                                  delay=0) == proto
Example #4
0
def assert_proto_dict_convert(gate: cirq.Gate, proto: operations_pb2.Operation,
                              *qubits: cirq.Qid):
    assert programs.gate_to_proto(gate, qubits, delay=0) == proto
    assert programs.xmon_op_from_proto(proto) == gate(*qubits)