How to use the projectq.ops.Rz function in projectq

To help you get started, we’ve selected a few projectq 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 XanaduAI / pennylane-pq / pennylane_pq / devices.py View on Github external
:class:`pennylane.PauliZ` basis. These measurements may thus be slightly more
       noisy than native :class:`pennylane.PauliZ` measurement.


    Extra Operations:
      :class:`pennylane_pq.S `,
      :class:`pennylane_pq.T `,
      :class:`pennylane_pq.SqrtX `,
      :class:`pennylane_pq.SqrtSwap `,

    """

    short_name = 'projectq.ibm'
    _operation_map = {key:val for key, val in PROJECTQ_OPERATION_MAP.items()
                      if val in [HGate, XGate, YGate, ZGate, SGate, TGate,
                                 SqrtXGate, SwapGate, SqrtSwapGate, Rx, Ry, Rz, R, CNOT,
                                 CZ, Rot, BasisState]}
    _observable_map = dict({key:val for key, val in _operation_map.items() if val in [HGate, XGate, YGate, ZGate]}, **{'Identity': None})
    _circuits = {}
    _backend_kwargs = ['use_hardware', 'num_runs', 'verbose', 'user', 'password', 'device',
                       'retrieve_execution']

    def __init__(self, wires=1, shots=1024, **kwargs):
        # check that necessary arguments are given
        if 'user' not in kwargs:
            raise ValueError('An IBM Quantum Experience user name specified via the "user" keyword argument is required') #pylint: disable=line-too-long
        if 'password' not in kwargs:
            raise ValueError('An IBM Quantum Experience password specified via the "password" keyword argument is required') #pylint: disable=line-too-long

        import projectq.setups.ibm #pylint: disable=unused-variable

        kwargs['backend'] = 'IBMBackend'
github QuantumBFS / Yao.jl / benchmark / projectq / bench.py View on Github external
def rot(self):
        tl = []
        for nsite, num_bench in zip(NL, [1000, 1000, 1000, 100, 10, 5]):
            print('========== N: %d ============'%nsite)
            for func in [bRot(ops.Rx), bRot(ops.Ry), bRot(ops.Rz)]:
                tl.append(qbenchmark(func, nsite, num_bench)*1e6)
        np.savetxt('rot-report.dat', tl)
github ProjectQ-Framework / FermiLib / src / fermilib / circuits / _low_depth_trotter_simulation.py View on Github external
"""Apply the 'special F' (fermionic swap, XX+YY evolution, and ZZ
    evolution) gate to the register on qubit_index and qubit_index + 1.

    Args:
        register (projectq.QuReg): The register to apply the gate to.
        qubit_index (integer): The left qubit to act on.
        xx_yy_angle (float): The angle for evolution under XX+YY.
        zz_angle (float): The angle for evolution under ZZ.
    """
    Rx(numpy.pi / 2.) | register[qubit_index]
    CNOT | (register[qubit_index], register[qubit_index + 1])
    Rx(xx_yy_angle) | register[qubit_index]
    Ry(xx_yy_angle) | register[qubit_index + 1]
    CNOT | (register[qubit_index + 1], register[qubit_index])
    Rx(-numpy.pi / 2.) | register[qubit_index + 1]
    Rz(zz_angle) | register[qubit_index + 1]
    Sdag | register[qubit_index + 1]
    CNOT | (register[qubit_index], register[qubit_index + 1])
    S | register[qubit_index]
    S | register[qubit_index + 1]
github Qiskit / qiskit-terra / qiskit / backends / local / qasm_simulator_projectq.py View on Github external
# Do each operation in this shot
            for operation in ccircuit['operations']:
                if 'conditional' in operation:
                    mask = int(operation['conditional']['mask'], 16)
                    if mask > 0:
                        value = self._classical_state & mask
                        while (mask & 0x1) == 0:
                            mask >>= 1
                            value >>= 1
                        if value != int(operation['conditional']['val'], 16):
                            continue
                # Check if single  gate
                if operation['name'] in ['U', 'u3']:
                    params = operation['params']
                    qubit = qureg[operation['qubits'][0]]
                    Rz(params[2]) | qubit
                    Ry(params[0]) | qubit
                    Rz(params[1]) | qubit
                elif operation['name'] in ['u1']:
                    params = operation['params']
                    qubit = qureg[operation['qubits'][0]]
                    Rz(params[0]) | qubit
                elif operation['name'] in ['u2']:
                    params = operation['params']
                    qubit = qureg[operation['qubits'][0]]
                    Rz(params[1] - np.pi/2) | qubit
                    Rx(np.pi/2) | qubit
                    Rz(params[0] + np.pi/2) | qubit
                elif operation['name'] == 't':
                    qubit = qureg[operation['qubits'][0]]
                    T | qubit
                elif operation['name'] == 'h':
github Huawei-HiQ / HiQsimulator / examples / exactgrover_mpi.py View on Github external
def alternating_bits_oracle_modified(eng, qubits, output, phi):
    """
    Marks the solution string 0,1,0,... by applying phase gate to the output bits,
    conditioned on qubits being equal to the alternating bit-string.

    Args:
        eng (MainEngine): Main compiler engine the algorithm is being run on.
        qubits (Qureg): n-qubit quantum register Grover search is run on.
        output (Qubit): Output qubit to mark the solution by a phase gate with parameter phi.
    """
    with Compute(eng):
        All(X) | qubits[1::2]
    with Control(eng, qubits):
        Rz(phi) | output
        Ph(phi/2) | output

    Uncompute(eng)
github QuantumBFS / Yao.jl / benchmark / projectq / bench.py View on Github external
def crot(self):
        tl = []
        for nsite, num_bench in zip(NL, [1000, 1000, 1000, 100, 10, 5]):
            print('========== N: %d ============'%nsite)
            for func in [bCRot(ops.Rx), bCRot(ops.Ry), bCRot(ops.Rz)]:
                tl.append(qbenchmark(func, nsite, num_bench)*1e6)
        np.savetxt('crot-report.dat', tl)
github ProjectQ-Framework / ProjectQ / projectq / backends / _ibm / _ibm.py View on Github external
"""
        Return true if the command can be executed.

        The IBM quantum chip can do X, Y, Z, T, Tdag, S, Sdag,
        rotation gates, barriers, and CX / CNOT.

        Args:
            cmd (Command): Command for which to check availability
        """
        g = cmd.gate
        if g == NOT and get_control_count(cmd) <= 1:
            return True
        if get_control_count(cmd) == 0:
            if g in (T, Tdag, S, Sdag, H, Y, Z):
                return True
            if isinstance(g, (Rx, Ry, Rz)):
                return True
        if g in (Measure, Allocate, Deallocate, Barrier):
            return True
        return False
github Huawei-HiQ / HiQsimulator / examples / exactgrover_mpi.py View on Github external
with Control(eng, x[0:-1]):
            Z | x[-1]

        Uncompute(eng)
   
    # prepare the oracle output qubit (the one that is flipped to indicate the
    # solution. start in state |1> s.t. a bit-flip turns into a e^(i*phi)-phase. 
    H | oracle_out
    oracle_modified(eng, x, oracle_out, phi)
    
    with Compute(eng):
        All(H) | x
        All(X) | x

    with Control(eng, x[0:-1]):
        Rz(varphi) | x[-1]
        Ph(varphi/2) | x[-1]

    Uncompute(eng)
    
    All(Measure) | x
    Measure | oracle_out

    eng.flush()
    # return result
    return [int(qubit) for qubit in x]
github ProjectQ-Framework / FermiLib / src / fermilib / circuits / _ffft.py View on Github external
def apply_phase(register, mode, phase):
    """Apply a phase to a fermionic mode if it is occupied.

    The phase is applied to the qubit corresponding to the mode under
    the Jordan-Wigner transformation.

    Args:
        register (projectq.Qureg): The register of qubits to act on.
        mode (int): The mode to apply the phase to.
    """
    Rz(2 * phase) | register[mode]
github quantumlib / OpenFermion-ProjectQ / openfermionprojectq / _ffft.py View on Github external
def apply_phase(register, mode, phase):
    """Apply a phase to a fermionic mode if it is occupied.

    The phase is applied to the qubit corresponding to the mode under
    the Jordan-Wigner transformation.

    Args:
        register (projectq.Qureg): The register of qubits to act on.
        mode (int): The mode to apply the phase to.
    """
    Rz(2 * phase) | register[mode]