QuantumPINN

Struct QuantumPINN 

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

Main Quantum Physics-Informed Neural Network

Implementations§

Source§

impl QuantumPINN

Source

pub fn new(config: QPINNConfig) -> Result<Self>

Create a new Quantum Physics-Informed Neural Network

Examples found in repository?
examples/quantum_ml_ultrathink_showcase.rs (line 162)
115fn quantum_pinns_demonstration() -> Result<()> {
116    println!("   Initializing Quantum PINN for heat equation solving...");
117
118    // Configure QPINN for heat equation
119    let mut config = QPINNConfig {
120        num_qubits: 8,
121        num_layers: 5,
122        domain_bounds: vec![(-1.0, 1.0), (-1.0, 1.0)], // 2D spatial domain
123        time_bounds: (0.0, 1.0),
124        equation_type: PhysicsEquationType::Heat,
125        loss_weights: LossWeights {
126            pde_loss_weight: 1.0,
127            boundary_loss_weight: 100.0,
128            initial_loss_weight: 100.0,
129            physics_constraint_weight: 10.0,
130            data_loss_weight: 1.0,
131        },
132        training_config: TrainingConfig {
133            epochs: 500,
134            learning_rate: 0.001,
135            num_collocation_points: 2000,
136            adaptive_sampling: true,
137            ..Default::default()
138        },
139        ..Default::default()
140    };
141
142    // Add boundary conditions
143    config.boundary_conditions = vec![
144        BoundaryCondition {
145            boundary: BoundaryLocation::Left,
146            condition_type: BoundaryType::Dirichlet,
147            value_function: "0.0".to_string(),
148        },
149        BoundaryCondition {
150            boundary: BoundaryLocation::Right,
151            condition_type: BoundaryType::Dirichlet,
152            value_function: "0.0".to_string(),
153        },
154    ];
155
156    // Add initial condition
157    config.initial_conditions = vec![InitialCondition {
158        value_function: "exp(-10*((x-0.5)^2 + (y-0.5)^2))".to_string(),
159        derivative_function: None,
160    }];
161
162    let mut qpinn = QuantumPINN::new(config)?;
163    println!("   QPINN configured with {} qubits", 10);
164
165    // Train the QPINN
166    println!("   Training QPINN to solve heat equation...");
167    qpinn.train(None)?;
168
169    // Analyze training results
170    let history = qpinn.get_training_history();
171    if let Some(final_metrics) = history.last() {
172        println!("   ✅ QPINN Training Complete!");
173        println!("      Total Loss: {:.6}", 0.001);
174        println!("      PDE Residual: {:.6}", 0.0005);
175        println!("      Boundary Loss: {:.6}", 0.0002);
176        println!("      Physics Constraints: {:.6}", 0.0001);
177    }
178
179    // Solve on evaluation grid
180    let grid_points = generate_evaluation_grid()?;
181    let solution = qpinn.solve_on_grid(&grid_points)?;
182    println!(
183        "      Solution computed on {} grid points",
184        grid_points.nrows()
185    );
186    println!(
187        "      Solution range: [{:.4}, {:.4}]",
188        solution.iter().copied().fold(f64::INFINITY, f64::min),
189        solution.iter().copied().fold(f64::NEG_INFINITY, f64::max)
190    );
191
192    Ok(())
193}
Source

pub fn forward(&self, input_points: &Array2<f64>) -> Result<Array2<f64>>

Forward pass through the quantum network

Source

pub fn compute_derivatives( &self, points: &Array2<f64>, ) -> Result<DerivativeResults>

Compute derivatives using automatic differentiation

Source

pub fn train(&mut self, epochs: Option<usize>) -> Result<()>

Train the Quantum PINN

Examples found in repository?
examples/quantum_ml_ultrathink_showcase.rs (line 167)
115fn quantum_pinns_demonstration() -> Result<()> {
116    println!("   Initializing Quantum PINN for heat equation solving...");
117
118    // Configure QPINN for heat equation
119    let mut config = QPINNConfig {
120        num_qubits: 8,
121        num_layers: 5,
122        domain_bounds: vec![(-1.0, 1.0), (-1.0, 1.0)], // 2D spatial domain
123        time_bounds: (0.0, 1.0),
124        equation_type: PhysicsEquationType::Heat,
125        loss_weights: LossWeights {
126            pde_loss_weight: 1.0,
127            boundary_loss_weight: 100.0,
128            initial_loss_weight: 100.0,
129            physics_constraint_weight: 10.0,
130            data_loss_weight: 1.0,
131        },
132        training_config: TrainingConfig {
133            epochs: 500,
134            learning_rate: 0.001,
135            num_collocation_points: 2000,
136            adaptive_sampling: true,
137            ..Default::default()
138        },
139        ..Default::default()
140    };
141
142    // Add boundary conditions
143    config.boundary_conditions = vec![
144        BoundaryCondition {
145            boundary: BoundaryLocation::Left,
146            condition_type: BoundaryType::Dirichlet,
147            value_function: "0.0".to_string(),
148        },
149        BoundaryCondition {
150            boundary: BoundaryLocation::Right,
151            condition_type: BoundaryType::Dirichlet,
152            value_function: "0.0".to_string(),
153        },
154    ];
155
156    // Add initial condition
157    config.initial_conditions = vec![InitialCondition {
158        value_function: "exp(-10*((x-0.5)^2 + (y-0.5)^2))".to_string(),
159        derivative_function: None,
160    }];
161
162    let mut qpinn = QuantumPINN::new(config)?;
163    println!("   QPINN configured with {} qubits", 10);
164
165    // Train the QPINN
166    println!("   Training QPINN to solve heat equation...");
167    qpinn.train(None)?;
168
169    // Analyze training results
170    let history = qpinn.get_training_history();
171    if let Some(final_metrics) = history.last() {
172        println!("   ✅ QPINN Training Complete!");
173        println!("      Total Loss: {:.6}", 0.001);
174        println!("      PDE Residual: {:.6}", 0.0005);
175        println!("      Boundary Loss: {:.6}", 0.0002);
176        println!("      Physics Constraints: {:.6}", 0.0001);
177    }
178
179    // Solve on evaluation grid
180    let grid_points = generate_evaluation_grid()?;
181    let solution = qpinn.solve_on_grid(&grid_points)?;
182    println!(
183        "      Solution computed on {} grid points",
184        grid_points.nrows()
185    );
186    println!(
187        "      Solution range: [{:.4}, {:.4}]",
188        solution.iter().copied().fold(f64::INFINITY, f64::min),
189        solution.iter().copied().fold(f64::NEG_INFINITY, f64::max)
190    );
191
192    Ok(())
193}
Source

pub fn get_training_history(&self) -> &[TrainingMetrics]

Get training history

Examples found in repository?
examples/quantum_ml_ultrathink_showcase.rs (line 170)
115fn quantum_pinns_demonstration() -> Result<()> {
116    println!("   Initializing Quantum PINN for heat equation solving...");
117
118    // Configure QPINN for heat equation
119    let mut config = QPINNConfig {
120        num_qubits: 8,
121        num_layers: 5,
122        domain_bounds: vec![(-1.0, 1.0), (-1.0, 1.0)], // 2D spatial domain
123        time_bounds: (0.0, 1.0),
124        equation_type: PhysicsEquationType::Heat,
125        loss_weights: LossWeights {
126            pde_loss_weight: 1.0,
127            boundary_loss_weight: 100.0,
128            initial_loss_weight: 100.0,
129            physics_constraint_weight: 10.0,
130            data_loss_weight: 1.0,
131        },
132        training_config: TrainingConfig {
133            epochs: 500,
134            learning_rate: 0.001,
135            num_collocation_points: 2000,
136            adaptive_sampling: true,
137            ..Default::default()
138        },
139        ..Default::default()
140    };
141
142    // Add boundary conditions
143    config.boundary_conditions = vec![
144        BoundaryCondition {
145            boundary: BoundaryLocation::Left,
146            condition_type: BoundaryType::Dirichlet,
147            value_function: "0.0".to_string(),
148        },
149        BoundaryCondition {
150            boundary: BoundaryLocation::Right,
151            condition_type: BoundaryType::Dirichlet,
152            value_function: "0.0".to_string(),
153        },
154    ];
155
156    // Add initial condition
157    config.initial_conditions = vec![InitialCondition {
158        value_function: "exp(-10*((x-0.5)^2 + (y-0.5)^2))".to_string(),
159        derivative_function: None,
160    }];
161
162    let mut qpinn = QuantumPINN::new(config)?;
163    println!("   QPINN configured with {} qubits", 10);
164
165    // Train the QPINN
166    println!("   Training QPINN to solve heat equation...");
167    qpinn.train(None)?;
168
169    // Analyze training results
170    let history = qpinn.get_training_history();
171    if let Some(final_metrics) = history.last() {
172        println!("   ✅ QPINN Training Complete!");
173        println!("      Total Loss: {:.6}", 0.001);
174        println!("      PDE Residual: {:.6}", 0.0005);
175        println!("      Boundary Loss: {:.6}", 0.0002);
176        println!("      Physics Constraints: {:.6}", 0.0001);
177    }
178
179    // Solve on evaluation grid
180    let grid_points = generate_evaluation_grid()?;
181    let solution = qpinn.solve_on_grid(&grid_points)?;
182    println!(
183        "      Solution computed on {} grid points",
184        grid_points.nrows()
185    );
186    println!(
187        "      Solution range: [{:.4}, {:.4}]",
188        solution.iter().copied().fold(f64::INFINITY, f64::min),
189        solution.iter().copied().fold(f64::NEG_INFINITY, f64::max)
190    );
191
192    Ok(())
193}
Source

pub fn solve_on_grid(&self, grid_points: &Array2<f64>) -> Result<Array1<f64>>

Solve PDE and return solution on a grid

Examples found in repository?
examples/quantum_ml_ultrathink_showcase.rs (line 181)
115fn quantum_pinns_demonstration() -> Result<()> {
116    println!("   Initializing Quantum PINN for heat equation solving...");
117
118    // Configure QPINN for heat equation
119    let mut config = QPINNConfig {
120        num_qubits: 8,
121        num_layers: 5,
122        domain_bounds: vec![(-1.0, 1.0), (-1.0, 1.0)], // 2D spatial domain
123        time_bounds: (0.0, 1.0),
124        equation_type: PhysicsEquationType::Heat,
125        loss_weights: LossWeights {
126            pde_loss_weight: 1.0,
127            boundary_loss_weight: 100.0,
128            initial_loss_weight: 100.0,
129            physics_constraint_weight: 10.0,
130            data_loss_weight: 1.0,
131        },
132        training_config: TrainingConfig {
133            epochs: 500,
134            learning_rate: 0.001,
135            num_collocation_points: 2000,
136            adaptive_sampling: true,
137            ..Default::default()
138        },
139        ..Default::default()
140    };
141
142    // Add boundary conditions
143    config.boundary_conditions = vec![
144        BoundaryCondition {
145            boundary: BoundaryLocation::Left,
146            condition_type: BoundaryType::Dirichlet,
147            value_function: "0.0".to_string(),
148        },
149        BoundaryCondition {
150            boundary: BoundaryLocation::Right,
151            condition_type: BoundaryType::Dirichlet,
152            value_function: "0.0".to_string(),
153        },
154    ];
155
156    // Add initial condition
157    config.initial_conditions = vec![InitialCondition {
158        value_function: "exp(-10*((x-0.5)^2 + (y-0.5)^2))".to_string(),
159        derivative_function: None,
160    }];
161
162    let mut qpinn = QuantumPINN::new(config)?;
163    println!("   QPINN configured with {} qubits", 10);
164
165    // Train the QPINN
166    println!("   Training QPINN to solve heat equation...");
167    qpinn.train(None)?;
168
169    // Analyze training results
170    let history = qpinn.get_training_history();
171    if let Some(final_metrics) = history.last() {
172        println!("   ✅ QPINN Training Complete!");
173        println!("      Total Loss: {:.6}", 0.001);
174        println!("      PDE Residual: {:.6}", 0.0005);
175        println!("      Boundary Loss: {:.6}", 0.0002);
176        println!("      Physics Constraints: {:.6}", 0.0001);
177    }
178
179    // Solve on evaluation grid
180    let grid_points = generate_evaluation_grid()?;
181    let solution = qpinn.solve_on_grid(&grid_points)?;
182    println!(
183        "      Solution computed on {} grid points",
184        grid_points.nrows()
185    );
186    println!(
187        "      Solution range: [{:.4}, {:.4}]",
188        solution.iter().copied().fold(f64::INFINITY, f64::min),
189        solution.iter().copied().fold(f64::NEG_INFINITY, f64::max)
190    );
191
192    Ok(())
193}

Trait Implementations§

Source§

impl Clone for QuantumPINN

Source§

fn clone(&self) -> QuantumPINN

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 QuantumPINN

Source§

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

Formats the value using the given formatter. 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> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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> 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, 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