quri_parts.qiskit.backend.utils module#

distribute_backend_shots(n_shots, min_shots, max_shots, enable_shots_roundup=True)#

Distributes the n_shots into batches of smaller shot numbers according to the max_shots value.

Parameters:
  • n_shots (int) – Total number of shots.

  • min_shots (int) – Minimal number of shots of a single batch.

  • max_shots (int | None) – Maximal number of shots of a single batch.

  • enable_shots_roundup (bool | None) – If True, when a number of shots of a batch is smaller than min_shots, 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.

Return type:

Sequence[int]

get_backend_min_max_shot(backend)#

Get the selected qiskit backend’s minimum and maximum shot number allowed in a single sampling job.

Parameters:

backend (Backend) –

Return type:

tuple[int, int | None]

get_job_mapper_and_circuit_transpiler(qubit_mapping=None, circuit_transpiler=None)#
Creates
  1. A job mapper that maps the qubits of raw sampling job from the backend to

    a SamplingJob according to the specified qubit_mapping.

  2. A circuit transpiler.

Parameters:
  • qubit_mapping (Mapping[int, int] | None) – 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}.

  • circuit_transpiler (circuit.transpile.transpiler.CircuitTranspiler | None) – A transpiler applied to the circuit before running it. QiskitSetTranspiler is used when not specified.

Return type:

tuple[Callable[[SamplingJob], SamplingJob], circuit.transpile.transpiler.CircuitTranspiler]

convert_qiskit_sampling_count_to_qp_sampling_count(qiskit_counts)#

Converts the raw counter returned from qiskit backends to quri-parts couter.

Note that the qiskit counter uses a string that represents a binary number as the key.

Parameters:

qiskit_counts (Mapping[str, int]) –

Return type:

backend.SamplingCounts