示例#1
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))
示例#2
0
def _phased_x_to_proto(gate: 'cirq.PhasedXPowGate',
                       q: 'cirq.Qid') -> operations_pb2.ExpW:
    return operations_pb2.ExpW(
        target=_qubit_to_proto(q),
        axis_half_turns=_parameterized_value_to_proto(gate.phase_exponent),
        half_turns=_parameterized_value_to_proto(gate.exponent),
    )
示例#3
0
def _y_to_proto(gate: 'cirq.YPowGate', q: 'cirq.Qid') -> operations_pb2.ExpW:
    return operations_pb2.ExpW(
        target=_qubit_to_proto(q),
        axis_half_turns=_parameterized_value_to_proto(0.5),
        half_turns=_parameterized_value_to_proto(gate.exponent))