How to use the projectq.MainEngine 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 Roger-luo / quantum-benchmarks / projectq / View on Github external
def run_bench(benchmark, G, locs, nqubits):
    eng = MainEngine()
    reg = eng.allocate_qureg(nqubits)
    qi = take_locs(reg, locs)
    benchmark(run_gate, eng, G, qi)
github Qiskit / qiskit-terra / qiskit / backends / local / View on Github external
            SimulatorError: if an error occurred.
        # pylint: disable=expression-not-assigned,pointless-statement
        ccircuit = circuit['compiled_circuit']
        self._number_of_qubits = ccircuit['header']['number_of_qubits']
        self._number_of_clbits = ccircuit['header']['number_of_clbits']
        self._statevector = 0
        self._classical_state = 0
        cl_reg_index = []  # starting bit index of classical register
        cl_reg_nbits = []  # number of bits in classical register
        clbit_index = 0
        qobj_quregs = OrderedDict(_get_register_specs(
        eng = MainEngine(backend=self._sim)
        for cl_reg in ccircuit['header']['clbit_labels']:
            clbit_index += cl_reg[1]
        # let circuit seed override qobj default
        if 'config' in circuit:
            if 'seed' in circuit['config']:
                if circuit['config']['seed'] is not None:
                    self._sim._simulator = CppSim(circuit['config']['seed'])
        outcomes = []
        start = time.time()
        for _ in range(self._shots):
            self._statevector = np.zeros(1 << self._number_of_qubits,
            self._statevector[0] = 1
            # initialize starting state
github XanaduAI / pennylane-pq / pennylane_pq / View on Github external
def reset(self):
        """Reset/initialize the device by initializing the backend and engine, and allocating qubits.
        backend = pq.backends.ClassicalSimulator(**self.filter_kwargs_for_backend(self._kwargs))
        self._eng = pq.MainEngine(backend, verbose=self._kwargs['verbose'])
github libtangle / qcgpu / View on Github external
def bench_projectq(n, depth):
    eng = MainEngine(backend=Simulator(gate_fusion=True), engine_list=[])
    qbits = eng.allocate_qureg(n)

    start = time.time()

    for level in range(depth):
        for q in qbits:
            ops.H | q
            ops.T | q
            if q != qbits[0]:
                ops.CNOT | (q, qbits[0])

    for q in qbits:
        ops.Measure | q
    return time.time() - start
github ProjectQ-Framework / FermiLib / src / fermilib / circuits / View on Github external
# Build the full set of engines that will be applied to qubits
    replacer = projectq.cengines.AutoReplacer(rule_set)
    compiler_engine_list = [replacer,
                                lambda x, y:
                                (_non_adjacent_filter(x, y, qubit_graph) and
                                 _two_gate_filter(x, y)))]
    if opt_size is not None:

    # Start the compiler engine with these rules
    compiler_engine = (
    return compiler_engine
github QuTech-Delft / quantuminspire / docs / View on Github external
email, password = QI_EMAIL, QI_PASSWORD
        return get_basic_authentication(email, password)

if __name__ == '__main__':

    # Remote Quantum-Inspire backend #
    authentication = get_authentication()
    qi = QuantumInspireAPI(QI_URL, authentication)
    qi_backend = QIBackend(quantum_inspire_api=qi)

    compiler_engines = restrictedgateset.get_engine_list(one_qubit_gates=qi_backend.one_qubit_gates,
    qi_engine = MainEngine(backend=qi_backend, engine_list=compiler_engines)

    # Run remote Grover search to find a n-bit solution
    result_qi = run_grover(qi_engine, 3, alternating_bits_oracle)
    print("\nResult from the remote Quantum-Inspire backend: {}".format(result_qi))

    # Local ProjectQ simulator backend #
    compiler_engines = restrictedgateset.get_engine_list(one_qubit_gates="any", two_qubit_gates=(CNOT, CZ))
    local_engine = MainEngine(Simulator(), compiler_engines)

    # Run local Grover search to find a n-bit solution
    result_local = run_grover(local_engine, 3, alternating_bits_oracle)
    print("Result from the local ProjectQ simulator backend: {}\n".format(result_local))
github Huawei-HiQ / HiQsimulator / hiq / projectq / cengines / View on Github external
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.

from projectq import MainEngine
from projectq.ops import Command, Deallocate
from projectq.types import Qureg, Qubit, WeakQubitRef

from hiq.projectq.ops import AllocateQuregGate

class HiQMainEngine(MainEngine):
    HiQ Main Engine provides all functionality of the main compiler engine.
    It is an extension of ProjectQ MainEngine adopted for using with

    def allocate_qureg(self, n, init=0.0):
        Allocate n qubits and return them as a quantum register, which is a
        list of qubit objects.

            n (int): Number of qubits to allocate
            init (complex): Assign this value to every amplitude
            Qureg of length n, a list of n newly allocated qubits.