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

[Bug]: model.set_initial_conditions_from assumes state variable names consistent with output variables #4662

Open
martinjrobins opened this issue Dec 11, 2024 · 4 comments · May be fixed by #4700
Labels
bug Something isn't working

Comments

@martinjrobins
Copy link
Contributor

PyBaMM Version

develop

Python Version

n/a

Describe the bug

the BaseModel.set_initial_conditions function extracts the ic values from a pybamm.Solution object. It looks in the output variables of the model to find each variable in turn, then concatenates a new state vector from the evaluation of those output variables.

This works fine with our library models, where for each variable a = pybamm.Variable('A'), we have defined an output variable model.variables = { 'A': a}. But third party models do not neccessarily have this structure, so the BaseModel.set_initial_conditions function can easily fail when this third party model is used in an experiment

Perhaps instead we could:

  1. disallow any output variables of a model with the same name as a model variable
  2. automatically create output variables for each variable when model is discretised

Steps to Reproduce

  1. create a model that has a variable with name A, and an output variable with the same name but a different shape
  2. use this model in an experiment

Relevant log output

@martinjrobins martinjrobins added the bug Something isn't working label Dec 11, 2024
@agriyakhetarpal
Copy link
Member

Hi @TusharNaugain, your potential solution seems to be just a rephrase of the steps that have been outlined already. Could you please elaborate on how you plan to implement these changes? A proposal to fix this must be refined enough and filled with details that describe your approach to the codebase succinctly.

This might not be a "good first issue", since it assumes some knowledge of what is going on with the processing and solving of our models – please look for issues labelled as "easy" if you wish to contribute and are looking for where to start!

@martinjrobins
Copy link
Contributor Author

agree with @agriyakhetarpal that this is not a good first issue, you need to have a good knowledge of how pybamm represents and processes a model via discretisation.

I didn't implement the BaseModel.set_initial_conditions function, @valentinsulzer I think this was you, are you happy with my proposed solution?

@valentinsulzer
Copy link
Member

I think adding the variables when discretizing is a good idea, not sure why we also need to disallow outputs with the same name as set_initial_conditions should just look for the variable with the right name and ignore any others

@martinjrobins
Copy link
Contributor Author

if there is already an output with the same name as the variable then the discretisation class won't be able to add the variable (its a dict mapping str to an expression as I recall)

@martinjrobins martinjrobins linked a pull request Dec 20, 2024 that will close this issue
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants