utilsยถ

counts_processยถ

Recounting counts.

Post Processing - Utils - Counts Process (qurry.process.utils.ccounts_process)

qurry.process.utils.counts_process.counts_list_recount(counts_list: list[dict[str, int]], num_classical_register: int, selected_classical_registers_sorted: list[int]) list[dict[str, int]][source]ยถ

Calculate the counts under the degree.

Parameters:
  • counts_list (list[dict[str, int]]) โ€“ The list of counts measured from the single quantum circuit.

  • num_classical_register (int) โ€“ The number of classical registers.

  • selected_classical_registers_sorted (list[int]) โ€“ The list of the index of the selected_classical_registers.

Returns:

The counts under the degree.

Return type:

list[dict[str, int]]

qurry.process.utils.counts_process.counts_list_recount_pyrust(counts_list: list[dict[str, int]], num_classical_register: int, selected_classical_registers_sorted: list[int], backend: Literal['Cython', 'Rust', 'Python'] | str = 'Rust') list[dict[str, int]][source]ยถ

Calculate the counts under the degree.

Parameters:
  • counts_list (list[dict[str, int]]) โ€“ The list of counts measured from the single quantum circuit.

  • num_classical_register (int) โ€“ The number of classical registers.

  • selected_classical_registers_sorted (list[int]) โ€“ The list of the index of the selected_classical_registers.

  • backend (PostProcessingBackendLabel, optional) โ€“ Backend for the process. Defaults to โ€œRustโ€.

Returns:

The counts under the degree.

Return type:

list[dict[str, int]]

qurry.process.utils.counts_process.counts_list_vectorize_pyrust(counts_list: list[dict[str, int]], backend: Literal['Cython', 'Rust', 'Python'] | str = 'Rust') list[tuple[list[list[int]], list[int]]][source]ยถ

Vectorized counts.

Parameters:

counts_list (list[dict[str, int]]) โ€“ The list of counts measured from the single quantum circuit.

Returns:

The counts under the degree.

Return type:

list[tuple[list[list[int]], list[int]]]

qurry.process.utils.counts_process.rho_m_flatten_counts_list_vectorize_pyrust(counts_list: list[dict[str, int]], random_unitary_um: dict[int, dict[int, Literal[0, 1, 2] | int]], selected_classical_registers_sorted: list[int], backend: Literal['Cython', 'Rust', 'Python'] | str = 'Rust') list[tuple[list[list[int]], list[int]]][source]ยถ

Dedicated function for rho_m_flatten counts list vectorized.

Parameters:
  • counts_list (list[dict[str, int]]) โ€“ The list of counts measured from the single quantum circuit.

  • random_unitary_um (dict[int, dict[int, Union[Literal[0, 1, 2], int]]]) โ€“ The shadow direction of the unitary operators.

  • selected_classical_registers_sorted (list[int]) โ€“ The list of the index of the selected_classical_registers.

Returns:

The counts under the degree.

Return type:

list[tuple[list[list[int]], list[int]]]

qurry.process.utils.counts_process.shot_counts_selected_clreg_checker_pyrust(shots: int, counts: list[dict[str, int]], selected_classical_registers: int | list[int] | None = None, backend: Literal['Cython', 'Rust', 'Python'] | str = 'Rust') tuple[int, list[int]][source]ยถ

Check whether the selected classical registers are valid.

Parameters:
  • shots (int) โ€“ The number of shots.

  • counts (list[dict[str, int]]) โ€“ The list of the counts.

  • selected_classical_registers (Optional[Union[int, list[int]]], optional) โ€“ The selected classical registers. Defaults to None.

  • backend (PostProcessingBackendLabel, optional) โ€“ Backend for the process. Defaults to โ€œRustโ€.

Returns:

The size of the subsystem and the selected classical registers.

Return type:

tuple[int, list[int]]

qurry.process.utils.counts_process.single_counts_recount(single_counts: dict[str, int], num_classical_register: int, selected_classical_registers_sorted: list[int]) dict[str, int][source]ยถ

Calculate the counts under the degree.

Parameters:
  • single_counts (dict[str, int]) โ€“ Counts measured from the single quantum circuit.

  • num_classical_register (int) โ€“ The number of classical registers.

  • selected_classical_registers_sorted (list[int]) โ€“ The list of the index of the selected_classical_registers.

Returns:

The counts under the degree.

Return type:

dict[str, int]

qurry.process.utils.counts_process.single_counts_recount_pyrust(single_counts: dict[str, int], num_classical_register: int, selected_classical_registers_sorted: list[int], backend: Literal['Cython', 'Rust', 'Python'] | str = 'Rust') dict[str, int][source]ยถ

Calculate the counts under the degree.

Parameters:
  • single_counts (dict[str, int]) โ€“ Counts measured from the single quantum circuit.

  • num_classical_register (int) โ€“ The number of classical registers.

  • selected_classical_registers_sorted (list[int]) โ€“ The list of the index of the selected_classical_registers.

  • backend (PostProcessingBackendLabel, optional) โ€“ Backend for the process. Defaults to โ€œRustโ€.

Returns:

The counts under the degree.

Return type:

dict[str, int]

bit_sliceยถ

bitstring slicing.

Post Processing - Utils - Bit Slice (qurry.process.utils.bit_slice)

qurry.process.utils.bit_slice.cycling_slice(target: list[_ItemT], start: int, end: int, step: int = 1) list[_ItemT][source]ยถ
qurry.process.utils.bit_slice.cycling_slice(target: tuple[_ItemT], start: int, end: int, step: int = 1) tuple[_ItemT]
qurry.process.utils.bit_slice.cycling_slice(target: str, start: int, end: int, step: int = 1) str

Slice a iterable object with cycling.

Parameters:
  • target (_SliceableT) โ€“ The target object.

  • start (int) โ€“ Index of start.

  • end (int) โ€“ Index of end.

  • step (int, optional) โ€“ Step of slice. Defaults to 1.

Raises:

IndexError โ€“ Slice out of range.

Returns:

The sliced object.

Return type:

Iterable

qurry.process.utils.bit_slice.cycling_slice_rust(target: str, start: int, end: int, step: int = 1) str[source]ยถ

Slice a iterable object with cycling.

Parameters:
  • target (str) โ€“ The target object.

  • start (int) โ€“ Index of start.

  • end (int) โ€“ Index of end.

  • step (int, optional) โ€“ Step of slice. Defaults to 1.

Raises:

IndexError โ€“ Slice out of range.

Returns:

The sliced object.

Return type:

str

qurry.process.utils.bit_slice.degree_handler(allsystem_size: int, degree: int | tuple[int, int] | None, measure: tuple[int, int] | None) tuple[tuple[int, int], tuple[int, int], int][source]ยถ

Handle the degree of freedom for the subsystem.

Parameters:
  • allsystem_size (int) โ€“ The size of the whole system.

  • degree (Optional[Union[int, tuple[int, int]]]) โ€“ The degree of freedom.

  • measure (Optional[tuple[int, int]]) โ€“ The measure range.

Returns:

The degree of freedom, measure range, and subsystem size.

Return type:

tuple[tuple[int, int], tuple[int, int], int]

qurry.process.utils.bit_slice.degree_handler_rust(allsystem_size: int, degree: int | tuple[int, int] | None, measure: tuple[int, int] | None) tuple[tuple[int, int], tuple[int, int], int][source]ยถ

Handle the degree of freedom for the subsystem.

Parameters:
  • allsystem_size (int) โ€“ The size of the whole system.

  • degree (Optional[Union[int, tuple[int, int]]]) โ€“ The degree of freedom.

  • measure (Optional[tuple[int, int]]) โ€“ The measure range.

Returns:

The degree of freedom, measure range, and subsystem size.

Return type:

tuple[tuple[int, int], tuple[int, int], int]

qurry.process.utils.bit_slice.is_cycling_slice_active(allsystem_size: int, bitstring_range: tuple[int, int], subsystem_size: int) bool[source]ยถ

Check whether the cycling slice is active.

Parameters:
  • allsystem_size (int) โ€“ The size of the whole system.

  • bitstring_range (tuple[int, int]) โ€“ The range of the bitstring.

  • subsystem_size (int) โ€“ The size of the subsystem

Returns:

Whether the cycling slice is active.

Return type:

bool

qurry.process.utils.bit_slice.qubit_mapper(actual_num_qubits: int, selected_qubits: Sequence[int] | int | tuple[int, int] | None = None) dict[int, int][source]ยถ

Map the index of selected qubits to the index of the classical register.

Parameters:
  • actual_num_qubits (int) โ€“ The actual number of qubits.

  • selected_qubits (Optional[Union[Sequence[int], int, tuple[int, int]]], optional) โ€“ The selected qubits. If it is None, then it will return the mapping of all qubits. If it is int, then it will return the mapping of the last n qubits. If it is tuple, then it will return the mapping of the qubits in the range. If it is list, then it will return the mapping of the selected qubits.

Raises:
  • ValueError โ€“ The range of qubits should be defined by two integers.

  • ValueError โ€“ The selected qubits are beyond the number of qubits.

  • ValueError โ€“ The selected qubits are not natural number.

  • ValueError โ€“ The first integer should be less than the second integer.

  • ValueError โ€“ The number of selected qubits should be more than 1.

  • ValueError โ€“ The selected qubits index are beyond the number of qubits.

  • ValueError โ€“ The selected qubits index are not natural number.

  • ValueError โ€“ Duplicate selected qubits index are not allowed.

  • ValueError โ€“ Invalid input for selected qubits.

Returns:

The mapping of the index of selected qubits to the index of the classical register.

Return type:

dict[int, int]

qurry.process.utils.bit_slice.qubit_mapper_2_int(actual_num_qubits: int, selected_qubits: tuple[int, int]) dict[int, int][source]ยถ

Map the index of selected qubits to the index of the classical register. The selected qubits are defined by two integers.

Parameters:
  • actual_num_qubits (int) โ€“ The actual number of qubits.

  • selected_qubits (tuple[int, int]) โ€“ The range of the selected qubits.

Raises:
  • ValueError โ€“ The range of qubits should be defined by two integers.

  • ValueError โ€“ The selected qubits are beyond the number of qubits.

  • ValueError โ€“ The selected qubits are not natural number.

  • ValueError โ€“ The first integer should be less than the second integer.

Returns:

The mapping of the index of selected qubits to the index of the classical register.

Return type:

dict[int, int]

qurry.process.utils.bit_slice.qubit_selector(num_qubits: int, degree: int | tuple[int, int] | None = None) tuple[int, int][source]ยถ

Determint the qubits to be used.

Parameters:
  • num_qubits (int) โ€“ Number of qubits.

  • degree (Union[int, tuple[int, int], None], optional) โ€“ Degree of freedom or specific subsystem range. Defaults to None then will use number of qubits as degree.

Raises:
  • ValueError โ€“ The specific degree of subsystem qubits beyond number of qubits which the wave function has.

  • ValueError โ€“ The number of qubits of subsystem A is not a natural number.

  • ValueError โ€“ Invalid input for subsystem range defined by only two integers.

  • ValueError โ€“ Degree of freedom is not given.

Returns:

The range of qubits to be used.

Return type:

tuple[int]

qurry.process.utils.bit_slice.qubit_selector_rust(num_qubits: int, degree: int | tuple[int, int] | None = None) tuple[int, int][source]ยถ

Determint the qubits to be used.

Parameters:
  • num_qubits (int) โ€“ Number of qubits.

  • degree (Union[int, tuple[int, int], None], optional) โ€“ Degree of freedom or specific subsystem range. Defaults to None then will use number of qubits as degree.

Raises:
  • ValueError โ€“ The specific degree of subsystem qubits beyond number of qubits which the wave function has.

  • ValueError โ€“ The number of qubits of subsystem A is not a natural number.

  • ValueError โ€“ Invalid input for subsystem range defined by only two integers.

  • ValueError โ€“ Degree of freedom is not given.

Returns:

The range of qubits to be used.

Return type:

tuple[int]

randomizedยถ

Peripheral functions for randomized measurement.

Post Processing - Utils - Randomized (qurry.process.utils.randomized)

qurry.process.utils.randomized.ensemble_cell(s_i: str, s_i_meas: int, s_j: str, s_j_meas: int, a_num: int, shots: int) float64[source]ยถ

Calculate the value of two counts from qubits in ensemble average.

  • about diff = hamming_distance(sAi, sAj):

    It is hamming_distance from qiskit.visualization.count_visualization. Due to frequently update of Qiskit and itโ€™s a simple function, I decide not to use source code instead of calling from qiskit.

Parameters:
  • s_i (str) โ€“ First countโ€™s qubits arrange.

  • s_i_meas (int) โ€“ First count.

  • s_j (str) โ€“ Second countโ€™s qubits arrange.

  • s_j_meas (int) โ€“ Second count.

  • a_num (int) โ€“ Degree of freedom.

  • shots (int) โ€“ Shots of executation.

Returns:

the value of two counts from qubits in ensemble average.

Return type:

float

qurry.process.utils.randomized.ensemble_cell_rust(s_i: str, s_i_meas: int, s_j: str, s_j_meas: int, a_num: int, shots: int) float | float64[source]ยถ

Calculate the value of two counts from qubits in ensemble average by Rust.

Parameters:
  • s_i (str) โ€“ First countโ€™s qubits arrange.

  • s_i_meas (int) โ€“ First count.

  • s_j (str) โ€“ Second countโ€™s qubits arrange.

  • s_j_meas (int) โ€“ Second count.

  • a_num (int) โ€“ Degree of freedom.

  • shots (int) โ€“ Shots of executation.

Returns:

the value of two counts from qubits in ensemble average.

Return type:

float

qurry.process.utils.randomized.hamming_distance(str1: str, str2: str) int[source]ยถ

Calculate the Hamming distance between two bit strings.

Parameters:
  • str1 (str) โ€“ First string.

  • str2 (str) โ€“ Second string.

Returns:

Distance between strings.

Return type:

int

Raises:

ValueError โ€“ Strings not same length.

qurry.process.utils.randomized.hamming_distance_rust(str1: str, str2: str) int[source]ยถ

Calculate the Hamming distance between two bit strings.

Parameters:
  • str1 (str) โ€“ First string.

  • str2 (str) โ€“ Second string.

Returns:

Distance between strings.

Return type:

int

Raises:

VisualizationError โ€“ Strings not same length.

dummyยถ

Dummy case counts generating.

Post Processing - Utils - Toolkits for Dummy Case (qurry.process.utils.dummy)

qurry.process.utils.dummy.makeTwoBitStrOneLiner(bitlen, bits=[''])ยถ

Make a list of bit strings with length of num. But itโ€™s an ONE LINE code.

Parameters:
  • bitlen (int) โ€“ bit string length.

  • bits (list[str], optional) โ€“ The input for recurrsion. Defaults to [โ€˜โ€™].

Returns:

The list of bit strings.

Return type:

list[str]

qurry.process.utils.dummy.make_dummy_case(n_a: int, shot_per_case: int, bitstring_num: int | None = None, backend: Literal['Cython', 'Rust', 'Python'] | str = 'Rust') dict[str, int][source]ยถ

Make a dummy case for the experiment.

Parameters:
  • n_a (int) โ€“ Number of qubits in subsystem A.

  • shot_per_case (int) โ€“ Number of shots per case.

  • bitstring_num (Optional[int]) โ€“ Maximum number of bits.

  • backend (PostProcessingBackendLabel) โ€“ The backend to use.

Returns:

The dummy case.

Return type:

dict[str, int]

qurry.process.utils.dummy.make_two_bit_str(bitlen: int, num: int | None = None, backend: Literal['Cython', 'Rust', 'Python'] | str = 'Rust') list[str][source]ยถ

Make a list of bit strings with length of num.

Parameters:
  • num (int) โ€“ bit string length.

  • backend (PostProcessingBackendLabel) โ€“ The backend to use.

Returns:

The list of bit strings.

Return type:

list[str]

qurry.process.utils.dummy.make_two_bit_str_32_py(bitlen: int, num: int | None = None) list[str][source]ยถ

Make a list of bit strings with length of num.

Parameters:
  • bitlen (int) โ€“ bit string length.

  • num (Optional[int]) โ€“ The number of bit strings.

Returns:

The list of bit strings.

Return type:

list[str]

qurry.process.utils.dummy.make_two_bit_str_unlimit(bitlen: int, backend: Literal['Cython', 'Rust', 'Python'] | str = 'Rust') list[str][source]ยถ

Make a list of bit strings with length of num.

Parameters:
  • bitlen (int) โ€“ bit string length.

  • num (Optional[int]) โ€“ The number of bit strings.

  • backend (PostProcessingBackendLabel) โ€“ The backend to use.

Returns:

The list of bit strings.

Return type:

list[str]

testยถ

Rust binding test function.

Test (qurry.process.utils.test)

qurry.process.utils.test.test_bit_slice()[source]ยถ

Test the construct module.

otherยถ

Remains are not ditributed.

Post Processing - Utils - Other (qurry.process.utils.other)

qurry.process.utils.other.NUMERICAL_ERROR_TOLERANCE = 1e-14ยถ

Tolerance for numerical errors in calculations. This is used to determine if two floating-point numbers are close enough to be considered equal.

The default value is set to 1e-14.