Open MichaelClerx opened 4 years ago
What I currently use for codegen (outsode pints / cellmlmanip) would need to be able to generate a function call that ends up being in the output. E.g.
lambda eq: sympy.Eq(eq.lhs, eq.rhs * sp.Function('HeartConfig::Instance()->GetCapacitance', real=True)()
so I think that may not be possible with this.
Could still work! @jonc125 wrapped sympy objects in pint.Quantity
, and I don't see why calling sp.Function(..)
couldn't be part of the lambda you passed in?
Also, you could just store the output of the function in a local var?
The function has no output, it needs to be there as a cal. In other woulds the C++ output is of the for:
const double xyz = .... * HeartConfig::Instance()->GetCapacitance()
If you can wrap that in a quantity maybe it's possible, where could I find this wrapping in action to look at?
There's an example of the wrapping in the description.
I also wondered about using Sympy's lambdify to convert from a Sympy expression to an equivalent Python that could operate on the Pint units. If you had Pint Quantity
instances with Sympy expressions as magnitudes (including UnevaluatedFunction
for your capacitance example, and our Variable
/Quantity
classes for variables & numbers) then applying such a Python-ised function to them should I think result in a Quantity
with the desired units, and the Sympy expression you need as the magnitude.
There's an example of the wrapping in the description.
I might be blind but I can't see it?
Ah, good point, sorry, didn't realise Michael had done something different. My example was at https://github.com/ModellingWebLab/weblab-fc/issues/156#issuecomment-614675629
The second point is handled by #286.
This issue has two goals:
cf
, we should somehow let that restriction goThe above is an example of pint transformations.
There's some subtle gotchas:
this will break, because the lambda doesn't store a copy of
f
, it just grabs anf
from the local scope whenever it's used, so both functions actually use the same f. So some tricks needed there (e.g. define a callable class).But the main thing to figure out is whether we can come up with some cellmlmanip API that can be re-used by FC (Web Lab) and chaste codegen, for specifying rules with lambdas (python lambdas? sympy expressions?) so that conversion of currents is easier