pub struct ParticleGAN {
pub gan: QuantumGAN,
pub physics_params: PhysicsParameters,
}Expand description
GAN model specialized for particle physics simulations
Fields§
§gan: QuantumGANThe core quantum GAN implementation
physics_params: PhysicsParametersSpecialized parameters for physics simulations
Implementations§
Source§impl ParticleGAN
impl ParticleGAN
Sourcepub fn new(
num_qubits_gen: usize,
num_qubits_disc: usize,
latent_dim: usize,
data_dim: usize,
) -> Result<Self>
pub fn new( num_qubits_gen: usize, num_qubits_disc: usize, latent_dim: usize, data_dim: usize, ) -> Result<Self>
Creates a new particle physics GAN
Examples found in repository?
examples/quantum_gan.rs (lines 108-113)
15fn main() -> Result<()> {
16 println!("Quantum Generative Adversarial Network Example");
17 println!("=============================================");
18
19 // GAN parameters
20 let num_qubits_gen = 6;
21 let num_qubits_disc = 6;
22 let latent_dim = 4;
23 let data_dim = 8;
24
25 println!("Creating Quantum GAN...");
26 println!(" Generator: {num_qubits_gen} qubits");
27 println!(" Discriminator: {num_qubits_disc} qubits");
28 println!(" Latent dimension: {latent_dim}");
29 println!(" Data dimension: {data_dim}");
30
31 // Create quantum GAN
32 let mut qgan = QuantumGAN::new(
33 num_qubits_gen,
34 num_qubits_disc,
35 latent_dim,
36 data_dim,
37 GeneratorType::HybridClassicalQuantum,
38 DiscriminatorType::HybridQuantumFeatures,
39 )?;
40
41 // Generate synthetic data for training
42 println!("Generating synthetic data for training...");
43 let real_data = generate_sine_wave_data(500, data_dim);
44
45 // Train GAN
46 println!("Training quantum GAN...");
47 let training_params = [
48 (50, 32, 0.01, 0.01, 1), // (epochs, batch_size, lr_gen, lr_disc, disc_steps)
49 ];
50
51 for (epochs, batch_size, lr_gen, lr_disc, disc_steps) in training_params {
52 println!("Training with parameters:");
53 println!(" Epochs: {epochs}");
54 println!(" Batch size: {batch_size}");
55 println!(" Generator learning rate: {lr_gen}");
56 println!(" Discriminator learning rate: {lr_disc}");
57 println!(" Discriminator steps per iteration: {disc_steps}");
58
59 let start = Instant::now();
60 let history = qgan.train(&real_data, epochs, batch_size, lr_gen, lr_disc, disc_steps)?;
61
62 println!("Training completed in {:.2?}", start.elapsed());
63 println!("Final losses:");
64 println!(
65 " Generator: {:.4}",
66 history.gen_losses.last().unwrap_or(&0.0)
67 );
68 println!(
69 " Discriminator: {:.4}",
70 history.disc_losses.last().unwrap_or(&0.0)
71 );
72 }
73
74 // Generate samples
75 println!("\nGenerating samples from trained GAN...");
76 let num_samples = 10;
77 let generated_samples = qgan.generate(num_samples)?;
78
79 println!("Generated {num_samples} samples");
80 println!("First sample:");
81 print_sample(
82 &generated_samples
83 .slice(scirs2_core::ndarray::s![0, ..])
84 .to_owned(),
85 );
86
87 // Evaluate GAN
88 println!("\nEvaluating GAN quality...");
89 let eval_metrics = qgan.evaluate(&real_data, num_samples)?;
90
91 println!("Evaluation metrics:");
92 println!(
93 " Real data accuracy: {:.2}%",
94 eval_metrics.real_accuracy * 100.0
95 );
96 println!(
97 " Fake data accuracy: {:.2}%",
98 eval_metrics.fake_accuracy * 100.0
99 );
100 println!(
101 " Overall discriminator accuracy: {:.2}%",
102 eval_metrics.overall_accuracy * 100.0
103 );
104 println!(" JS Divergence: {:.4}", eval_metrics.js_divergence);
105
106 // Use physics-specific GAN
107 println!("\nCreating specialized particle physics GAN...");
108 let particle_gan = quantrs2_ml::gan::physics_gan::ParticleGAN::new(
109 num_qubits_gen,
110 num_qubits_disc,
111 latent_dim,
112 data_dim,
113 )?;
114
115 println!("Particle GAN created successfully");
116
117 Ok(())
118}Auto Trait Implementations§
impl Freeze for ParticleGAN
impl RefUnwindSafe for ParticleGAN
impl Send for ParticleGAN
impl Sync for ParticleGAN
impl Unpin for ParticleGAN
impl UnsafeUnpin for ParticleGAN
impl UnwindSafe for ParticleGAN
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> 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.