How to use the pyquil.gates.RY function in pyquil

To help you get started, we’ve selected a few pyquil examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rigetti / reference-qvm / tests / test_wavefunction.py View on Github external
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]
    wf_true = np.reshape(np.array(wf_true), (4, 1))
    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)
github qctrl / python-open-controls / tests / test_pyquil_sequence.py View on Github external
azimuthal_angles=_azimuthal_angles,
        detuning_rotations=_detuning_rotations)

    program = convert_dds_to_pyquil_program(
        sequence,
        [0],
        gate_time=1e-6)

    assert len(program) == 13
    assert program[0] == Pragma("PRESERVE_BLOCK")
    assert program[-1] == Pragma("END_PRESERVE_BLOCK")
    assert program[1] == RX(np.pi/2, 0)
    assert program[2] == I(0)
    assert program[3] == RX(np.pi / 2, 0)
    assert program[4] == I(0)
    assert program[5] == RY(np.pi, 0)
    assert program[6] == I(0)
    assert program[7] == RZ(np.pi, 0)
    assert program[8] == I(0)
    assert program[9] == RX(np.pi / 2, 0)
github rigetti / grove / grove / tomography / tomography.py View on Github external
                                    (lambda q: RY(np.pi / 2, q), (-1j * np.pi / 4 * QY).expm()),
                                    (lambda q: RX(np.pi, q), (-1j * np.pi / 2 * QX).expm())])
github rigetti / pyquil / pyquil / operator_estimation.py View on Github external
def _local_pauli_eig_meas(op, idx):
    """
    Generate gate sequence to measure in the eigenbasis of a Pauli operator, assuming
    we are only able to measure in the Z eigenbasis. (Note: The unitary operations of this
    Program are essentially the Hermitian conjugates of those in :py:func:`_one_q_pauli_prep`)

    """
    if op == "X":
        return Program(RY(-pi / 2, idx))
    elif op == "Y":
        return Program(RX(pi / 2, idx))
    elif op == "Z":
        return Program()
    raise ValueError(f"Unknown operation {op}")
github rigetti / grove / grove / measurements / estimation.py View on Github external
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
github rigetti / pyquil / pyquil / operator_estimation.py View on Github external
def _one_q_pauli_prep(label, index, qubit):
    """Prepare the index-th eigenstate of the pauli operator given by label."""
    if index not in [0, 1]:
        raise ValueError(f"Bad Pauli index: {index}")

    if label == "X":
        if index == 0:
            return Program(RY(pi / 2, qubit))
        else:
            return Program(RY(-pi / 2, qubit))

    elif label == "Y":
        if index == 0:
            return Program(RX(-pi / 2, qubit))
        else:
            return Program(RX(pi / 2, qubit))

    elif label == "Z":
        if index == 0:
            return Program()
        else:
            return Program(RX(pi, qubit))

    raise ValueError(f"Bad Pauli label: {label}")
github qctrl / python-open-controls / qctrlopencontrols / pyquil / program.py View on Github external
'with multiple rotation operations at an offset.',
                {'dynamic_decoupling_sequence': dynamic_decoupling_sequence},
                extras={'offset': offset,
                        'rabi_rotation': rabi_rotation,
                        'azimuthal_angle': azimuthal_angle,
                        'detuning_rotation': detuning_rotation}
            )

        for qubit in target_qubits:
            if nonzero_pulse_counts == 0:
                program += I(qubit)
            else:
                if not np.isclose(rotations[0], 0.0):
                    program += RX(rotations[0], qubit)
                elif not np.isclose(rotations[1], 0.0):
                    program += RY(rotations[1], qubit)
                elif not np.isclose(rotations[2], 0.):
                    program += RZ(rotations[2], qubit)

        time_covered = offset + unitary_time

    if add_measurement:
        readout = program.declare('ro', 'BIT', len(target_qubits))
        for idx, qubit in enumerate(target_qubits):
            program += MEASURE(qubit, readout[idx])

    program += Pragma('END_PRESERVE_BLOCK')

    return program