示例#1
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))
示例#2
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)
示例#3
0
def test_z_proto_convert():
    gate = cirq.Z**sympy.Symbol('k')
    proto = operations_pb2.Operation(exp_z=operations_pb2.ExpZ(
        target=operations_pb2.Qubit(row=2, col=3),
        half_turns=operations_pb2.ParameterizedFloat(parameter_key='k'),
    ))

    assert_proto_dict_convert(gate, proto, cirq.GridQubit(2, 3))
    gate = cirq.Z**0.5
    proto = operations_pb2.Operation(exp_z=operations_pb2.ExpZ(
        target=operations_pb2.Qubit(row=2, col=3),
        half_turns=operations_pb2.ParameterizedFloat(raw=0.5),
    ))
    assert_proto_dict_convert(gate, proto, cirq.GridQubit(2, 3))
示例#4
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))
示例#5
0
def test_w_to_proto():
    gate = cirq.PhasedXPowGate(exponent=sympy.Symbol('k'), phase_exponent=1)
    proto = operations_pb2.Operation(exp_w=operations_pb2.ExpW(
        target=operations_pb2.Qubit(row=2, col=3),
        axis_half_turns=operations_pb2.ParameterizedFloat(raw=1),
        half_turns=operations_pb2.ParameterizedFloat(parameter_key='k'),
    ))
    assert_proto_dict_convert(gate, proto, cirq.GridQubit(2, 3))

    gate = cirq.PhasedXPowGate(exponent=0.5, phase_exponent=sympy.Symbol('j'))
    proto = operations_pb2.Operation(exp_w=operations_pb2.ExpW(
        target=operations_pb2.Qubit(row=2, col=3),
        axis_half_turns=operations_pb2.ParameterizedFloat(parameter_key='j'),
        half_turns=operations_pb2.ParameterizedFloat(raw=0.5),
    ))
    assert_proto_dict_convert(gate, proto, cirq.GridQubit(2, 3))

    gate = cirq.X**0.25
    proto = operations_pb2.Operation(exp_w=operations_pb2.ExpW(
        target=operations_pb2.Qubit(row=2, col=3),
        axis_half_turns=operations_pb2.ParameterizedFloat(raw=0.0),
        half_turns=operations_pb2.ParameterizedFloat(raw=0.25),
    ))
    assert_proto_dict_convert(gate, proto, cirq.GridQubit(2, 3))

    gate = cirq.Y**0.25
    proto = operations_pb2.Operation(exp_w=operations_pb2.ExpW(
        target=operations_pb2.Qubit(row=2, col=3),
        axis_half_turns=operations_pb2.ParameterizedFloat(raw=0.5),
        half_turns=operations_pb2.ParameterizedFloat(raw=0.25),
    ))
    assert_proto_dict_convert(gate, proto, cirq.GridQubit(2, 3))

    gate = cirq.PhasedXPowGate(exponent=0.5, phase_exponent=sympy.Symbol('j'))
    proto = operations_pb2.Operation(exp_w=operations_pb2.ExpW(
        target=operations_pb2.Qubit(row=2, col=3),
        axis_half_turns=operations_pb2.ParameterizedFloat(parameter_key='j'),
        half_turns=operations_pb2.ParameterizedFloat(raw=0.5),
    ))
    assert_proto_dict_convert(gate, proto, cirq.GridQubit(2, 3))
示例#6
0
def _qubit_to_proto(qubit):
    return operations_pb2.Qubit(row=qubit.row, col=qubit.col)