Exemplo n.º 1
0
    def setup(self):
        need_token = self.use_actual_hardware or not self.run_locally
        if need_token:
            if self.ibm_qe_api_token is None:
                self.ibm_qe_api_token = getpass.getpass(
                    'Please input your token and hit enter: ')
            self.qx_config = {
                'APItoken': self.ibm_qe_api_token,
                'url': 'https://quantumexperience.ng.bluemix.net/api'
            }
            try:
                print('registering API token...')
                register(self.qx_config['APItoken'], self.qx_config['url'])

                print('\nYou have access to great power!')
                print(available_backends({'local': False, 'simulator': False}))
            except:
                print('Something went wrong.\nDid you enter a correct token?')
                exit()

        # If no backend is requested, find the least busy one
        if self.qiskit_backend is None:
            self.qiskit_backend = least_busy(
                available_backends({
                    'simulator': (not self.use_actual_hardware),
                    'local': self.run_locally
                }))

        print('available_backends: {}'.format(available_backends()))
        print('Using simulator backend: ' + self.qiskit_backend)
Exemplo n.º 2
0
    def _get_backends(self, QE_TOKEN, QE_URL):
        sim_backend = 'local_qasm_simulator'
        try:
            register(QE_TOKEN, QE_URL)
            real_backends = available_backends({'simulator': False})
            real_backend = least_busy(real_backends)
        except Exception:
            real_backend = None

        return sim_backend, real_backend
Exemplo n.º 3
0
    def _get_backends(self, qe_token, qe_url):
        sim_backend = 'local_qasm_simulator'
        try:
            register(qe_token, qe_url)
            real_backends = available_backends({'simulator': False})
            real_backend = least_busy(real_backends)
        except Exception:
            real_backend = None

        return sim_backend, real_backend
Exemplo n.º 4
0
    # Compile and run the Quantum circuit on a simulator backend
    job_sim = execute(qc, "local_qasm_simulator")
    sim_result = job_sim.result()

    # Show the results
    print("simulation: ", sim_result)
    print(sim_result.get_counts(qc))

    # see a list of available remote backends
    remote_backends = available_backends({'local': False, 'simulator': False})

    print("Remote backends: ", remote_backends)
    # Compile and run the Quantum Program on a real device backend
    try:
        least_busy_device = least_busy(available_backends())
        print("Running on current least busy device: ", least_busy_device)

        #runing the job
        job_exp = execute(qc, least_busy_device, shots=1024, max_credits=10)
        exp_result = job_exp.result()

        # Show the results
        print("experiment: ", exp_result)
        print(exp_result.get_counts(qc))
    except:
        print("All devices are currently unavailable.")

except QISKitError as ex:
    print('There was an error in the circuit!. Error = {}'.format(ex))
Exemplo n.º 5
0
    x_bar = mean(x)
    return [x_i - x_bar for x_i in x]


def variance(x):
    n = len(x)
    deviations = de_mean(x)
    return sum_of_squares(deviations) / n


def expected_value(p, x):
    return sum([pi * xi for pi, xi in zip(p, x)])


# initialize
backend = least_busy(available_backends({'simulator': True, 'local': True}))
quantumReg = QuantumRegister(3)
classicReg = ClassicalRegister(3)
quantumCirc = QuantumCircuit(quantumReg, classicReg)
# grab user prefs
roll_count = int(input("Number of rolls? (up to 8192): "))
#build the dice, according to entangled states or not
quantumCirc.h(quantumReg[0])
quantumCirc.h(quantumReg[1])
quantumCirc.h(quantumReg[2])
quantumCirc.measure(quantumReg[0], classicReg[0])
quantumCirc.measure(quantumReg[1], classicReg[1])
quantumCirc.measure(quantumReg[2], classicReg[2])
# run the quantumCirc and get result for dice
job = execute(quantumCirc, backend=backend, shots=roll_count)
counts = job.result().get_counts(quantumCirc)