Skip to content

Conversation

@mj023
Copy link
Collaborator

@mj023 mj023 commented Oct 30, 2025

This PR is supposed to add features to handle Models that consist of multiple deterministic Regimes.

  • Add Multi Regime attributes to Model and Regime objects
  • Adapt solution to multi-regime Models
  • Rework PramsTemplate for multi-regime models
  • Refactor simulation
  • Adapt simulation to multi-regime models
  • Add new test for multi-regime models
  • Fix tests

For the next PR(s)

  1. Move simulation result processing out of core simulation function and improve
  2. Check if argmax needs to return flattened index arrays?

mj023 and others added 2 commits October 30, 2025 22:29
…group (#167)

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
state_action_spaces = build_state_action_spaces(regime)
next_state = get_next_state_function(
internal_functions=internal_functions,
transitions=flatten_to_qnames(internal_functions.transitions),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you write a wrapper function for the flatten_to_qnames functions in some utils module that explains what behavior we expect in lcm. Since transitions have a specific structure we can say more about the expected structure of the outcome that way.


internal_transition = {
fn_name: functions[fn_name] for fn_name in regime.transitions
fn_name: functions[fn_name] for fn_name in flatten_to_qnames(regime.transitions)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here and for the unflattening part. Would be better if these functions come from some of our modules and have a name that potentially add some information of what happens in our case.

src/lcm/model.py Outdated
Comment on lines 131 to 133
argmax_and_max_Q_over_a_functions=self.internal_regimes.argmax_and_max_Q_over_a_functions,
next_state_simulation_function=self.internal_regimes.next_state_simulation_function,
internal_regime=self.internal_regimes,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that you only pass the internal regimes to solve and not the individual functions. Can we do the same for simulate?

functions: dict[str, UserFunction] = field(default_factory=dict)
actions: dict[str, Grid] = field(default_factory=dict)
states: dict[str, Grid] = field(default_factory=dict)
regime_transition_probabilities: Callable[..., dict[str, float]]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

regime_transition_probs, otherwise it is too long.

src/lcm/model.py Outdated
)
self.regimes[regime.name] = regime
self.internal_regimes[regime.name] = process_regime(
regime=regime, n_periods=n_periods, enable_jit=enable_jit
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we have to update the regime processing to include all regimes? I thought that we need to do the processing of certain regime components first, as we then need to pass the processed components of all regimes into each regime? I.e., the Q-and-F function of a regime depends on all of the other regimes?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants