quri_parts.qiskit.backend.saved_sampling module#

class quri_parts.qiskit.backend.saved_sampling.QiskitSavedDataSamplingResult(raw_data: dict[str, int])#

Bases: SamplingResult

An object that holds a sampling count from qiskit backend output and converts it into quri-parts sampling count.

The raw_data should take in the output of qiskit_result.get_counts(), which is a counter that uses str as its key.

raw_data: dict[str, int]#
property counts: Mapping[int, float | int]#

Convert the raw data to quri-parts sampling count.

The quri-parts sampling count is a counter that uses int as its key.

class quri_parts.qiskit.backend.saved_sampling.QiskitRuntimeSavedDataSamplingResult(quasi_dist: dict[int, float], n_shots: int)#

Bases: SamplingResult

An object that holds quasi disttribution and total shot count from qiskit runtime output and converts it into quri-parts sampling count.

  • quasi_dist – The first element of the quasi_dists attribute of a qiskit.primitives.SamplerResult object.

  • n_shots – The metadata[0][“shots”] output of a qiskit.primitives.SamplerResult object.

quasi_dist: dict[int, float]#
n_shots: int#
property counts: Mapping[int, float | int]#

Measurement counts obtained by a sampling measurement.

class quri_parts.qiskit.backend.saved_sampling.QiskitSavedDataSamplingJob(circuit_qasm: str, n_shots: int, saved_result: QiskitSavedDataSamplingResult | QiskitRuntimeSavedDataSamplingResult)#

Bases: SamplingJob

An object that represents a saved sampling job.

  • circuit_qasm – A string that represents the circuit used in a sampling job. Note that it should take in the qasm string of a qiskit quantum circuit. It can be accessed by qiskit_circuit.qasm().

  • n_shots – The total shots of a sampling job.

  • saved_result – A QiskitSavedDataSamplingResult instance that represents the result when (circuit_str, n_shots) is passed into the sampler.

circuit_qasm: str#
n_shots: int#
saved_result: QiskitSavedDataSamplingResult | QiskitRuntimeSavedDataSamplingResult#
result() QiskitSavedDataSamplingResult | QiskitRuntimeSavedDataSamplingResult#

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.saved_sampling.QiskitSavedDataSamplingBackend(backend: ~qiskit.providers.backend.Backend, saved_data: str, 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: ~typing.Mapping[int, int] | None = None, run_kwargs: ~typing.Mapping[str, ~typing.Any] = {})#

Bases: SamplingBackend

A Qiskit backend for replaying saved sampling experiments. When a sampler is created with a QiskitSavedDataSamplingBackend object, the sequence of (circuit, n_shots) pairs should be passed in to the sampler the same order as the orginal experiment.


  1. Sampling experiment

1-a: Sampling mode with data saving

>>> backend_device = AerSimulator()
>>> sampling_backend = QiskitSamplingBackend(
...     backend_device, save_data_while_sampling=True
... )
>>> sampler = create_sampler_from_sampling_backend(sampling_backend)

1-b: Perform sampling experiments

>>> sampling_count_1 = sampler(circuit_1, n_shots_1)
>>> sampling_count_2 = sampler(circuit_2, n_shots_2)
>>> sampling_count_3 = sampler(circuit_3, n_shots_3)

1-c: Dump sampling data

>>> experiment_json_str = sampling_backend.jobs_json()
  1. Replay sampling experiment

2-a: Create sampling backend and sampler with saved data.

>>> saved_data_sampling_backend = QiskitSavedDataSamplingBackend(
...     backend = backend_device,
...     saved_data = experiment_json_str
... )
>>> saved_data_sampler = create_sampler_from_sampling_backend(
...    saved_data_sampling_backend
... )

2-b: Replay sampling experiment.

(circuit, n_shots) pairs are passed in to the saved_data_sampler the same order as they were passed in to the sampler.

>>> replayed_sampling_count_1 = sampler(circuit_1, n_shots_1)
>>> replayed_sampling_count_2 = sampler(circuit_2, n_shots_2)
>>> replayed_sampling_count_3 = sampler(circuit_3, n_shots_3)
  • backend – A Qiskit qiskit.providers.backend.Backend for circuit execution.

  • saved_data – A json string output by the .json_str property of :class:`~quri_parts.qiskit.backend.QiskitSamplingBackend.

  • 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}.

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

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

Perform a sampling measurement of a circuit.

quri_parts.qiskit.backend.saved_sampling.decode_json_to_saved_data_sequence(json_str: str) Sequence[QiskitSavedDataSamplingJob]#
quri_parts.qiskit.backend.saved_sampling.encode_saved_data_job_sequence_to_json(saved_data_seq: Sequence[QiskitSavedDataSamplingJob]) str#