pub struct QuantumPINN { /* private fields */ }Expand description
Main Quantum Physics-Informed Neural Network
Implementations§
Source§impl QuantumPINN
impl QuantumPINN
Sourcepub fn new(config: QPINNConfig) -> Result<Self>
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}Sourcepub fn forward(&self, input_points: &Array2<f64>) -> Result<Array2<f64>>
pub fn forward(&self, input_points: &Array2<f64>) -> Result<Array2<f64>>
Forward pass through the quantum network
Sourcepub fn compute_derivatives(
&self,
points: &Array2<f64>,
) -> Result<DerivativeResults>
pub fn compute_derivatives( &self, points: &Array2<f64>, ) -> Result<DerivativeResults>
Compute derivatives using automatic differentiation
Sourcepub fn train(&mut self, epochs: Option<usize>) -> Result<()>
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}Sourcepub fn get_training_history(&self) -> &[TrainingMetrics]
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}Sourcepub fn solve_on_grid(&self, grid_points: &Array2<f64>) -> Result<Array1<f64>>
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
impl Clone for QuantumPINN
Source§fn clone(&self) -> QuantumPINN
fn clone(&self) -> QuantumPINN
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for QuantumPINN
impl RefUnwindSafe for QuantumPINN
impl Send for QuantumPINN
impl Sync for QuantumPINN
impl Unpin for QuantumPINN
impl UnwindSafe for QuantumPINN
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
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
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
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.