def get_qiskit_noise_model( device_name: str, hub: str = "ibm-q", group: str = "open", project: str = "main", api_token: Optional[str] = None, ) -> Tuple[NoiseModel, CircuitConnectivity]: """Get a qiskit noise model to use noisy simulations with a qiskit simulator Args: device_name: The name of the device trying to be emulated hub: The ibmq hub (see qiskit documentation) group: The ibmq group (see qiskit documentation) project: The ibmq project (see qiskit documentation) api_token: The ibmq api token (see qiskit documentation) """ if api_token is not None and api_token is not "None": try: IBMQ.enable_account(api_token) except IBMQAccountError as e: if (e.message != "An IBM Quantum Experience account is already in use for the session." ): raise RuntimeError(e) # Get qiskit noise model from qiskit provider = IBMQ.get_provider(hub=hub, group=group, project=project) noisy_device = provider.get_backend(device_name) noise_model = AerNoise.NoiseModel.from_backend(noisy_device) coupling_map = noisy_device.configuration().coupling_map return noise_model, CircuitConnectivity(coupling_map)
def __init__( self, device_name: str, n_samples: Optional[int] = None, hub: Optional[str] = "ibm-q", group: Optional[str] = "open", project: Optional[str] = "main", api_token: Optional[str] = None, readout_correction: Optional[bool] = False, optimization_level: Optional[int] = 0, retry_delay_seconds: Optional[int] = 60, retry_timeout_seconds: Optional[int] = 86400, **kwargs, ): """Get a qiskit QPU that adheres to the zquantum.core.interfaces.backend.QuantumBackend Args: device_name: the name of the device n_samples: the number of samples to use when running the device hub: IBMQ hub group: IBMQ group project: IBMQ project api_token: IBMQ Api Token readout_correction: flag of whether or not to use basic readout correction optimization_level: optimization level for the default qiskit transpiler (0, 1, 2, or 3). retry_delay_seconds: Number of seconds to wait to resubmit a job when backend job limit is reached. retry_timeout_seconds: Number of seconds to wait """ super().__init__(n_samples=n_samples) self.device_name = device_name if api_token is not None: try: IBMQ.enable_account(api_token) except IBMQAccountError as e: if e.message != ( "An IBM Quantum Experience account is already in use " "for the session." ): raise RuntimeError(e) provider = IBMQ.get_provider(hub=hub, group=group, project=project) self.device = provider.get_backend(name=self.device_name) self.max_shots = self.device.configuration().max_shots self.batch_size = self.device.configuration().max_experiments self.supports_batching = True self.readout_correction = readout_correction self.readout_correction_filter = None self.optimization_level = optimization_level self.basis_gates = kwargs.get( "basis_gates", self.device.configuration().basis_gates ) self.retry_delay_seconds = retry_delay_seconds self.retry_timeout_seconds = retry_timeout_seconds
def _wrapper(*args, **kwargs): _enable_account(kwargs.pop('qe_token'), kwargs.pop('qe_url')) # Get the private hub/group/project. hgp = os.getenv('QE_STAGING_PRIVATE_HGP', None) \ if os.getenv('USE_STAGING_CREDENTIALS', '') else os.getenv('QE_PRIVATE_HGP', None) if not hgp: raise SkipTest('Requires private provider.') hgp = hgp.split('/') provider = IBMQ.get_provider(hub=hgp[0], group=hgp[1], project=hgp[2]) kwargs.update({'provider': provider}) return func(*args, **kwargs)
def _wrapper(*args, **kwargs): _enable_account(kwargs.pop("qe_token"), kwargs.pop("qe_url")) # Get the private hub/group/project. hgp = (os.getenv("QISKIT_IBM_STAGING_PRIVATE_HGP", None) if os.getenv( "QISKIT_IBM_USE_STAGING_CREDENTIALS", "") else os.getenv( "QISKIT_IBM_PRIVATE_HGP", None)) if not hgp: raise SkipTest("Requires private provider.") hgp = hgp.split("/") provider = IBMQ.get_provider(hub=hgp[0], group=hgp[1], project=hgp[2]) kwargs.update({"provider": provider}) return func(*args, **kwargs)
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')