예제 #1
0
def create_engine(use_QI_backend=False,
                  api=None,
                  num_runs=1,
                  verbose=False,
                  gate_fusion=False):
    """
    Creates a new MainEngine. 
    If use_QI_backend= True, Quantum Inspire is used as backend,
    else the ProjectQ default Simulator

    Returns engine for simulation
    Note: backend can be accessed via engine.backend both for QuantumInspire and ProjectQ simulators
    """
    if use_QI_backend:
        assert (
            api
            is not None), 'api must be defined if QI-backend should be used'

    # Set up compiler engines
    compiler_engines = default.get_engine_list()
    compiler_engines.extend([ManualMapper(lambda x: x)])

    if use_QI_backend:
        qi_backend = QIBackend(quantum_inspire_api=api, num_runs=num_runs)
        engine = MainEngine(backend=qi_backend,
                            engine_list=compiler_engines,
                            verbose=verbose)
    else:
        sim = Simulator(gate_fusion=gate_fusion)
        engine = MainEngine(backend=sim,
                            engine_list=compiler_engines,
                            verbose=verbose)

    return engine
예제 #2
0
# -*- coding: utf-8 -*-
# pylint: skip-file
"""Example implementation of a quantum circuit generating a Bell pair state."""

import matplotlib.pyplot as plt
from teleport import create_bell_pair

from projectq import MainEngine
from projectq.backends import CircuitDrawer
from projectq.libs.hist import histogram
from projectq.setups.default import get_engine_list

# create a main compiler engine
drawing_engine = CircuitDrawer()
eng = MainEngine(engine_list=get_engine_list() + [drawing_engine])

qb0, qb1 = create_bell_pair(eng)

eng.flush()
print(drawing_engine.get_latex())

histogram(eng.backend, [qb0, qb1])
plt.show()
예제 #3
0
from projectq.ops import X, Y, Z, T, H, CNOT, SqrtX, All, Measure
from hiq.projectq.backends import SimulatorMPI
from hiq.projectq.cengines import GreedyScheduler, HiQMainEngine
from projectq.backends import CommandPrinter
from projectq.setups.default import get_engine_list

import numpy as np
import random
import copy
from mpi4py import MPI

# Create main engine to compile the code to machine instructions(required)
#eng = HiQMainEngine(SimulatorMPI(gate_fusion=True, num_local_qubits=20))
eng = HiQMainEngine(engine_list=get_engine_list() + [CommandPrinter()])

# Qubit number N
num_of_qubit = 5

#Circuit Depth
depth = 30

# Gate
gate_set = [X, Y, Z, T, H, SqrtX, CNOT]

# Use the method provided by the main engine to create qubit registers
qureg = eng.allocate_qureg(num_of_qubit)

for i in range(depth):

    #Pick random gate from gate_set
    chosen_gate = random.sample(gate_set, 1)
예제 #4
0
def circuit(engine):
    q = engine.allocate_qureg(2)

    q = oracale(q)
    q = reflection(q)

    #All(Measure) | q

    engine.flush()

    histogram(eng.backend, q)
    plt.show()


#engine = input("Engin> ")
engine = "aqt"

if engine == "aqt":
    backend = AQTBackend(use_hardware=True,
                         token=token,
                         num_runs=200,
                         verbose=False,
                         device=device)
    engine_list = projectq.setups.aqt.get_engine_list(token=token,
                                                      device=device)
    eng = MainEngine(backend, engine_list=engine_list)
if engine == "sim":
    eng = MainEngine(engine_list=get_engine_list())

circuit(eng)