Closed hsorby closed 3 years ago
Agreed that something funny is happening here. I believe compute_computed_constants
and compute_variables
should actually be defined as follows since we cannot guarantee that variables[3]
is a computed constant (since variables[0]
and variables[1]
are external variables):
def compute_computed_constants(variables):
pass
def compute_variables(variables, external_variable):
variables[0] = external_variable(variables, 0)
variables[1] = external_variable(variables, 1)
variables[2] = 1000.0*3.14*variables[1]*variables[1]*variables[0]
variables[3] = 0.02*variables[2]
Otherwise, good point about initialising the external variables. I guess we should have a new method for the case where we have external variables. Something like:
def initialise_external_variables(variables, external_variable):
variables[0] = external_variable(variables, 0)
variables[1] = external_variable(variables, 1)
Something to discuss at our next libCellML meeting @hsorby and @nickerso.
After our weekly meeting, we agreed that we should have the following (@hsorby and @nickerso to comment if I got it wrong):
initialise_constants()
and initialise_states_and_constants()
are to be replaced with initialise_variables()
as follows:
# Algebraic model:
def initialise_variables(variables):
...
def initialise_variables(variables, external_variable): ... variables[index] = external_variable(variables, index)
def initialise_variables(states, variables): ...
def initialise_variables(voi, states, variables, external_variable): variables[index] = external_variable(voi, states, variables, index)
- `compute_rates()` is to be updated as follows:
```python
# Differential model:
def compute_rates(voi, states, rates, variables):
...
# Differential model + external variables:
def compute_rates(voi, states, rates, variables, external_variable):
variables[index] = external_variable(voi, states, variables, index)
compute_variables()
is to be updated as follows:
# Algebraic model:
def compute_variables(variables):
...
def compute_variables(variables, external_variable): ... variables[index] = external_variable(variables, index)
def compute_variables(voi, states, rates, variables): ...
def compute_variables(voi, states, rates, variables, external_variable): variables[index] = external_variable(voi, states, variables, index)
Can you confirm that you need voi
for an algebraic equation with external variables. I don't see why it should be there.
That's, I believe, what @nickerso was talking about this morning, i.e. the user may have some recorded data that s/he wants to use as the value of some external variable. To retrieve the correct value from that recorded data, to have access to voi
will (likely?) be needed.
Algebraic models do not have a voi
, right? so "time" would just be a variable...
Oops, sorry, yes of course! Was thinking about initialise_variables()
for a differential model + external variables. My bad. I have corrected my comment.
If I have the following model:
and I run it through the following Python script
I get the following Python implementation code
Which I think has the problem in the
compute_computed_constants
function where the equation for settingvariable[2]
does not appear. Also, I cannot initialise the external variables.