Diff of a ParameterFunction doesn't work when evaluated at a constant
See original GitHub issueDescribe the bug
When defining a parameter as the diff
of a ParameterFunction
sometimes it returns 0. I think the issue is that the expression gets simplified first and, because the argument is a constant, we loose track of the differentiation variable. Then, when taking the derivative, the variable is not in the tree and therefore it returns 0.
To Reproduce Steps to reproduce the behaviour:
- Add a
diff
parameter to your model, for example
def Uprime(sto, T):
inputs = {"Positive particle stoichiometry": sto}
Uprime_ref = pybamm.FunctionParameter(
"Positive electrode OCP [V]", inputs, diff_variable=sto
)
return Uprime_ref / pot
- Set the positive OCV from a function (for example a linear function).
- Evaluate at
c_0 = param.c_p_init(1)
, the function returns zero. - Evaluate at
c_0 + 0 * pybamm.t
, the function now returns the right value.
Issue Analytics
- State:
- Created 3 years ago
- Comments:7
Top Results From Across the Web
What's the difference between an argument and a parameter?
A parameter is a variable in a method definition. When a method is called, the arguments are the data you pass into the...
Read more >Functions - Advanced R. - Hadley Wickham
This function would not work without lazy evaluation because both x and y would always be evaluated, testing a > 0 even when...
Read more >Function pass by value vs. pass by reference
I will call what you are passing in a to a function the actual parameters, and where you receive them, the parameters in...
Read more >24. Passing Arguments | Python Tutorial
The passing of parameters and arguments in Python. Explaining the difference between call by object sharing, call by value and call by name....
Read more >Why do I get the error "Unrecognized function or variable"?
This error occurs only when I use mphload('filename') in an exe file. When in a .m file this line works well. I thought...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Ok, then I will implement the hacky method of the Multiplication by one, as you did with
c_e
.You might need to do the adding 0 * pybamm.t for it to work. Otherwise even the multiplication will get simplified out later, e.g.
2 * pybamm.Multiplication(5, 1)
would realize that the whole thing is constant and returnScalar(10)