def test_autoregister_no_credentials(self): """Test register() with no credentials available.""" with no_file('Qconfig.py'), custom_qiskitrc(), no_envs(CREDENTIAL_ENV_VARS): with self.assertRaises(IBMQAccountError) as context_manager: IBMQ.load_account() self.assertIn('No IBM Q Experience credentials found', str(context_manager.exception))
def _try_login_saved_account(cls) -> bool: if not QiskitIBMQ.active_account(): try: QiskitIBMQ.load_account() except IBMQAccountCredentialsNotFound: print(f"No saved account found for IBMQ. Only simulator devices will be available. {_IBMQHints.LOGIN}") return False # Failed login return True # Successful login
def test_load_account_no_credentials(self) -> None: """Test ``load_account()`` with no credentials available.""" with custom_qiskitrc(), no_envs(CREDENTIAL_ENV_VARS): with self.assertRaises(IBMQAccountError) as context_manager: IBMQ.load_account() self.assertIn('No IBM Quantum Experience credentials found', str(context_manager.exception))
def load_account_oneshot(): try: IBMQ.load_account() except IBMQAccountError as e: print("Couldn't load IBMQ account: {}".format(e)) print("Try again, loading API key from file...") with open(IBMQ_TOKEN_FILENAME, 'r') as file: IBMQ.save_account(file.read()) IBMQ.load_account()
def analyze_circuit(circuit: QuantumCircuit): provider = IBMQ.load_account() backend = provider.get_backend("ibmq_ourense") print(circuit) mapped_circuit = transpile(circuit, backend=backend, optimization_level=0) qobj = assemble(mapped_circuit, backend=backend, shots=8192) print(mapped_circuit) print(qobj)
def get_ibm_qc(n_qubits): provider = IBMQ.load_account() backend = provider.backends( filters=lambda x: x.configuration().n_qubits >= n_qubits and not x. configuration().simulator and x.status().operational) if len(backend) == 0: raise Exception("No backend found with the given constraints") return least_busy(backend)
def get_provider(hub='ibm-q'): """Create an IBMQ provider with Qiskit to be used as a device in qbitkit Args: hub (str): The hub to pick IBM Q machines from. (default 'ibm-q') Returns: qiskit.providers.BaseProvider: the IBMQ provider""" # Create a provider object from specified hub name. provider = __IBMQ__.load_account(hub) # Return new provider object. return provider
def run_circuit(circuit: QuantumCircuit): """account must be saved first: https://quantum-computing.ibm.com/""" provider = IBMQ.load_account() # print(provider.backends(simulator=False, operational=True)) backend = provider.get_backend("ibmq_ourense") print(backend) mapped_circuit = transpile(circuit, backend=backend) qobj = assemble(mapped_circuit, backend=backend, shots=8192) # print(qobj) job = backend.run(qobj) print("Job: ") print(job) print(job.status()) print(job.job_id()) result = job.result() counts = result.get_counts() print(counts)
register_token() qubits = 4 circuit = QuantumCircuit(qubits, qubits) circuit.h(0) circuit.cx(0, 1) circuit.cx(1, 2) circuit.measure([0, 1, 2, 3], [0, 1, 2, 3]) circuit.draw(output='mpl') simulator = Aer.get_backend('qasm_simulator') sim_result = execute(circuit, backend=simulator, shots=1024).result() plot_histogram(sim_result.get_counts(circuit)) IBMQ.load_account() provider = IBMQ.get_provider(hub='ibm-q') device = provider.get_backend('ibmqx2') job = execute(circuit, backend=device, shots=1024) print("Job ID:", job.job_id()) job_monitor(job) device_result = job.result() plot_histogram(device_result.get_counts(circuit)) cal_circuits, state_labels = complete_meas_cal( qr=circuit.qregs[0], circlabel='measerrormitigationcal') cal_circuits[2].draw(output='mpl')
qft4.barrier() for j in range(4): qft4.measure(j, j) input_state(qft5, 5) qft5.barrier() qft(qft5, 5) qft5.barrier() for j in range(5): qft5.measure(j, j) print(qft3) print(qft4) print(qft5) ############################################################### # Set up the API and execute the program. ############################################################### provider = IBMQ.load_account() # Second version: real device least_busy_device = least_busy( provider.backends(simulator=False, filters=lambda x: x.configuration().n_qubits > 4)) print("Running on current least busy device: ", least_busy_device) job = execute([qft3, qft4, qft5], least_busy_device, shots=1024) result = job.result() print(result.get_counts(qft3)) print(result.get_counts(qft4)) print(result.get_counts(qft5))
def ibmq(qpu_name: str): provider = IBMQ.load_account() backend = provider.get_backend(qpu_name) return CouplingMap(backend.configuration().coupling_map)