pub struct QLearningOptimizer { /* private fields */ }Expand description
Q-learning agent for circuit optimization
Implementations§
Source§impl QLearningOptimizer
impl QLearningOptimizer
Sourcepub fn new(
learning_rate: f64,
discount_factor: f64,
initial_epsilon: f64,
) -> Self
pub fn new( learning_rate: f64, discount_factor: f64, initial_epsilon: f64, ) -> Self
Create a new Q-learning optimizer
§Arguments
learning_rate- How quickly the agent learns (0.0 to 1.0)discount_factor- How much future rewards matter (0.0 to 1.0)initial_epsilon- Initial exploration rate (0.0 to 1.0)
Sourcepub fn choose_action(
&self,
state: &CircuitState,
available_actions: &[OptimizationAction],
) -> OptimizationAction
pub fn choose_action( &self, state: &CircuitState, available_actions: &[OptimizationAction], ) -> OptimizationAction
Choose action using epsilon-greedy policy
§Arguments
state- Current circuit stateavailable_actions- List of actions that can be taken
Sourcepub fn update_q_value(
&mut self,
state: &CircuitState,
action: OptimizationAction,
reward: f64,
next_state: &CircuitState,
next_actions: &[OptimizationAction],
)
pub fn update_q_value( &mut self, state: &CircuitState, action: OptimizationAction, reward: f64, next_state: &CircuitState, next_actions: &[OptimizationAction], )
Update Q-value based on observed reward
§Arguments
state- Previous stateaction- Action takenreward- Reward receivednext_state- New state after actionnext_actions- Actions available in next state
Sourcepub fn calculate_reward(
&self,
old_state: &CircuitState,
new_state: &CircuitState,
) -> f64
pub fn calculate_reward( &self, old_state: &CircuitState, new_state: &CircuitState, ) -> f64
Calculate reward for a state transition
Reward is based on improvements in circuit metrics:
- Reduced depth (+reward)
- Reduced gate count (+reward)
- Increased fidelity (+reward)
Sourcepub fn finish_episode(&mut self, episode: OptimizationEpisode)
pub fn finish_episode(&mut self, episode: OptimizationEpisode)
Complete an optimization episode
Sourcepub fn get_statistics(&self) -> OptimizationStatistics
pub fn get_statistics(&self) -> OptimizationStatistics
Get optimization statistics
Sourcepub fn save_q_table(&self, path: &str) -> QuantRS2Result<()>
pub fn save_q_table(&self, path: &str) -> QuantRS2Result<()>
Save the learned Q-table to path as JSON.
The Q-table is HashMap<(Vec<u8>, OptimizationAction), f64>. JSON object keys must
be strings, so entries are serialized as a flat list of
((state_key, action), q_value) tuples. Returns an honest error on serialization
or I/O failure rather than silently dropping the data.
Sourcepub fn load_q_table(&mut self, path: &str) -> QuantRS2Result<()>
pub fn load_q_table(&mut self, path: &str) -> QuantRS2Result<()>
Load a Q-table from path, replacing the current table.
Reads the JSON written by Self::save_q_table. Returns an honest error on I/O or
deserialization failure.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for QLearningOptimizer
impl RefUnwindSafe for QLearningOptimizer
impl Send for QLearningOptimizer
impl Sync for QLearningOptimizer
impl Unpin for QLearningOptimizer
impl UnsafeUnpin for QLearningOptimizer
impl UnwindSafe for QLearningOptimizer
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
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> ⓘ
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> ⓘ
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
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
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>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
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
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.