当前位置: 首页>>代码示例>>Python>>正文


Python gates.RY属性代码示例

本文整理汇总了Python中pyquil.gates.RY属性的典型用法代码示例。如果您正苦于以下问题:Python gates.RY属性的具体用法?Python gates.RY怎么用?Python gates.RY使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在pyquil.gates的用法示例。


在下文中一共展示了gates.RY属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_rotation_program

# 需要导入模块: from pyquil import gates [as 别名]
# 或者: from pyquil.gates import RY [as 别名]
def get_rotation_program(pauli_term: PauliTerm) -> Program:
    """
    Generate a rotation program so that the pauli term is diagonal.

    :param pauli_term: The Pauli term used to generate diagonalizing one-qubit rotations.
    :return: The rotation program.
    """
    meas_basis_change = Program()
    for index, gate in pauli_term:
        if gate == 'X':
            meas_basis_change.inst(RY(-np.pi / 2, index))
        elif gate == 'Y':
            meas_basis_change.inst(RX(np.pi / 2, index))
        elif gate == 'Z':
            pass
        else:
            raise ValueError()

    return meas_basis_change 
开发者ID:rigetti,项目名称:grove,代码行数:21,代码来源:estimation.py

示例2: test_mutation_free_estimation

# 需要导入模块: from pyquil import gates [as 别名]
# 或者: from pyquil.gates import RY [as 别名]
def test_mutation_free_estimation():
    """
    Make sure the estimation routines do not mutate the programs the user sends.

    This is accomplished by a deep copy in `estimate_pauli_sum'.
    """
    prog = Program().inst(I(0))
    pauli_sum = sX(0)  # measure in the X-basis

    # set up fake QVM
    with patch("pyquil.api.QuantumComputer") as qc:
        # Mock the response
        qc.run.return_value = [[0], [1]]

    _, _, _ = estimate_locally_commuting_operator(prog,
                                                  pauli_sum=PauliSum([pauli_sum]),
                                                  variance_bound=1.0E-3,
                                                  quantum_resource=qc)

    # make sure RY(-pi/2) 0\nMEASURE 0 [0] was not added to the program the user sees
    assert prog.out() == 'I 0\n' 
开发者ID:rigetti,项目名称:grove,代码行数:23,代码来源:test_estimation.py

示例3: _random_2q_programs

# 需要导入模块: from pyquil import gates [as 别名]
# 或者: from pyquil.gates import RY [as 别名]
def _random_2q_programs(n_progs=3):
    """Generate random programs that consist of single qubit rotations, a CZ, and single
    qubit rotations.
    """
    r = random.Random(52)

    def RI(qubit, angle):
        # throw away angle so we can randomly choose the identity
        return I(qubit)

    def _random_1q_gate(qubit):
        return r.choice([RI, RX, RY, RZ])(qubit=qubit, angle=r.uniform(0, 2 * pi))

    for _ in range(n_progs):
        prog = Program()
        prog += _random_1q_gate(0)
        prog += _random_1q_gate(1)
        prog += CZ(0, 1)
        prog += _random_1q_gate(0)
        prog += _random_1q_gate(1)
        yield prog 
开发者ID:rigetti,项目名称:pyquil,代码行数:23,代码来源:test_operator_estimation.py

示例4: local_pauli_eig_prep

# 需要导入模块: from pyquil import gates [as 别名]
# 或者: from pyquil.gates import RY [as 别名]
def local_pauli_eig_prep(op, qubit):
    r"""
    Generate gate sequence to prepare a the +1 eigenstate of a Pauli operator, assuming
    we are starting from the ground state ( the +1 eigenstate of :math:`Z^{\otimes n}`)

    :param str op: A string representation of the Pauli operator whose eigenstate we would like to
        prepare.
    :param int qubit: The index of the qubit that the preparation is acting on
    :return: The preparation Program.
    """
    if op == 'X':
        gate = RY(pi / 2, qubit)
    elif op == 'Y':
        gate = RX(-pi / 2, qubit)
    elif op == 'Z':
        gate = I(qubit)
    else:
        raise ValueError('Unknown gate operation')
    prog = Program(gate)
    return prog 
开发者ID:rigetti,项目名称:forest-benchmarking,代码行数:22,代码来源:utils.py

示例5: local_pauli_eigs_prep

# 需要导入模块: from pyquil import gates [as 别名]
# 或者: from pyquil.gates import RY [as 别名]
def local_pauli_eigs_prep(op, qubit):
    """
    Generate all gate sequences to prepare all eigenstates of a (local) Pauli operator, assuming
    we are starting from the ground state.

    :param str op: A string representation of the Pauli operator whose eigenstate we would like to
        prepare.
    :param int qubit: The index of the qubit that the preparation is acting on
    :rtype list: A list of programs
    """
    if op == 'X':
        gates = [RY(pi / 2, qubit), RY(-pi / 2, qubit)]
    elif op == 'Y':
        gates = [RX(-pi / 2, qubit), RX(pi / 2, qubit)]
    elif op == 'Z':
        gates = [I(qubit), RX(pi, qubit)]
    else:
        raise ValueError('Unknown gate operation')
    return [Program(gate) for gate in gates] 
开发者ID:rigetti,项目名称:forest-benchmarking,代码行数:21,代码来源:utils.py

示例6: measure_graph_state

# 需要导入模块: from pyquil import gates [as 别名]
# 或者: from pyquil.gates import RY [as 别名]
def measure_graph_state(graph: nx.Graph, focal_node: int):
    """
    Given a graph state, measure a focal node and its neighbors with a particular measurement
    angle.

    :param graph: The graph state graph. This is needed to figure out what the neighbors are
    :param focal_node: The node in the graph to serve as the focus. The focal node is measured
        at an angle and all its neighbors are measured in the Z basis
    :return: Program, list of classical offsets into the ``ro`` register.
    """
    program = Program()
    theta = program.declare('theta', 'REAL')
    program += RY(theta, focal_node)

    neighbors = sorted(graph[focal_node])
    ro = program.declare('ro', 'BIT', len(neighbors) + 1)

    program += MEASURE(focal_node, ro[0])
    for i, neighbor in enumerate(neighbors):
        program += MEASURE(neighbor, ro[i + 1])

    classical_addresses = list(range(len(neighbors) + 1))
    return program, classical_addresses 
开发者ID:rigetti,项目名称:forest-benchmarking,代码行数:25,代码来源:entangled_states.py

示例7: test_rotation_programs

# 需要导入模块: from pyquil import gates [as 别名]
# 或者: from pyquil.gates import RY [as 别名]
def test_rotation_programs():
    """
    Testing the generation of post rotations
    """
    test_term = sZ(0) * sX(20) * sI(100) * sY(5)
    rotations_to_do = [RX(np.pi / 2, 5), RY(-np.pi / 2, 20)]
    test_rotation_program = get_rotation_program(test_term)
    # Since the rotations commute, it's sufficient to test membership in the program,
    # without ordering. However, it's true that a more complicated rotation could be performed,
    #  where the elements would not be free to be permuted. We ignore this possibility, for now.
    assert len(rotations_to_do) == len(test_rotation_program)
    for rotation in test_rotation_program:
        assert rotation in rotations_to_do 
开发者ID:rigetti,项目名称:grove,代码行数:15,代码来源:test_estimation.py

示例8: test_PrepareAndMeasureOnQVM_QubitPlaceholders_nondiag_hamiltonian

# 需要导入模块: from pyquil import gates [as 别名]
# 或者: from pyquil.gates import RY [as 别名]
def test_PrepareAndMeasureOnQVM_QubitPlaceholders_nondiag_hamiltonian():
    q1, q2, q3 = QubitPlaceholder(), QubitPlaceholder(), QubitPlaceholder()
    ham = PauliTerm("Y", q1)*PauliTerm("Z",q3)
    ham += PauliTerm("Y", q1)*PauliTerm("Z",q2,-0.3)
    ham += PauliTerm("Y", q1)*PauliTerm("X",q3, 2.0)
    params = [3.0,0.4,4.5]

    prepare_ansatz = Program()
    param_register = prepare_ansatz.declare(
        "params", memory_type="REAL", memory_size=3)
    prepare_ansatz.inst(RX(param_register[0], q1))
    prepare_ansatz.inst(RY(param_register[1], q2))
    prepare_ansatz.inst(RY(param_register[2], q3))

    def make_memory_map(params):
        return {"params": params}

    qubit_mapping = get_default_qubit_mapping(prepare_ansatz)
    qvm = get_qc("3q-qvm")
    cost_fn = PrepareAndMeasureOnQVM(prepare_ansatz, make_memory_map,
                                     qvm=qvm,
                                     hamiltonian=ham,
                                     scalar_cost_function=False,
                                     base_numshots=100,
                                     qubit_mapping=qubit_mapping)
    out = cost_fn(params, nshots=10)
    assert np.allclose(out, (0.346, 0.07), rtol=1.1) 
开发者ID:entropicalabs,项目名称:entropica_qaoa,代码行数:29,代码来源:test_cost_function.py

示例9: test_qaoa_density

# 需要导入模块: from pyquil import gates [as 别名]
# 或者: from pyquil.gates import RY [as 别名]
def test_qaoa_density():
    wf_true = [0.00167784 + 1.00210180e-05*1j, 0.50000000 - 4.99997185e-01*1j,
               0.50000000 - 4.99997185e-01*1j, 0.00167784 + 1.00210180e-05*1j]
    wf_true = np.reshape(np.array(wf_true), (4, 1))
    rho_true = np.dot(wf_true, np.conj(wf_true).T)
    prog = Program()
    prog.inst([RYgate(np.pi/2, 0), RXgate(np.pi, 0),
               RYgate(np.pi/2, 1), RXgate(np.pi, 1),
               CNOTgate(0, 1), RXgate(-np.pi/2, 1), RYgate(4.71572463191, 1),
               RXgate(np.pi/2, 1), CNOTgate(0, 1),
               RXgate(-2*2.74973750579, 0), RXgate(-2*2.74973750579, 1)])

    qvm = QVMConnection(type_trans='density')
    wf_rho = qvm.density(prog)
    assert np.isclose(rho_true, wf_rho.todense()).all() 
开发者ID:rigetti,项目名称:reference-qvm,代码行数:17,代码来源:test_density.py

示例10: test_qaoa_circuit

# 需要导入模块: from pyquil import gates [as 别名]
# 或者: from pyquil.gates import RY [as 别名]
def test_qaoa_circuit(qvm):
    wf_true = [0.00167784 + 1.00210180e-05*1j, 0.50000000 - 4.99997185e-01*1j,
               0.50000000 - 4.99997185e-01*1j, 0.00167784 + 1.00210180e-05*1j]
    prog = Program()
    prog.inst([RYgate(np.pi/2, 0), RXgate(np.pi, 0),
               RYgate(np.pi/2, 1), RXgate(np.pi, 1),
               CNOTgate(0, 1), RXgate(-np.pi/2, 1), RYgate(4.71572463191, 1),
               RXgate(np.pi/2, 1), CNOTgate(0, 1),
               RXgate(-2*2.74973750579, 0), RXgate(-2*2.74973750579, 1)])
    wf_test, _ = qvm.wavefunction(prog)
    assert np.allclose(wf_test.amplitudes, wf_true) 
开发者ID:rigetti,项目名称:reference-qvm,代码行数:13,代码来源:test_wavefunction.py

示例11: rotation

# 需要导入模块: from pyquil import gates [as 别名]
# 或者: from pyquil.gates import RY [as 别名]
def rotation(a, b, c, wire):
    r"""Arbitrary one-qubit rotation using three Euler angles.

    Args:
        a, b, c (float): rotation angles
        wire (int): wire the rotation acts on

    Returns:
        list: Ry and Rz matrix operators acting on each wire
    """
    return [RZ(a, wire), RY(b, wire), RZ(c, wire)] 
开发者ID:rigetti,项目名称:pennylane-forest,代码行数:13,代码来源:device.py

示例12: test_convert_program_with_controlled_operations

# 需要导入模块: from pyquil import gates [as 别名]
# 或者: from pyquil.gates import RY [as 别名]
def test_convert_program_with_controlled_operations(self):
        """Test that a program with controlled operations is properly converted."""
        program = pyquil.Program()

        program += g.RZ(0.34, 1)
        program += g.RY(0.2, 3).controlled(2)
        program += g.RX(0.4, 2).controlled(0)
        program += g.CNOT(1, 4)
        program += g.CNOT(1, 6).controlled(3)
        program += g.X(3).controlled(4).controlled(1)

        with OperationRecorder() as rec:
            load_program(program)(wires=range(6))

        expected_queue = [
            qml.RZ(0.34, wires=[1]),
            qml.CRY(0.2, wires=[2, 3]),
            qml.CRX(0.4, wires=[0, 2]),
            qml.CNOT(wires=[1, 4]),
            plf.ops.CCNOT(wires=[3, 1, 5]),
            plf.ops.CCNOT(wires=[1, 4, 3]),
        ]

        for converted, expected in zip(rec.queue, expected_queue):
            assert converted.name == expected.name
            assert converted.wires == expected.wires
            assert converted.params == expected.params 
开发者ID:rigetti,项目名称:pennylane-forest,代码行数:29,代码来源:test_converter.py

示例13: test_qaoa_unitary

# 需要导入模块: from pyquil import gates [as 别名]
# 或者: from pyquil.gates import RY [as 别名]
def test_qaoa_unitary():
    wf_true = [
        0.00167784 + 1.00210180e-05 * 1j,
        0.50000000 - 4.99997185e-01 * 1j,
        0.50000000 - 4.99997185e-01 * 1j,
        0.00167784 + 1.00210180e-05 * 1j,
    ]

    prog = Program(
        [
            RY(np.pi / 2, 0),
            RX(np.pi, 0),
            RY(np.pi / 2, 1),
            RX(np.pi, 1),
            CNOT(0, 1),
            RX(-np.pi / 2, 1),
            RY(4.71572463191, 1),
            RX(np.pi / 2, 1),
            CNOT(0, 1),
            RX(-2 * 2.74973750579, 0),
            RX(-2 * 2.74973750579, 1),
        ]
    )

    test_unitary = program_unitary(prog, n_qubits=2)
    wf_test = np.zeros(4)
    wf_test[0] = 1.0
    wf_test = test_unitary.dot(wf_test)
    assert np.allclose(wf_test, wf_true) 
开发者ID:rigetti,项目名称:pyquil,代码行数:31,代码来源:test_tools.py

示例14: test_lifted_gate_modified

# 需要导入模块: from pyquil import gates [as 别名]
# 或者: from pyquil.gates import RY [as 别名]
def test_lifted_gate_modified():
    test_unitary = lifted_gate(RZ(np.pi / 4, 0).dagger(), 1)
    true_unitary = mat.RZ(-np.pi / 4)
    assert np.allclose(test_unitary, true_unitary)

    test_unitary = lifted_gate(X(0).dagger().controlled(1), 2)
    true_unitary = lifted_gate(CNOT(1, 0), 2)
    other_true = mat.CNOT
    assert np.allclose(test_unitary, true_unitary)
    assert np.allclose(other_true, true_unitary)

    test_unitary = lifted_gate(X(1).dagger().controlled(0).dagger().dagger(), 2)
    true_unitary = lifted_gate(CNOT(0, 1), 2)
    assert np.allclose(test_unitary, true_unitary)

    test_unitary = lifted_gate(X(0).dagger().controlled(1).dagger().dagger().controlled(2), 3)
    true_unitary = lifted_gate(CCNOT(1, 2, 0), 3)
    other_true = mat.CCNOT
    assert np.allclose(test_unitary, true_unitary)
    assert np.allclose(other_true, true_unitary)

    test_unitary = lifted_gate(RY(np.pi / 4, 0).dagger().controlled(2).dagger().dagger(), 3)
    ry_part = lifted_gate(RY(-np.pi / 4, 0), 1)
    zero = np.eye(2)
    zero[1, 1] = 0
    one = np.eye(2)
    one[0, 0] = 0
    true_unitary = np.kron(zero, np.eye(4)) + np.kron(one, np.kron(np.eye(2), ry_part))
    assert np.allclose(test_unitary, true_unitary)

    test_unitary = lifted_gate(PHASE(0.0, 1).forked(0, [np.pi]), 2)
    true_unitary = lifted_gate(CZ(0, 1), 2)
    assert np.allclose(test_unitary, true_unitary)

    test_unitary = lifted_gate(PHASE(0.0, 2).forked(1, [0.0]).forked(0, [0.0, np.pi]), 3)
    true_unitary = lifted_gate(CZ(1, 2).controlled(0), 3)
    assert np.allclose(test_unitary, true_unitary) 
开发者ID:rigetti,项目名称:pyquil,代码行数:39,代码来源:test_tools.py

示例15: test_qaoa_density

# 需要导入模块: from pyquil import gates [as 别名]
# 或者: from pyquil.gates import RY [as 别名]
def test_qaoa_density():
    wf_true = [
        0.00167784 + 1.00210180e-05 * 1j,
        0.50000000 - 4.99997185e-01 * 1j,
        0.50000000 - 4.99997185e-01 * 1j,
        0.00167784 + 1.00210180e-05 * 1j,
    ]
    wf_true = np.reshape(np.array(wf_true), (4, 1))
    rho_true = np.dot(wf_true, np.conj(wf_true).T)
    prog = Program()
    prog.inst(
        [
            RY(np.pi / 2, 0),
            RX(np.pi, 0),
            RY(np.pi / 2, 1),
            RX(np.pi, 1),
            CNOT(0, 1),
            RX(-np.pi / 2, 1),
            RY(4.71572463191, 1),
            RX(np.pi / 2, 1),
            CNOT(0, 1),
            RX(-2 * 2.74973750579, 0),
            RX(-2 * 2.74973750579, 1),
        ]
    )

    qam = PyQVM(n_qubits=2, quantum_simulator_type=ReferenceDensitySimulator).execute(prog)
    rho = qam.wf_simulator.density
    np.testing.assert_allclose(rho_true, rho, atol=1e-8) 
开发者ID:rigetti,项目名称:pyquil,代码行数:31,代码来源:test_reference_density.py


注:本文中的pyquil.gates.RY属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。