Example #1
0
 def _shors_period_finder(self, job_descriptor: ShorJobDescriptor, fleet: QFleet, shots=None):
     key = str(job_descriptor)
     self.logger.debug("Constructing circuit for Shor's algorithm on {}".format(key))
     self._update_status(job_descriptor,
                         status=QStatus.CONSTRUCTING_CIRCUIT)
     n = job_descriptor.n
     a = job_descriptor.a
     shor = Shor(N=n, a=a)
     circ = shor.construct_circuit(measurement=True)
     self.logger.debug("Constructed circuit for {}, finding backend...".format(key))
     self._update_status(job_descriptor,
                         status=QStatus.FINDING_BACKEND)
     qcomp = fleet.get_best_backend(circ.n_qubits, job_descriptor.allow_simulator)
     if not qcomp:
         raise QNoBackendException("No viable backend with {} qubits for job {}".format(circ.n_qubits, key))
     self.logger.debug("Got backend '{}' for job {}. Executing...".format(qcomp.name(), key))
     self._update_status(job_descriptor,
                         status=QStatus.REQUEST_EXECUTE,
                         backend=qcomp)
     kwargs = {'backend': qcomp}
     if shots:
         kwargs['shots'] = shots
     job = execute(circ, **kwargs)
     self.logger.debug("Started job {}, status is {}".format(key, job.status()))
     self._update_status_by_job(job_descriptor, job, circ)
     return job, circ
Example #2
0
def shor_circuit():
    """
    Builds A QuantumCircuit object of shor's algorithm implementation
    found in qiskit aqua

    Args:

    Returns:
        Resulting circuit of the qiskit aqua implementation of Shor's
        algorithm after adding measures on every qubit.
    """
    shor = Shor()
    circ = shor.construct_circuit()
    return add_measures(circ)
Example #3
0
import logging
import os
from qiskit.aqua.algorithms import Shor

from definitions import OUTPUT_DIR

logging.basicConfig(format="%(message)s", level=logging.INFO)
logger = logging.getLogger(__name__)

Ns = 15, 21, 39

for N in Ns:
    logging.info("\nShor's circuit configuration for factoring {}:".format(N))
    shor = Shor(N)

    qc = shor.construct_circuit()
    qc.draw(output='latex_source',
            filename=(os.path.join(OUTPUT_DIR,
                                   'shors-diag-for-{}.tex'.format(N))))

    num_qubits = qc.num_qubits
    num_classical_bits = qc.num_clbits

    # get the number and type of the gates in circuit
    num_ops = qc.count_ops()

    # get just the raw count of operations by computing the circuits size
    size = qc.size()
    '''The depth of a quantum circuit is a measure of how many "layers" of quantum gates, executed in parallel, 
    it takes to complete the computation defined by the circuit. Because quantum gates take time to implement, 
    the depth of a circuit roughly corresponds to the amount of time it takes the quantum computer to execute the 
# -*- coding: utf-8 -*-
"""
Created on Fri Apr 24 21:06:08 2020

@author: Neil Gupte
"""
from qiskit import IBMQ
from qiskit.aqua import QuantumInstance
from qiskit.aqua.algorithms import Shor

IBMQ.enable_account( ' aditya replace your token here 52b916f6b6934d0ff3a5754d98217dc1862bcb88cc04acc77147936d166cb28f67d4f60d6fd492b7') # Enter your API token here
provider = IBMQ.get_provider(hub='ibm-q')

backend = provider.get_backend('ibmq_qasm_simulator') # Specifies the quantum device

print('\n Shors Algorithm')
print('--------------------')
print('\nExecuting...\n')

factors = Shor(15) #Function to run Shor's algorithm where 21 is the integer to be factored

result_dict = factors.run(QuantumInstance(backend, shots=1, skip_qobj_validation=False))
result = result_dict['factors'] # Get factors from results

print(result)
print('\nPress any key to close')

circuit =Shor.construct_circuit() #check if we show the circuit by any means there is a circuit available on ibmq dashboard but it is too large to display see if there is a way to show that circuit
circuit.draw()