random_unitaryΒΆ

ToolKits for Random Unitary Operator (qurry.qurrium.utils.random_unitary)

qurry.qurrium.utils.random_unitary.check_and_generate_for_single_circ(seed_for_single_circ: int | Generator | Sequence[int | Generator] | dict[int, int | Generator] | None, num_qubits: int) dict[int, int][source]ΒΆ

Check the input of generate_random_unitary_seeds.

Parameters:
  • seed_for_single_circ (Optional[Union[SeedType, Sequence[SeedType], dict[int, SeedType]]]) – The seed for single circuit.

  • num_qubits (int) – The number of qubits.

Raises:
  • TypeError – If the seed is not int, np.random.Generator, Sequence, or dict.

  • ValueError – If the seed for one qubit is not found. If the seed is not int or np.random.Generator. If the length of seed is not equal to num_qubits.

Returns:

The seed for single circuit.

Return type:

dict[int, int]

qurry.qurrium.utils.random_unitary.check_input_for_experiment(times: int, num_qubits: int, random_unitary_seeds: dict[int, dict[int, int]] | None) None[source]ΒΆ

Check the input of the experiment. If you want to generate the seeds for all random unitary operator, you can use the function generate_random_unitary_seeds in qurry.qurrium.utils.random_unitary.

Parameters:
  • times (int) – The number of random unitary operator.

  • num_qubits (int) – The number of qubits.

  • random_unitary_seeds (Optional[dict[int, dict[int, int]]]) – The seeds for all random unitary operator. This argument only takes input as type of dict[int, dict[int, int]]. The first key is the index for the random unitary operator. The second key is the index for the qubit.

Raises:
  • TypeError – If the random_unitary_seeds is not dict.

  • ValueError – If the length of random_unitary_seeds is not equal to times.

  • TypeError – If the random_unitary_seeds[i] is not dict.

  • ValueError – If the length of random_unitary_seeds[i] is not equal to num_qubits.

  • TypeError – If the random_unitary_seeds[i][j] is not int.

qurry.qurrium.utils.random_unitary.generate_random_unitary_seeds(times: int, num_qubits: int, seed: int | Generator | Sequence[int | Generator | Sequence[int | Generator] | dict[int, int | Generator]] | dict[int, int | Generator | Sequence[int | Generator] | dict[int, int | Generator]] | None = None) dict[int, dict[int, int]][source]ΒΆ

Generate random unitary seeds.

Parameters:
  • times (int) – The number of random unitary operator.

  • num_qubits (int) – The number of qubits.

  • (Union[ (seed) –

    int, np.random.Generator, Sequence[Union[

    int, np.random.Generator, Sequence[Union[int, np.random.Generator]], dict[int, Union[int, np.random.Generator]]

    ]], dict[int, Union[

    int, np.random.Generator, Sequence[Union[int, np.random.Generator]], dict[int, Union[int, np.random.Generator]]

    ]]

  • ] – The seed of random generator.

  • optional) – The seed of random generator.

Raises:
  • TypeError – If the seed is not int, np.random.Generator, Sequence, or dict.

  • ValueError – If the length of seed is not equal to times.

Returns:

The random unitary seeds.

Return type:

dict[int, dict[int, int]]]

qurry.qurrium.utils.random_unitary.generate_seeds_for_single_circ(seed_for_single_circ: int | Generator | None, num_qubits: int) dict[int, int][source]ΒΆ

Generate the seed for single circuit.

Parameters:
  • seed_for_single_circ (Optional[SeedType]) – The seed for single circuit.

  • num_qubits (int) – The number of qubits.

Raises:

ValueError – If the seed is not int, np.random.Generator

Returns:

The seed for single circuit.

Return type:

dict[int, int]