quri_parts.qiskit.backend.primitive module#

class quri_parts.qiskit.backend.primitive.QiskitRuntimeSamplingResult(qiskit_result: SamplerResult)#

Bases: SamplingResult

Class for the results by Qiskit sampler job.

property counts: Mapping[int, float | int]#

Measurement counts obtained by a sampling measurement.

class quri_parts.qiskit.backend.primitive.QiskitRuntimeSamplingJob(qiskit_job: RuntimeJob)#

Bases: SamplingJob

A job for a Qiskit sampling measurement.

result() SamplingResult#

Returns the result of the sampling job.

If the job is not complete, this method waits until the job finishes.

class quri_parts.qiskit.backend.primitive.QiskitRuntimeSamplingBackend(backend: ~qiskit_ibm_runtime.ibm_backend.IBMBackend, service: ~qiskit_ibm_runtime.qiskit_runtime_service.QiskitRuntimeService | None = None, circuit_converter: ~typing.Callable[[~quri_parts.circuit.circuit.NonParametricQuantumCircuit, ~typing.Callable[[~quri_parts.circuit.circuit.NonParametricQuantumCircuit], ~quri_parts.circuit.circuit.NonParametricQuantumCircuit] | None], ~qiskit.circuit.quantumcircuit.QuantumCircuit] = <function convert_circuit>, circuit_transpiler: ~typing.Callable[[~quri_parts.circuit.circuit.NonParametricQuantumCircuit], ~quri_parts.circuit.circuit.NonParametricQuantumCircuit] | None = None, enable_shots_roundup: bool = True, qubit_mapping: ~collections.abc.Mapping[int, int] | None = None, sampler_options: None | ~qiskit_ibm_runtime.options.options.Options | ~typing.Dict[str, ~typing.Any] = None, run_kwargs: ~collections.abc.Mapping[str, ~typing.Any] = {}, save_data_while_sampling: bool = False, total_time_limit: float | None = None, single_job_max_execution_time: float | None = None, strict_time_limit: bool = False)#

Bases: SamplingBackend

A Qiskit backend for a sampling measurement.

  • backend – A Qiskit qiskit_ibm_runtime.ibm_backend that interfaces with IBM quantum backend.

  • service – A Qiskit

:param qiskit_ibm_runtime.qiskit_runtime_service.QiskitRuntimeService: :param that interacts with the Qiskit Runtime service.: :param circuit_converter: A function converting

NonParametricQuantumCircuit to a Qiskit qiskit.circuit.QuantumCircuit.

  • circuit_transpiler – A transpiler applied to the circuit before running it. QiskitTranspiler is used when not specified.

  • enable_shots_roundup – If True, when a number of shots specified to sample() is smaller than the minimum number of shots supported by the device, it is rounded up to the minimum. In this case, it is possible that shots more than specified are used. If it is strictly not allowed to exceed the specified shot count, set this argument to False.

  • qubit_mapping – If specified, indices of qubits in the circuit are remapped before running it on the backend. It can be used when you want to use specific backend qubits, e.g. those with high fidelity. The mapping should be specified with “from” qubit indices as keys and “to” qubit indices as values. For example, if you want to map qubits 0, 1, 2, 3 to backend qubits as 0 → 4, 1 → 2, 2 → 5, 3 → 0, then the qubit_mapping should be {0: 4, 1: 2, 2: 5, 3: 0}.

  • sampler_options – Options for providing sampler. It can be a dictionary or a qiskit_ibm_runtime.Options.

  • run_kwargs – Additional keyword arguments for qiskit.providers.backend.Backend.run() method.

  • save_data_while_sampling – If True, the circuit, n_shots and the sampling counts will be saved. Please use the .jobs or .jobs_json to access the saved data.

  • total_time_limit

    The total time limit the jobs submitted by this backend can use.

    • A Tracker is created when the time limit is set. The tracker can be accessed by the .tracker attribute.

    • If the job execution time exceeds the time limit, new call to the sample() will be rejected and all current running jobs will be cancelled.

  • single_job_max_execution_time – Maximum execution time limit of a submitted (circuit, n_shot) pair. The value should be greater or equal to 300 seconds.

  • strict_time_limit – The Runtime backend can only abort jobs that has been executed longer than 300 seconds or above. If this option is set to True, the sampling backend will reject jobs whose time limit setting is less than 300 seconds.

close() None#

Close the IBM session.

This will terminate all unfinished jobs.

sample(circuit: NonParametricQuantumCircuit, n_shots: int) SamplingJob#

Perform a sampling measurement of a circuit.

property jobs: Sequence[QiskitSavedDataSamplingJob]#

Convert saved data to a list of QiskitSavedDataSamplingJob objects.

property jobs_json: str#

Encodes the list of QiskitSavedDataSamplingJob objects to a json string.