pub struct QuantumReasoningModule { /* private fields */ }Expand description
Quantum reasoning module
Implementations§
Source§impl QuantumReasoningModule
impl QuantumReasoningModule
Sourcepub fn new(config: QuantumReasoningConfig) -> Result<Self>
pub fn new(config: QuantumReasoningConfig) -> Result<Self>
Create new quantum reasoning module
Examples found in repository?
examples/quantum_llm.rs (line 217)
205fn quantum_reasoning_demo() -> Result<()> {
206 println!(" Testing quantum reasoning modules...");
207
208 let reasoning_configs = vec![
209 ("Basic Logical", QuantumReasoningConfig::default()),
210 ("Enhanced Causal", QuantumReasoningConfig::enhanced()),
211 ("Advanced Analogical", QuantumReasoningConfig::advanced()),
212 ];
213
214 for (name, config) in reasoning_configs {
215 println!("\n --- {} Reasoning ---", name);
216
217 let mut reasoning_module = QuantumReasoningModule::new(config.clone())?;
218
219 println!(" Reasoning capabilities:");
220 println!(" - Logical reasoning: {}", config.logical_reasoning);
221 println!(" - Causal reasoning: {}", config.causal_reasoning);
222 println!(" - Analogical reasoning: {}", config.analogical_reasoning);
223 println!(" - Reasoning steps: {}", config.reasoning_steps);
224 println!(" - Circuit depth: {}", config.circuit_depth);
225 println!(
226 " - Entanglement strength: {:.2}",
227 config.entanglement_strength
228 );
229
230 // Test reasoning on sample hidden states
231 let hidden_states = Array3::from_shape_fn((2, 8, 256), |(b, s, d)| {
232 // Create patterns that require reasoning
233 let logical_pattern = if s % 2 == 0 { 0.8 } else { 0.2 };
234 let causal_pattern = s as f64 * 0.1;
235 let base_value = logical_pattern + causal_pattern;
236
237 base_value + 0.05 * (b as f64 + d as f64 * 0.001)
238 });
239
240 println!(" Input hidden states shape: {:?}", hidden_states.dim());
241
242 // Apply quantum reasoning
243 let reasoned_output = reasoning_module.apply_reasoning(&hidden_states)?;
244 println!(" Reasoned output shape: {:?}", reasoned_output.dim());
245
246 // Analyze reasoning effects
247 let reasoning_enhancement =
248 analyze_reasoning_enhancement(&hidden_states, &reasoned_output)?;
249 println!(" Reasoning enhancement metrics:");
250 println!(
251 " - Pattern amplification: {:.3}",
252 reasoning_enhancement.pattern_amplification
253 );
254 println!(
255 " - Logical consistency: {:.3}",
256 reasoning_enhancement.logical_consistency
257 );
258 println!(
259 " - Causal coherence: {:.3}",
260 reasoning_enhancement.causal_coherence
261 );
262
263 // Test quantum coherence during reasoning
264 let coherence = reasoning_module.measure_coherence()?;
265 println!(" Quantum coherence: {:.3}", coherence);
266
267 // Test token selection enhancement
268 let sample_logits = Array1::from_shape_fn(1000, |i| {
269 0.01 * (i as f64 * 0.1).sin() + 0.001 * fastrand::f64()
270 });
271
272 let enhanced_logits = reasoning_module.enhance_token_selection(&sample_logits)?;
273 let enhancement_effect = (&enhanced_logits - &sample_logits)
274 .mapv(|x| x.abs())
275 .mean()
276 .unwrap_or(0.0);
277 println!(" Token selection enhancement: {:.4}", enhancement_effect);
278 }
279
280 Ok(())
281}Sourcepub fn apply_reasoning(
&mut self,
hidden_states: &Array3<f64>,
) -> Result<Array3<f64>>
pub fn apply_reasoning( &mut self, hidden_states: &Array3<f64>, ) -> Result<Array3<f64>>
Apply quantum reasoning to transformer output
Examples found in repository?
examples/quantum_llm.rs (line 243)
205fn quantum_reasoning_demo() -> Result<()> {
206 println!(" Testing quantum reasoning modules...");
207
208 let reasoning_configs = vec![
209 ("Basic Logical", QuantumReasoningConfig::default()),
210 ("Enhanced Causal", QuantumReasoningConfig::enhanced()),
211 ("Advanced Analogical", QuantumReasoningConfig::advanced()),
212 ];
213
214 for (name, config) in reasoning_configs {
215 println!("\n --- {} Reasoning ---", name);
216
217 let mut reasoning_module = QuantumReasoningModule::new(config.clone())?;
218
219 println!(" Reasoning capabilities:");
220 println!(" - Logical reasoning: {}", config.logical_reasoning);
221 println!(" - Causal reasoning: {}", config.causal_reasoning);
222 println!(" - Analogical reasoning: {}", config.analogical_reasoning);
223 println!(" - Reasoning steps: {}", config.reasoning_steps);
224 println!(" - Circuit depth: {}", config.circuit_depth);
225 println!(
226 " - Entanglement strength: {:.2}",
227 config.entanglement_strength
228 );
229
230 // Test reasoning on sample hidden states
231 let hidden_states = Array3::from_shape_fn((2, 8, 256), |(b, s, d)| {
232 // Create patterns that require reasoning
233 let logical_pattern = if s % 2 == 0 { 0.8 } else { 0.2 };
234 let causal_pattern = s as f64 * 0.1;
235 let base_value = logical_pattern + causal_pattern;
236
237 base_value + 0.05 * (b as f64 + d as f64 * 0.001)
238 });
239
240 println!(" Input hidden states shape: {:?}", hidden_states.dim());
241
242 // Apply quantum reasoning
243 let reasoned_output = reasoning_module.apply_reasoning(&hidden_states)?;
244 println!(" Reasoned output shape: {:?}", reasoned_output.dim());
245
246 // Analyze reasoning effects
247 let reasoning_enhancement =
248 analyze_reasoning_enhancement(&hidden_states, &reasoned_output)?;
249 println!(" Reasoning enhancement metrics:");
250 println!(
251 " - Pattern amplification: {:.3}",
252 reasoning_enhancement.pattern_amplification
253 );
254 println!(
255 " - Logical consistency: {:.3}",
256 reasoning_enhancement.logical_consistency
257 );
258 println!(
259 " - Causal coherence: {:.3}",
260 reasoning_enhancement.causal_coherence
261 );
262
263 // Test quantum coherence during reasoning
264 let coherence = reasoning_module.measure_coherence()?;
265 println!(" Quantum coherence: {:.3}", coherence);
266
267 // Test token selection enhancement
268 let sample_logits = Array1::from_shape_fn(1000, |i| {
269 0.01 * (i as f64 * 0.1).sin() + 0.001 * fastrand::f64()
270 });
271
272 let enhanced_logits = reasoning_module.enhance_token_selection(&sample_logits)?;
273 let enhancement_effect = (&enhanced_logits - &sample_logits)
274 .mapv(|x| x.abs())
275 .mean()
276 .unwrap_or(0.0);
277 println!(" Token selection enhancement: {:.4}", enhancement_effect);
278 }
279
280 Ok(())
281}Sourcepub fn enhance_token_selection(
&self,
logits: &Array1<f64>,
) -> Result<Array1<f64>>
pub fn enhance_token_selection( &self, logits: &Array1<f64>, ) -> Result<Array1<f64>>
Enhance token selection with quantum reasoning
Examples found in repository?
examples/quantum_llm.rs (line 272)
205fn quantum_reasoning_demo() -> Result<()> {
206 println!(" Testing quantum reasoning modules...");
207
208 let reasoning_configs = vec![
209 ("Basic Logical", QuantumReasoningConfig::default()),
210 ("Enhanced Causal", QuantumReasoningConfig::enhanced()),
211 ("Advanced Analogical", QuantumReasoningConfig::advanced()),
212 ];
213
214 for (name, config) in reasoning_configs {
215 println!("\n --- {} Reasoning ---", name);
216
217 let mut reasoning_module = QuantumReasoningModule::new(config.clone())?;
218
219 println!(" Reasoning capabilities:");
220 println!(" - Logical reasoning: {}", config.logical_reasoning);
221 println!(" - Causal reasoning: {}", config.causal_reasoning);
222 println!(" - Analogical reasoning: {}", config.analogical_reasoning);
223 println!(" - Reasoning steps: {}", config.reasoning_steps);
224 println!(" - Circuit depth: {}", config.circuit_depth);
225 println!(
226 " - Entanglement strength: {:.2}",
227 config.entanglement_strength
228 );
229
230 // Test reasoning on sample hidden states
231 let hidden_states = Array3::from_shape_fn((2, 8, 256), |(b, s, d)| {
232 // Create patterns that require reasoning
233 let logical_pattern = if s % 2 == 0 { 0.8 } else { 0.2 };
234 let causal_pattern = s as f64 * 0.1;
235 let base_value = logical_pattern + causal_pattern;
236
237 base_value + 0.05 * (b as f64 + d as f64 * 0.001)
238 });
239
240 println!(" Input hidden states shape: {:?}", hidden_states.dim());
241
242 // Apply quantum reasoning
243 let reasoned_output = reasoning_module.apply_reasoning(&hidden_states)?;
244 println!(" Reasoned output shape: {:?}", reasoned_output.dim());
245
246 // Analyze reasoning effects
247 let reasoning_enhancement =
248 analyze_reasoning_enhancement(&hidden_states, &reasoned_output)?;
249 println!(" Reasoning enhancement metrics:");
250 println!(
251 " - Pattern amplification: {:.3}",
252 reasoning_enhancement.pattern_amplification
253 );
254 println!(
255 " - Logical consistency: {:.3}",
256 reasoning_enhancement.logical_consistency
257 );
258 println!(
259 " - Causal coherence: {:.3}",
260 reasoning_enhancement.causal_coherence
261 );
262
263 // Test quantum coherence during reasoning
264 let coherence = reasoning_module.measure_coherence()?;
265 println!(" Quantum coherence: {:.3}", coherence);
266
267 // Test token selection enhancement
268 let sample_logits = Array1::from_shape_fn(1000, |i| {
269 0.01 * (i as f64 * 0.1).sin() + 0.001 * fastrand::f64()
270 });
271
272 let enhanced_logits = reasoning_module.enhance_token_selection(&sample_logits)?;
273 let enhancement_effect = (&enhanced_logits - &sample_logits)
274 .mapv(|x| x.abs())
275 .mean()
276 .unwrap_or(0.0);
277 println!(" Token selection enhancement: {:.4}", enhancement_effect);
278 }
279
280 Ok(())
281}Sourcepub fn measure_coherence(&self) -> Result<f64>
pub fn measure_coherence(&self) -> Result<f64>
Measure quantum coherence in reasoning
Examples found in repository?
examples/quantum_llm.rs (line 264)
205fn quantum_reasoning_demo() -> Result<()> {
206 println!(" Testing quantum reasoning modules...");
207
208 let reasoning_configs = vec![
209 ("Basic Logical", QuantumReasoningConfig::default()),
210 ("Enhanced Causal", QuantumReasoningConfig::enhanced()),
211 ("Advanced Analogical", QuantumReasoningConfig::advanced()),
212 ];
213
214 for (name, config) in reasoning_configs {
215 println!("\n --- {} Reasoning ---", name);
216
217 let mut reasoning_module = QuantumReasoningModule::new(config.clone())?;
218
219 println!(" Reasoning capabilities:");
220 println!(" - Logical reasoning: {}", config.logical_reasoning);
221 println!(" - Causal reasoning: {}", config.causal_reasoning);
222 println!(" - Analogical reasoning: {}", config.analogical_reasoning);
223 println!(" - Reasoning steps: {}", config.reasoning_steps);
224 println!(" - Circuit depth: {}", config.circuit_depth);
225 println!(
226 " - Entanglement strength: {:.2}",
227 config.entanglement_strength
228 );
229
230 // Test reasoning on sample hidden states
231 let hidden_states = Array3::from_shape_fn((2, 8, 256), |(b, s, d)| {
232 // Create patterns that require reasoning
233 let logical_pattern = if s % 2 == 0 { 0.8 } else { 0.2 };
234 let causal_pattern = s as f64 * 0.1;
235 let base_value = logical_pattern + causal_pattern;
236
237 base_value + 0.05 * (b as f64 + d as f64 * 0.001)
238 });
239
240 println!(" Input hidden states shape: {:?}", hidden_states.dim());
241
242 // Apply quantum reasoning
243 let reasoned_output = reasoning_module.apply_reasoning(&hidden_states)?;
244 println!(" Reasoned output shape: {:?}", reasoned_output.dim());
245
246 // Analyze reasoning effects
247 let reasoning_enhancement =
248 analyze_reasoning_enhancement(&hidden_states, &reasoned_output)?;
249 println!(" Reasoning enhancement metrics:");
250 println!(
251 " - Pattern amplification: {:.3}",
252 reasoning_enhancement.pattern_amplification
253 );
254 println!(
255 " - Logical consistency: {:.3}",
256 reasoning_enhancement.logical_consistency
257 );
258 println!(
259 " - Causal coherence: {:.3}",
260 reasoning_enhancement.causal_coherence
261 );
262
263 // Test quantum coherence during reasoning
264 let coherence = reasoning_module.measure_coherence()?;
265 println!(" Quantum coherence: {:.3}", coherence);
266
267 // Test token selection enhancement
268 let sample_logits = Array1::from_shape_fn(1000, |i| {
269 0.01 * (i as f64 * 0.1).sin() + 0.001 * fastrand::f64()
270 });
271
272 let enhanced_logits = reasoning_module.enhance_token_selection(&sample_logits)?;
273 let enhancement_effect = (&enhanced_logits - &sample_logits)
274 .mapv(|x| x.abs())
275 .mean()
276 .unwrap_or(0.0);
277 println!(" Token selection enhancement: {:.4}", enhancement_effect);
278 }
279
280 Ok(())
281}Sourcepub fn num_parameters(&self) -> usize
pub fn num_parameters(&self) -> usize
Get number of parameters
Trait Implementations§
Source§impl Clone for QuantumReasoningModule
impl Clone for QuantumReasoningModule
Source§fn clone(&self) -> QuantumReasoningModule
fn clone(&self) -> QuantumReasoningModule
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 QuantumReasoningModule
impl !RefUnwindSafe for QuantumReasoningModule
impl Send for QuantumReasoningModule
impl Sync for QuantumReasoningModule
impl Unpin for QuantumReasoningModule
impl !UnwindSafe for QuantumReasoningModule
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.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.