pub struct Register<const N: usize> { /* private fields */ }Expand description
A quantum register that holds the state of N qubits
Implementations§
Source§impl<const N: usize> Register<N>
impl<const N: usize> Register<N>
Sourcepub fn with_amplitudes(amplitudes: Vec<Complex64>) -> QuantRS2Result<Self>
pub fn with_amplitudes(amplitudes: Vec<Complex64>) -> QuantRS2Result<Self>
Create a register with custom initial amplitudes
§Errors
Returns an error if the provided amplitudes vector doesn’t have the correct dimension (2^N) or if the vector isn’t properly normalized.
Sourcepub const fn num_qubits(&self) -> usize
pub const fn num_qubits(&self) -> usize
Get the number of qubits in this register
Sourcepub fn amplitudes(&self) -> &[Complex64] ⓘ
pub fn amplitudes(&self) -> &[Complex64] ⓘ
Get access to the raw amplitudes vector
Sourcepub fn amplitudes_mut(&mut self) -> &mut [Complex64] ⓘ
pub fn amplitudes_mut(&mut self) -> &mut [Complex64] ⓘ
Get mutable access to the raw amplitudes vector
Sourcepub fn amplitude(&self, bits: &[u8]) -> QuantRS2Result<Complex64>
pub fn amplitude(&self, bits: &[u8]) -> QuantRS2Result<Complex64>
Get the amplitude for a specific basis state
The bits parameter must be a slice of length N, where each element is either 0 or 1 representing the computational basis state.
§Errors
Returns an error if the bits slice has incorrect length or contains values other than 0 or 1.
Sourcepub fn probability(&self, bits: &[u8]) -> QuantRS2Result<f64>
pub fn probability(&self, bits: &[u8]) -> QuantRS2Result<f64>
Calculate the probability of measuring a specific basis state
The bits parameter must be a slice of length N, where each element is either 0 or 1 representing the computational basis state.
§Errors
Returns an error if the bits slice has incorrect length or contains values other than 0 or 1.
Sourcepub fn probabilities(&self) -> Vec<f64>
pub fn probabilities(&self) -> Vec<f64>
Calculate the probabilities of measuring each basis state
Sourcepub fn expectation_z(&self, qubit: impl Into<QubitId>) -> QuantRS2Result<f64>
pub fn expectation_z(&self, qubit: impl Into<QubitId>) -> QuantRS2Result<f64>
Calculate the expectation value of a single-qubit Pauli operator