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


Python gates.RZ属性代码示例

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


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

示例1: test_diffusion_operator

# 需要导入模块: from pyquil import gates [as 别名]
# 或者: from pyquil.gates import RZ [as 别名]
def test_diffusion_operator():
    """
    Checks that the diffusion operator outputs the correct operation
    """
    created = decomposed_diffusion_program(qubits[:2])
    desired = Program()
    for def_gate in created.defined_gates:
        desired.defgate(def_gate.name, def_gate.matrix)
    qubit0 = qubits[0]
    qubit1 = qubits[1]
    desired.inst(X(qubit0))
    desired.inst(X(qubit1))
    desired.inst(H(qubit1))
    desired.inst(RZ(-np.pi, qubit0))
    desired.inst(CNOT(qubit0, qubit1))
    desired.inst(RZ(-np.pi, qubit0))
    desired.inst(H(qubit1))
    desired.inst(X(qubit0))
    desired.inst(X(qubit1))
    assert desired == created 
开发者ID:rigetti,项目名称:grove,代码行数:22,代码来源:test_amplification.py

示例2: test_psiref_bar_p2

# 需要导入模块: from pyquil import gates [as 别名]
# 或者: from pyquil.gates import RZ [as 别名]
def test_psiref_bar_p2():
    bar = [(0, 1)]
    p = 2
    with patch('pyquil.api.get_qc', spec=qc_mod):
        inst = maxcut_qaoa(bar, steps=p)

    param_prog = inst.get_parameterized_program()

    # returns are the rotations correct?
    prog = param_prog([1.2, 3.4, 2.1, 4.5])
    result_prog = Program().inst([H(0), H(1),
                                  CNOT(0, 1), RZ(2.1, 1), CNOT(0, 1),
                                  X(0), PHASE(1.05, 0), X(0), PHASE(1.05, 0),
                                  H(0), RZ(-2.4, 0), H(0),
                                  H(1), RZ(-2.4, 1), H(1),
                                  CNOT(0, 1), RZ(4.5, 1), CNOT(0, 1),
                                  X(0), PHASE(2.25, 0), X(0), PHASE(2.25, 0),
                                  H(0), RZ(-6.8, 0), H(0),
                                  H(1), RZ(-6.8, 1), H(1),
                                  ])
    assert prog == result_prog 
开发者ID:rigetti,项目名称:grove,代码行数:23,代码来源:test_maxcut.py

示例3: test_parameter_not_given_error

# 需要导入模块: from pyquil import gates [as 别名]
# 或者: from pyquil.gates import RZ [as 别名]
def test_parameter_not_given_error(self):
        """Test that the correct error is raised if a parameter is not given."""
        program = pyquil.Program()

        alpha = program.declare("alpha", "REAL")
        beta = program.declare("beta", "REAL")

        program += g.H(0)
        program += g.CNOT(0, 1)
        program += g.RX(alpha, 1)
        program += g.RZ(beta, 1)

        a = 0.1

        parameter_map = {"alpha": a}

        with pytest.raises(
            qml.DeviceError,
            match="The PyQuil program defines a variable .* that is not present in the given variable map",
        ):
            load_program(program)(wires=range(2), parameter_map=parameter_map) 
开发者ID:rigetti,项目名称:pennylane-forest,代码行数:23,代码来源:test_converter.py

示例4: _one_q_sic_prep

# 需要导入模块: from pyquil import gates [as 别名]
# 或者: from pyquil.gates import RZ [as 别名]
def _one_q_sic_prep(index: int, qubit: QubitDesignator) -> Program:
    """Prepare the index-th SIC basis state."""
    if index == 0:
        return Program()

    theta = 2 * np.arccos(1 / np.sqrt(3))
    zx_plane_rotation = Program([RX(-pi / 2, qubit), RZ(theta - pi, qubit), RX(-pi / 2, qubit)])

    if index == 1:
        return zx_plane_rotation

    elif index == 2:
        return zx_plane_rotation + RZ(-2 * pi / 3, qubit)

    elif index == 3:
        return zx_plane_rotation + RZ(2 * pi / 3, qubit)

    raise ValueError(f"Bad SIC index: {index}") 
开发者ID:rigetti,项目名称:pyquil,代码行数:20,代码来源:operator_estimation.py

示例5: _random_2q_programs

# 需要导入模块: from pyquil import gates [as 别名]
# 或者: from pyquil.gates import RZ [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

示例6: test_exponentiate_bp0_ZY

# 需要导入模块: from pyquil import gates [as 别名]
# 或者: from pyquil.gates import RZ [as 别名]
def test_exponentiate_bp0_ZY():
    # testing change of basis position 0
    q = QubitPlaceholder.register(8)
    generator = PauliTerm("Y", q[0], 1.0) * PauliTerm("Z", q[1], 1.0)
    para_prog = exponential_map(generator)
    prog = para_prog(1)
    result_prog = Program().inst(
        [
            RX(math.pi / 2.0, q[0]),
            CNOT(q[0], q[1]),
            RZ(2.0, q[1]),
            CNOT(q[0], q[1]),
            RX(-math.pi / 2, q[0]),
        ]
    )
    assert address_qubits(prog) == address_qubits(result_prog) 
开发者ID:rigetti,项目名称:pyquil,代码行数:18,代码来源:test_paulis_with_placeholders.py

示例7: test_exponentiate_bp1_YZ

# 需要导入模块: from pyquil import gates [as 别名]
# 或者: from pyquil.gates import RZ [as 别名]
def test_exponentiate_bp1_YZ():
    q = QubitPlaceholder.register(8)
    # testing change of basis position 1
    generator = PauliTerm("Z", q[0], 1.0) * PauliTerm("Y", q[1], 1.0)
    para_prog = exponential_map(generator)
    prog = para_prog(1)
    result_prog = Program().inst(
        [
            RX(math.pi / 2.0, q[1]),
            CNOT(q[0], q[1]),
            RZ(2.0, q[1]),
            CNOT(q[0], q[1]),
            RX(-math.pi / 2.0, q[1]),
        ]
    )
    assert address_qubits(prog) == address_qubits(result_prog) 
开发者ID:rigetti,项目名称:pyquil,代码行数:18,代码来源:test_paulis_with_placeholders.py

示例8: test_exponentiate_3cob

# 需要导入模块: from pyquil import gates [as 别名]
# 或者: from pyquil.gates import RZ [as 别名]
def test_exponentiate_3cob():
    # testing circuit for 3-terms with change of basis
    q = QubitPlaceholder.register(8)
    generator = PauliTerm("Z", q[0], 1.0) * PauliTerm("Y", q[1], 1.0) * PauliTerm("X", q[2], 1.0)
    para_prog = exponential_map(generator)
    prog = para_prog(1)
    result_prog = Program().inst(
        [
            RX(math.pi / 2.0, q[1]),
            H(q[2]),
            CNOT(q[0], q[1]),
            CNOT(q[1], q[2]),
            RZ(2.0, q[2]),
            CNOT(q[1], q[2]),
            CNOT(q[0], q[1]),
            RX(-math.pi / 2.0, q[1]),
            H(q[2]),
        ]
    )
    assert address_qubits(prog) == address_qubits(result_prog) 
开发者ID:rigetti,项目名称:pyquil,代码行数:22,代码来源:test_paulis_with_placeholders.py

示例9: test_exponentiate_3cob

# 需要导入模块: from pyquil import gates [as 别名]
# 或者: from pyquil.gates import RZ [as 别名]
def test_exponentiate_3cob():
    # testing circuit for 3-terms with change of basis
    generator = PauliTerm("Z", 0, 1.0) * PauliTerm("Y", 1, 1.0) * PauliTerm("X", 2, 1.0)
    para_prog = exponential_map(generator)
    prog = para_prog(1)
    result_prog = Program().inst(
        [
            RX(math.pi / 2.0, 1),
            H(2),
            CNOT(0, 1),
            CNOT(1, 2),
            RZ(2.0, 2),
            CNOT(1, 2),
            CNOT(0, 1),
            RX(-math.pi / 2.0, 1),
            H(2),
        ]
    )
    assert prog == result_prog 
开发者ID:rigetti,项目名称:pyquil,代码行数:21,代码来源:test_paulis.py

示例10: test_parameterized_single_qubit_state_preparation

# 需要导入模块: from pyquil import gates [as 别名]
# 或者: from pyquil.gates import RZ [as 别名]
def test_parameterized_single_qubit_state_preparation():
    p = Program()
    alpha = p.declare("preparation_alpha", "REAL", 2)
    beta = p.declare("preparation_beta", "REAL", 2)
    gamma = p.declare("preparation_gamma", "REAL", 2)
    p += RZ(alpha[0], 0)
    p += RX(np.pi / 2, 0)
    p += RZ(beta[0], 0)
    p += RX(-np.pi / 2, 0)
    p += RZ(gamma[0], 0)
    p += RZ(alpha[1], 1)
    p += RX(np.pi / 2, 1)
    p += RZ(beta[1], 1)
    p += RX(-np.pi / 2, 1)
    p += RZ(gamma[1], 1)
    assert parameterized_single_qubit_state_preparation([0, 1]).out() == p.out() 
开发者ID:rigetti,项目名称:pyquil,代码行数:18,代码来源:test_program.py

示例11: generate_cz_phase_ramsey_experiments

# 需要导入模块: from pyquil import gates [as 别名]
# 或者: from pyquil.gates import RZ [as 别名]
def generate_cz_phase_ramsey_experiments(cz_qubits: Sequence[int], measure_qubit: int,
                                         angles: Sequence[float]) -> List[ObservablesExperiment]:
    """
    Return ObservablesExperiments containing programs that constitute a CZ phase ramsey experiment.

    :param cz_qubits: the qubits participating in the cz gate
    :param measure_qubit: Which qubit to measure.
    :param angles: A list of angles at which to make a measurement
    :return: ObservablesExperiments which can be run to estimate the effective RZ rotation
        applied to a single qubit during the application of a CZ gate.
    """
    expts = []
    for angle in angles:
        settings = []
        program = Program()
        # apply CZ, possibly inducing an effective RZ on measure qubit by some angle
        program += CZ(*cz_qubits)
        # apply phase to measure_qubit akin to T2 experiment
        program += RZ(angle, measure_qubit)
        settings = [ExperimentSetting(minusY(measure_qubit), PauliTerm('Y', measure_qubit))]

        expts.append(ObservablesExperiment([settings], program))

    return expts 
开发者ID:rigetti,项目名称:forest-benchmarking,代码行数:26,代码来源:qubit_spectroscopy.py

示例12: _one_q_sic_prep

# 需要导入模块: from pyquil import gates [as 别名]
# 或者: from pyquil.gates import RZ [as 别名]
def _one_q_sic_prep(index, qubit):
    """Prepare the index-th SIC basis state."""
    if index == 0:
        return Program()

    theta = 2 * np.arccos(1 / np.sqrt(3))
    zx_plane_rotation = Program([
        RX(-pi / 2, qubit),
        RZ(theta - pi, qubit),
        RX(-pi / 2, qubit),
    ])

    if index == 1:
        return zx_plane_rotation

    elif index == 2:
        return zx_plane_rotation + RZ(-2 * pi / 3, qubit)

    elif index == 3:
        return zx_plane_rotation + RZ(2 * pi / 3, qubit)

    raise ValueError(f'Bad SIC index: {index}') 
开发者ID:rigetti,项目名称:forest-benchmarking,代码行数:24,代码来源:observable_estimation.py

示例13: test_expectations_at_depth

# 需要导入模块: from pyquil import gates [as 别名]
# 或者: from pyquil.gates import RZ [as 别名]
def test_expectations_at_depth(qvm):
    qvm.qam.random_seed = 5
    q = 0
    qubits = (q, )
    expected_outcomes = [1., 0, -1., 0]
    for depth in [0, 1, 2, 3, 4]:
        prep, meas, settings = rpe.all_eigenvector_prep_meas_settings(qubits, I(q))
        depth_many_rot = [RZ(pi/2, q) for _ in range(depth)]
        program = Program(prep) + sum(depth_many_rot, Program()) + Program(meas)
        expt = ObservablesExperiment(list(settings), program)

        results = list(estimate_observables(qvm, expt))

        for res in results:
            meas_dir = res.setting.observable[q]
            idx = ((depth - 1) if meas_dir == 'Y' else depth) % 4
            expected = expected_outcomes[idx]
            exp = res.expectation
            assert np.allclose(expected, exp, atol=.05) 
开发者ID:rigetti,项目名称:forest-benchmarking,代码行数:21,代码来源:test_robust_phase_estimation.py

示例14: decomposed_diffusion_program

# 需要导入模块: from pyquil import gates [as 别名]
# 或者: from pyquil.gates import RZ [as 别名]
def decomposed_diffusion_program(qubits: List[int]) -> Program:
    """
    Constructs the diffusion operator used in Grover's Algorithm, acted on both sides by an
    a Hadamard gate on each qubit. Note that this means that the matrix representation of this
    operator is diag(1, -1, ..., -1). In particular, this decomposes the diffusion operator, which
    is a :math:`2**{len(qubits)}\times2**{len(qubits)}` sparse matrix, into
     :math:`\mathcal{O}(len(qubits)**2) single and two qubit gates.

    See C. Lavor, L.R.U. Manssur, and R. Portugal (2003) `Grover's Algorithm: Quantum Database
    Search`_ for more information.

    .. _`Grover's Algorithm: Quantum Database Search`: https://arxiv.org/abs/quant-ph/0301079

    :param qubits: A list of ints corresponding to the qubits to operate on.
                   The operator operates on bistrings of the form
                   ``|qubits[0], ..., qubits[-1]>``.
    """
    program = Program()
    if len(qubits) == 1:
        program.inst(Z(qubits[0]))
    else:
        program.inst([X(q) for q in qubits])
        program.inst(H(qubits[-1]))
        program.inst(RZ(-np.pi, qubits[0]))
        program += (ControlledProgramBuilder()
                              .with_controls(qubits[:-1])
                              .with_target(qubits[-1])
                              .with_operation(X_GATE)
                              .with_gate_name(X_GATE_LABEL).build())
        program.inst(RZ(-np.pi, qubits[0]))
        program.inst(H(qubits[-1]))
        program.inst([X(q) for q in qubits])
    return program 
开发者ID:rigetti,项目名称:grove,代码行数:35,代码来源:amplification.py

示例15: test_param_prog_p1_barbell

# 需要导入模块: from pyquil import gates [as 别名]
# 或者: from pyquil.gates import RZ [as 别名]
def test_param_prog_p1_barbell():
    test_graph = [(0, 1)]
    p = 1
    with patch('pyquil.api.get_qc', spec=qc_mod):
        inst = maxcut_qaoa(test_graph, steps=p)

    param_prog = inst.get_parameterized_program()
    trial_prog = param_prog([1.2, 3.4])
    result_prog = Program().inst([H(0), H(1), CNOT(0, 1), RZ(3.4, 1),
                                  CNOT(0, 1), X(0), PHASE(1.7, 0), X(0),
                                  PHASE(1.7, 0), H(0), RZ(-2.4, 0), H(0), H(1),
                                  RZ(-2.4, 1), H(1)])
    assert trial_prog == result_prog 
开发者ID:rigetti,项目名称:grove,代码行数:15,代码来源:test_maxcut.py


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