Skip to main content

QftFile

Struct QftFile 

Source
pub struct QftFile { /* private fields */ }
Expand description

A quantum state file in .qft format

Implementations§

Source§

impl QftFile

Source

pub async fn load_async(path: impl AsRef<Path>) -> Result<Self>

Available on crate feature async only.

Asynchronously load a QFT file.

Source

pub async fn save_async(&self, path: impl AsRef<Path>) -> Result<()>

Available on crate feature async only.

Asynchronously save a QFT file.

Source§

impl QftFile

Source

pub fn new(num_qubits: usize) -> Result<Self>

Create a new QFT file with the specified number of qubits. Initializes to the |0…0⟩ state.

§Arguments
  • num_qubits - Number of qubits (1-30)
§Example
use qft::QftFile;
let state = QftFile::new(4).unwrap();
assert_eq!(state.num_qubits(), 4);
assert_eq!(state.dimension(), 16);
Source

pub fn with_config(num_qubits: usize, config: QftConfig) -> Result<Self>

Create a QFT file with custom configuration.

Source

pub fn from_amplitudes(amplitudes: Vec<Complex64>) -> Result<Self>

Create from a vector of complex amplitudes.

§Example
use qft::QftFile;
use num_complex::Complex64;

let sqrt2_inv = 1.0 / 2.0_f64.sqrt();
let amplitudes = vec![
    Complex64::new(sqrt2_inv, 0.0),
    Complex64::new(0.0, 0.0),
    Complex64::new(0.0, 0.0),
    Complex64::new(sqrt2_inv, 0.0),
];
let bell = QftFile::from_amplitudes(amplitudes).unwrap();
assert_eq!(bell.num_qubits(), 2);
Source

pub fn from_real_imag(real: &[f64], imag: &[f64]) -> Result<Self>

Create from separate real and imaginary arrays.

Source

pub fn num_qubits(&self) -> usize

Get the number of qubits.

Source

pub fn dimension(&self) -> usize

Get the state vector dimension (2^num_qubits).

Source

pub fn config(&self) -> &QftConfig

Get the configuration.

Source

pub fn config_mut(&mut self) -> &mut QftConfig

Get mutable reference to configuration.

Source

pub fn amplitudes(&self) -> &[Complex64]

Get all amplitudes as a slice.

Source

pub fn amplitudes_mut(&mut self) -> &mut [Complex64]

Get mutable access to amplitudes.

Source

pub fn get_amplitude(&self, index: usize) -> Result<Complex64>

Get a single amplitude by basis state index.

Source

pub fn set_amplitude(&mut self, index: usize, value: Complex64) -> Result<()>

Set a single amplitude by basis state index.

Source

pub fn set_amplitudes(&mut self, amplitudes: &[Complex64]) -> Result<()>

Set all amplitudes from a slice.

Source

pub fn set_metadata(&mut self, key: impl Into<String>, value: impl Into<String>)

Set a metadata key-value pair.

Source

pub fn get_metadata(&self, key: &str) -> Option<&str>

Get a metadata value by key.

Source

pub fn metadata(&self) -> &HashMap<String, String>

Get all metadata.

Source

pub fn metadata_mut(&mut self) -> &mut HashMap<String, String>

Get mutable access to metadata.

Source

pub fn norm_squared(&self) -> f64

Calculate the norm squared (sum of |amplitude|²).

Source

pub fn norm(&self) -> f64

Calculate the norm.

Source

pub fn is_normalized(&self, tolerance: f64) -> bool

Check if the state is normalized within tolerance.

Source

pub fn normalize(&mut self) -> Result<()>

Normalize the state vector in place.

Source

pub fn inner_product(&self, other: &QftFile) -> Result<Complex64>

Calculate the inner product ⟨self|other⟩.

Source

pub fn fidelity(&self, other: &QftFile) -> Result<f64>

Calculate the fidelity |⟨self|other⟩|².

Source

pub fn trace_distance(&self, other: &QftFile) -> Result<f64>

Calculate the trace distance to another state.

Source

pub fn load(path: impl AsRef<Path>) -> Result<Self>

Load a QFT file from disk.

§Example
use qft::QftFile;
let state = QftFile::load("state.qft").unwrap();
Source

pub fn save(&self, path: impl AsRef<Path>) -> Result<()>

Save the QFT file to disk.

§Example
use qft::QftFile;
let state = QftFile::new(4).unwrap();
state.save("state.qft").unwrap();
Source

pub fn read_from<R: Read>(reader: &mut R) -> Result<Self>

Read from any reader.

Source

pub fn write_to<W: Write>(&self, writer: &mut W) -> Result<()>

Write to any writer.

Source

pub fn to_bytes(&self) -> Result<Vec<u8>>

Serialize to bytes.

Source

pub fn from_bytes(data: &[u8]) -> Result<Self>

Deserialize from bytes.

Source

pub fn to_json(&self) -> Result<String>

Export to JSON.

Source

pub fn from_json(json: &str) -> Result<Self>

Import from JSON.

Trait Implementations§

Source§

impl Clone for QftFile

Source§

fn clone(&self) -> QftFile

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for QftFile

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for QftFile

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Index<usize> for QftFile

Source§

type Output = Complex<f64>

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl IndexMut<usize> for QftFile

Source§

fn index_mut(&mut self, index: usize) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<'a> IntoIterator for &'a QftFile

Source§

type Item = &'a Complex<f64>

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, Complex<f64>>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl IntoIterator for QftFile

Source§

type Item = Complex<f64>

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<Complex<f64>>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.