graphix.random_objects module¶
Functions to generate various random objects.
- rand_outcome(rng: Generator | None = None, *, stacklevel: int = 1) Outcome[source]¶
Generate random measurement outcome (0 or 1).
- rand_herm(sz: IntLike, rng: Generator | None = None, *, stacklevel: int = 1) npt.NDArray[np.complex128][source]¶
Generate random hermitian matrix of size sz*sz.
- rand_unit(sz: IntLike, rng: Generator | None = None, *, stacklevel: int = 1) npt.NDArray[np.complex128][source]¶
Generate haar random unitary matrix of size sz*sz.
- rand_dm(dim: IntLike, rng: Generator | None = None, rank: IntLike | None = None, *, stacklevel: int = 1) npt.NDArray[np.complex128][source]¶
Generate random density matrices (positive semi-definite matrices with unit trace).
Returns either a
graphix.sim.density_matrix.DensityMatrixor anp.ndarraydepending on the parameter dm_dtype.- Parameters:
- Returns:
the density matrix in the specified format.
- Return type:
DensityMatrix | np.ndarray
Note
Thanks to Ulysse Chabaud.
- rand_gauss_cpx_mat(dim: IntLike, rng: Generator | None = None, sig: _SIG = None, *, stacklevel: int = 1) 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
- rand_channel_kraus(dim: int, rng: Generator | None = None, rank: int | None = None, sig: _SIG = None, *, stacklevel: int = 1) KrausChannel[source]¶
Return a random
graphix.sim.channels.KrausChannelobject 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)
- rand_pauli_channel_kraus(dim: int, rng: Generator | None = None, rank: int | None = None, *, stacklevel: int = 1) KrausChannel[source]¶
Return a random Kraus channel operator.
- rand_gate(nqubits: int, depth: int, pairs: Iterable[tuple[int, int]], rng: Generator | None = None, *, use_rzz: bool = False, stacklevel: int = 1) 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
Trueuse \(R_{ZZ}\) gates as entanglers instead of CNOT.
- Returns:
The generated random circuit.
- Return type:
- rand_circuit(nqubits: int, depth: int, rng: Generator | None = None, *, use_j: bool = True, use_cz: bool = True, use_rzz: bool = False, use_ccx: bool = False, parameters: Iterable[Parameter] | None = None, stacklevel: int = 1) 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_j (bool, optional) – If
Trueadd J gates in each layer (default:False).use_cz (bool, optional) – If
Trueadd CZ gates in each layer (default:True).use_rzz (bool, optional) – If
Trueadd \(R_{ZZ}\) gates in each layer (default:False).use_ccx (bool, optional) – If
Trueadd CCX gates in each layer (default:False).parameters (Iterable[Parameter], optional) – Parameters used for randomly chosen rotation gates.
- Returns:
The generated random circuit.
- Return type:
- rand_state_vector(nqubits: int, rng: Generator | None = None, *, stacklevel: int = 1) npt.NDArray[np.complex128][source]¶
Generate a random normalized complex state vector of size 2^n.
- Parameters:
nqubits (int) – The power of 2 for the vector size
- Returns:
Normalized complex vector of size 2^nqubits
- Return type: