Skip to content

Commit 180e02a

Browse files
Rename MoveGenerator agent hooks to save/restore_proposal_state and copy_state_from
1 parent cc40971 commit 180e02a

3 files changed

Lines changed: 22 additions & 20 deletions

File tree

vpr/src/place/move_generators/move_generator.h

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -147,22 +147,24 @@ class MoveGenerator {
147147
virtual void process_outcome(double /*reward*/, e_reward_function /*reward_fun*/) {}
148148

149149
/**
150-
* @brief Returns an identifier for the internal decision ("arm") behind the
151-
* most recent propose_move(). Only meaningful for RL-agent based generators.
152-
* Capturing it after each proposal and restoring it before the matching
153-
* outcome lets a caller interleave proposals and still replay outcomes in order.
150+
* @brief Returns a token describing the generator's state after the most
151+
* recent propose_move(). Only needed when outcomes are not reported right
152+
* after each proposal. A caller can record the token and reward of each
153+
* proposal and apply them later in a batch. Stateless generators return 0.
154154
*/
155-
virtual size_t get_last_action() const { return 0; }
155+
virtual size_t save_proposal_state() const { return 0; }
156156

157-
/// @brief Restores the action identifier captured by get_last_action().
158-
virtual void set_last_action(size_t /*action*/) {}
157+
/**
158+
* @brief Restores a token from save_proposal_state() so the next
159+
* process_outcome() is credited to that proposal.
160+
*/
161+
virtual void restore_proposal_state(size_t /*state*/) {}
159162

160163
/**
161-
* @brief Copies the RL agent's Q-values from `other`, which must be
162-
* a generator of the same concrete type, so a replica proposes exactly
163-
* what the master would.
164+
* @brief Copies the state from `other`, which must be of the same
165+
* concrete type, so this generator proposes what `other` would.
164166
*/
165-
virtual void sync_state_from(const MoveGenerator& /*other*/) {}
167+
virtual void copy_state_from(const MoveGenerator& /*other*/) {}
166168

167169
/**
168170
* @brief Calculates the agent's reward and the total process outcome

vpr/src/place/move_generators/simpleRL_move_generator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ void SimpleRLMoveGenerator::process_outcome(double reward, e_reward_function rew
3131
karmed_bandit_agent->process_outcome(reward, reward_fun);
3232
}
3333

34-
void SimpleRLMoveGenerator::sync_state_from(const MoveGenerator& other) {
34+
void SimpleRLMoveGenerator::copy_state_from(const MoveGenerator& other) {
3535
// Callers always pass a generator of the same concrete type,
3636
// and this runs once per sync rather than per move, so the cost is negligible.
3737
const SimpleRLMoveGenerator* other_rl = dynamic_cast<const SimpleRLMoveGenerator*>(&other);
38-
VTR_ASSERT_MSG(other_rl != nullptr, "Can only sync agent state from another SimpleRLMoveGenerator.");
38+
VTR_ASSERT_MSG(other_rl != nullptr, "Can only copy agent state from another SimpleRLMoveGenerator.");
3939
karmed_bandit_agent->copy_state_from(*other_rl->karmed_bandit_agent);
4040
}
4141

vpr/src/place/move_generators/simpleRL_move_generator.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class KArmedBanditAgent {
5959
size_t last_action() const { return last_action_; }
6060

6161
/// @brief Overrides the action credited by the next process_outcome() call.
62-
/// See MoveGenerator::get_last_action() for the intended usage.
62+
/// See MoveGenerator::save_proposal_state() for the intended usage.
6363
void set_last_action(size_t action) { last_action_ = action; }
6464

6565
/// @brief Copies the learned state (Q-values, action counts, step size) from `other`.
@@ -264,14 +264,14 @@ class SimpleRLMoveGenerator : public MoveGenerator {
264264
// Receives feedback about the outcome of the previously proposed move
265265
void process_outcome(double reward, e_reward_function reward_fun) override;
266266

267-
/// @brief Returns/overrides the agent action behind the most recent proposal.
268-
/// See MoveGenerator::get_last_action() for the intended usage.
269-
size_t get_last_action() const override { return karmed_bandit_agent->last_action(); }
270-
void set_last_action(size_t action) override { karmed_bandit_agent->set_last_action(action); }
267+
/// @brief Saves/restores the agent action behind the most recent proposal.
268+
/// See MoveGenerator::save_proposal_state() for the intended usage.
269+
size_t save_proposal_state() const override { return karmed_bandit_agent->last_action(); }
270+
void restore_proposal_state(size_t state) override { karmed_bandit_agent->set_last_action(state); }
271271

272272
/// @brief Copies the agent state from another SimpleRLMoveGenerator.
273-
/// See MoveGenerator::sync_state_from() for the intended usage.
274-
void sync_state_from(const MoveGenerator& other) override;
273+
/// See MoveGenerator::copy_state_from() for the intended usage.
274+
void copy_state_from(const MoveGenerator& other) override;
275275
};
276276

277277
template<class T, class>

0 commit comments

Comments
 (0)