Random objects

graphix.random_objects module

This module provides functions to generate various random objects.

graphix.random_objects.rand_herm(sz: int, rng: Generator | None = None) npt.NDArray[np.complex128][source]

Generate random hermitian matrix of size sz*sz.

graphix.random_objects.rand_unit(sz: int, rng: Generator | None = None) npt.NDArray[np.complex128][source]

Generate haar random unitary matrix of size sz*sz.

graphix.random_objects.rand_dm(dim: int, rng: Generator | None = None, rank: int | None = None) npt.NDArray[np.complex128][source]

Generate random density matrices (positive semi-definite matrices with unit trace).

Returns either a graphix.sim.density_matrix.DensityMatrix or a np.ndarray depending on the parameter dm_dtype.

Parameters:
  • dim (int) – Linear dimension of the (square) matrix

  • rank (int, optional) – Rank of the density matrix (1 = pure state). If not specified then sent to dim (maximal rank). Defaults to None

Returns:

the density matrix in the specified format.

Return type:

DensityMatrix | np.ndarray

Note

Thanks to Ulysse Chabaud.

graphix.random_objects.rand_gauss_cpx_mat(dim: int, rng: Generator | None = None, sig: float = np.float64(0.7071067811865475)) npt.NDArray[np.complex128][source]

Return a square array of standard normal complex random variates.

Code from QuTiP: https://qutip.org/docs/4.0.2/modules/qutip/random_objects.html

Parameters:
  • dim (int) – Linear dimension of the (square) matrix

  • sig (float) – standard deviation of random variates. sig = 'ginibre draws from the Ginibre ensemble ie sig = 1 / sqrt(2 * dim).

graphix.random_objects.rand_channel_kraus(dim: int, rng: Generator | None = None, rank: int | None = None, sig: float = np.float64(0.7071067811865475)) KrausChannel[source]

Return a random graphix.sim.channels.KrausChannel object of given dimension and rank.

Following the method of [KNPPZ21] Kukulski, Nechita, Pawela, Puchała, Życzkowsk https://arxiv.org/pdf/2011.02994.pdf

Parameters:
  • dim (int) – Linear dimension of the (square) matrix of each Kraus operator. Only square operators so far.

  • rank (int (default to full rank dimension**2)) – Choi rank ie the number of Kraus operators. Must be between one and dim**2.

  • sig (see rand_cpx)

graphix.random_objects.rand_pauli_channel_kraus(dim: int, rng: Generator | None = None, rank: int | None = None) KrausChannel[source]

Return a random Kraus channel operator.

graphix.random_objects.rand_gate(nqubits: int, depth: int, pairs: Iterable[tuple[int, int]], rng: Generator | None = None, *, use_rzz: bool = False) Circuit[source]

Return a random gate composed of single-qubit rotations and entangling operations.

Parameters:
  • nqubits (int) – Number of qubits in the circuit.

  • depth (int) – Depth of alternating rotation and entangling layers.

  • pairs (Iterable[tuple[int, int]]) – Pairs of qubits used for entangling operations.

  • rng (numpy.random.Generator, optional) – Random number generator used to sample rotation angles. If None, a default generator is created.

  • use_rzz (bool, optional) – If True use \(R_{ZZ}\) gates as entanglers instead of CNOT.

Returns:

The generated random circuit.

Return type:

Circuit

graphix.random_objects.rand_circuit(nqubits: int, depth: int, rng: Generator | None = None, *, use_rzz: bool = False, use_ccx: bool = False, parameters: Iterable[Parameter] | None = None) Circuit[source]

Return a random parameterized circuit used for testing or benchmarking.

Parameters:
  • nqubits (int) – Number of qubits in the circuit.

  • depth (int) – Number of alternating entangling and single-qubit layers.

  • rng (numpy.random.Generator, optional) – Random number generator. A default generator is created if None.

  • use_rzz (bool, optional) – If True add \(R_{ZZ}\) gates in each layer.

  • use_ccx (bool, optional) – If True add CCX gates in each layer.

  • parameters (Iterable[Parameter], optional) – Parameters used for randomly chosen rotation gates.

Returns:

The generated random circuit.

Return type:

Circuit