Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example in tutorials: freezing a mode-switch variable #10

Open
MichaelClerx opened this issue Aug 2, 2021 · 1 comment
Open

Example in tutorials: freezing a mode-switch variable #10

MichaelClerx opened this issue Aug 2, 2021 · 1 comment
Labels
documentation Improvements or additions to documentation

Comments

@MichaelClerx
Copy link
Member

E.g. before fitting you'll want to change statements like

g_Kr = piecewise(cell.type == 0, 1, cell.type == 1, 1.2, cell.type == 2, 1.43) * g_Kr_base
  g_Kr_base = 0.123

to

g_Kr = 0.123

by doing e.g.

# Set the cell type you want
switch = m.get('cell.mode')
switch.set_rhs(1)

# Freeze all the (constant) variables to this mode
for var in switch.refs_by():
    if var.is_constant():
        # Evaluate the variable's RHS, and set its new RHS to the result
        var.set_rhs(var.eval())  # Remove the switch, if unused
        
        # Remove unused child variables, if any
        what's the best way to do this, if they depend on each other?

if not switch.refs_by():
    switch.parent().remove_variable(switch)
@MichaelClerx MichaelClerx added the documentation Improvements or additions to documentation label Aug 2, 2021
@MichaelClerx
Copy link
Member Author

Related: Should probably add a method that lets you delete all children of a VarOwner. This can re-use the variable _delete but with has_ancestor and any ancestor instead of the more limited whole_component=True

@MichaelClerx MichaelClerx transferred this issue from myokit/myokit Feb 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

1 participant