QuantumScoreDiffusion

Struct QuantumScoreDiffusion 

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

Quantum Score-Based Diffusion

Implementations§

Source§

impl QuantumScoreDiffusion

Source

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

Create new score-based diffusion model

Examples found in repository?
examples/quantum_diffusion.rs (lines 170-174)
168fn score_diffusion_demo() -> Result<()> {
169    // Create score-based model
170    let model = QuantumScoreDiffusion::new(
171        2,  // data dimension
172        4,  // num qubits
173        10, // noise levels
174    )?;
175
176    println!("   Created quantum score-based diffusion model");
177    println!("   - Noise levels: {:?}", model.noise_levels());
178
179    // Test score estimation
180    let x = Array1::from_vec(vec![0.5, -0.3]);
181    let noise_level = 0.1;
182
183    let score = model.estimate_score(&x, noise_level)?;
184    println!("\n   Score estimation:");
185    println!("   - Input: [{:.3}, {:.3}]", x[0], x[1]);
186    println!("   - Noise level: {:.3}", noise_level);
187    println!("   - Estimated score: [{:.3}, {:.3}]", score[0], score[1]);
188
189    // Langevin sampling
190    println!("\n   Langevin sampling:");
191    let init = Array1::from_vec(vec![2.0, 2.0]);
192    let num_steps = 100;
193    let step_size = 0.01;
194
195    let sample = model.langevin_sample(init.clone(), noise_level, num_steps, step_size)?;
196
197    println!("   - Initial: [{:.3}, {:.3}]", init[0], init[1]);
198    println!(
199        "   - After {} steps: [{:.3}, {:.3}]",
200        num_steps, sample[0], sample[1]
201    );
202    println!(
203        "   - Distance moved: {:.3}",
204        ((sample[0] - init[0]).powi(2) + (sample[1] - init[1]).powi(2)).sqrt()
205    );
206
207    Ok(())
208}
Source

pub fn estimate_score( &self, x: &Array1<f64>, noise_level: f64, ) -> Result<Array1<f64>>

Estimate score (gradient of log density)

Examples found in repository?
examples/quantum_diffusion.rs (line 183)
168fn score_diffusion_demo() -> Result<()> {
169    // Create score-based model
170    let model = QuantumScoreDiffusion::new(
171        2,  // data dimension
172        4,  // num qubits
173        10, // noise levels
174    )?;
175
176    println!("   Created quantum score-based diffusion model");
177    println!("   - Noise levels: {:?}", model.noise_levels());
178
179    // Test score estimation
180    let x = Array1::from_vec(vec![0.5, -0.3]);
181    let noise_level = 0.1;
182
183    let score = model.estimate_score(&x, noise_level)?;
184    println!("\n   Score estimation:");
185    println!("   - Input: [{:.3}, {:.3}]", x[0], x[1]);
186    println!("   - Noise level: {:.3}", noise_level);
187    println!("   - Estimated score: [{:.3}, {:.3}]", score[0], score[1]);
188
189    // Langevin sampling
190    println!("\n   Langevin sampling:");
191    let init = Array1::from_vec(vec![2.0, 2.0]);
192    let num_steps = 100;
193    let step_size = 0.01;
194
195    let sample = model.langevin_sample(init.clone(), noise_level, num_steps, step_size)?;
196
197    println!("   - Initial: [{:.3}, {:.3}]", init[0], init[1]);
198    println!(
199        "   - After {} steps: [{:.3}, {:.3}]",
200        num_steps, sample[0], sample[1]
201    );
202    println!(
203        "   - Distance moved: {:.3}",
204        ((sample[0] - init[0]).powi(2) + (sample[1] - init[1]).powi(2)).sqrt()
205    );
206
207    Ok(())
208}
Source

pub fn langevin_sample( &self, init: Array1<f64>, noise_level: f64, num_steps: usize, step_size: f64, ) -> Result<Array1<f64>>

Langevin dynamics sampling

Examples found in repository?
examples/quantum_diffusion.rs (line 195)
168fn score_diffusion_demo() -> Result<()> {
169    // Create score-based model
170    let model = QuantumScoreDiffusion::new(
171        2,  // data dimension
172        4,  // num qubits
173        10, // noise levels
174    )?;
175
176    println!("   Created quantum score-based diffusion model");
177    println!("   - Noise levels: {:?}", model.noise_levels());
178
179    // Test score estimation
180    let x = Array1::from_vec(vec![0.5, -0.3]);
181    let noise_level = 0.1;
182
183    let score = model.estimate_score(&x, noise_level)?;
184    println!("\n   Score estimation:");
185    println!("   - Input: [{:.3}, {:.3}]", x[0], x[1]);
186    println!("   - Noise level: {:.3}", noise_level);
187    println!("   - Estimated score: [{:.3}, {:.3}]", score[0], score[1]);
188
189    // Langevin sampling
190    println!("\n   Langevin sampling:");
191    let init = Array1::from_vec(vec![2.0, 2.0]);
192    let num_steps = 100;
193    let step_size = 0.01;
194
195    let sample = model.langevin_sample(init.clone(), noise_level, num_steps, step_size)?;
196
197    println!("   - Initial: [{:.3}, {:.3}]", init[0], init[1]);
198    println!(
199        "   - After {} steps: [{:.3}, {:.3}]",
200        num_steps, sample[0], sample[1]
201    );
202    println!(
203        "   - Distance moved: {:.3}",
204        ((sample[0] - init[0]).powi(2) + (sample[1] - init[1]).powi(2)).sqrt()
205    );
206
207    Ok(())
208}
Source

pub fn noise_levels(&self) -> &Array1<f64>

Get noise levels

Examples found in repository?
examples/quantum_diffusion.rs (line 177)
168fn score_diffusion_demo() -> Result<()> {
169    // Create score-based model
170    let model = QuantumScoreDiffusion::new(
171        2,  // data dimension
172        4,  // num qubits
173        10, // noise levels
174    )?;
175
176    println!("   Created quantum score-based diffusion model");
177    println!("   - Noise levels: {:?}", model.noise_levels());
178
179    // Test score estimation
180    let x = Array1::from_vec(vec![0.5, -0.3]);
181    let noise_level = 0.1;
182
183    let score = model.estimate_score(&x, noise_level)?;
184    println!("\n   Score estimation:");
185    println!("   - Input: [{:.3}, {:.3}]", x[0], x[1]);
186    println!("   - Noise level: {:.3}", noise_level);
187    println!("   - Estimated score: [{:.3}, {:.3}]", score[0], score[1]);
188
189    // Langevin sampling
190    println!("\n   Langevin sampling:");
191    let init = Array1::from_vec(vec![2.0, 2.0]);
192    let num_steps = 100;
193    let step_size = 0.01;
194
195    let sample = model.langevin_sample(init.clone(), noise_level, num_steps, step_size)?;
196
197    println!("   - Initial: [{:.3}, {:.3}]", init[0], init[1]);
198    println!(
199        "   - After {} steps: [{:.3}, {:.3}]",
200        num_steps, sample[0], sample[1]
201    );
202    println!(
203        "   - Distance moved: {:.3}",
204        ((sample[0] - init[0]).powi(2) + (sample[1] - init[1]).powi(2)).sqrt()
205    );
206
207    Ok(())
208}

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> 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> Ungil for T
where T: Send,