Example #1
0
def test_single_qubit_measurement_to_proto_convert_invert_mask():
    gate = cirq.MeasurementGate(1, 'test', invert_mask=(True, ))
    proto = operations_pb2.Operation(measurement=operations_pb2.Measurement(
        targets=[operations_pb2.Qubit(row=2, col=3)],
        key='test',
        invert_mask=[True]))
    assert_proto_dict_convert(gate, proto, cirq.GridQubit(2, 3))
Example #2
0
def test_multi_qubit_measurement_to_proto():
    gate = cirq.MeasurementGate(2, 'test')
    proto = operations_pb2.Operation(
        measurement=operations_pb2.Measurement(targets=[
            operations_pb2.Qubit(row=2, col=3),
            operations_pb2.Qubit(row=3, col=4)
        ],
                                               key='test'))
    assert_proto_dict_convert(gate, proto, cirq.GridQubit(2, 3),
                              cirq.GridQubit(3, 4))
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 _measure_to_proto(gate: 'cirq.MeasurementGate',
                      qubits: Sequence['cirq.Qid']):
    if len(qubits) == 0:
        raise ValueError('Measurement gate on no qubits.')

    invert_mask = None
    if gate.invert_mask:
        invert_mask = gate.invert_mask + (False, ) * (gate.num_qubits() -
                                                      len(gate.invert_mask))

    if invert_mask and len(invert_mask) != len(qubits):
        raise ValueError('Measurement gate had invert mask of length '
                         'different than number of qubits it acts on.')
    return operations_pb2.Measurement(
        targets=[_qubit_to_proto(q) for q in qubits],
        key=protocols.measurement_key(gate),
        invert_mask=invert_mask)