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]: pybamm.Simulation.set_parameters, pybamm.Simulation.set_up_and_parameterise_experiment and pybamm.Simulation.set_up_and_parameterise_model_for_experiment made private in simulation.py #3752

Conversation

Akhil-Sharma30
Copy link
Contributor

@Akhil-Sharma30 Akhil-Sharma30 commented Jan 21, 2024

Description

pybamm.Simulation.set_parameters, pybamm.Simulation.set_up_and_parameterise_experiment and pybamm.Simulation.set_up_and_parameterise_model_for_experiment made private in pybamm/simulation.py

Fixes #3751

Type of change

Please add a line in the relevant section of CHANGELOG.md to document the change (include PR #) - note reverse order of PR #s. If necessary, also add to the list of breaking changes.

  • New feature (non-breaking change which adds functionality)
  • Optimization (back-end change that speeds up the code)
  • Bug fix (non-breaking change which fixes an issue)

Key checklist:

  • No style issues: $ pre-commit run (or $ nox -s pre-commit) (see CONTRIBUTING.md for how to set this up to run automatically when committing locally, in just two lines of code)
  • All tests pass: $ python run-tests.py --all (or $ nox -s tests)
  • The documentation builds: $ python run-tests.py --doctest (or $ nox -s doctests)

You can run integration tests, unit tests, and doctests together at once, using $ python run-tests.py --quick (or $ nox -s quick).

Further checks:

  • Code is commented, particularly in hard-to-understand areas
  • Tests added that prove fix is effective or that feature works

@Akhil-Sharma30 Akhil-Sharma30 requested a review from a team as a code owner January 21, 2024 11:53
Copy link
Member

@valentinsulzer valentinsulzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@valentinsulzer valentinsulzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You will need to also update the method names wherever they are called (which should only be inside the Simulation class)

Copy link
Member

@agriyakhetarpal agriyakhetarpal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Akhil-Sharma30 for the fix!

Edit: yes, I missed Valentin's note. Please update the methods too

@agriyakhetarpal agriyakhetarpal dismissed their stale review January 21, 2024 12:16

This pull request needs extra changes, which I overlooked

@Akhil-Sharma30
Copy link
Contributor Author

You will need to also update the method names wherever they are called (which should only be inside the Simulation class)

Done.

@agriyakhetarpal
Copy link
Member

@all-contributors please add @Akhil-Sharma30 for docs

Copy link
Contributor

@agriyakhetarpal

I've put up a pull request to add @Akhil-Sharma30! 🎉

arjxn-py
arjxn-py previously approved these changes Jan 21, 2024
Copy link
Member

@arjxn-py arjxn-py left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Akhil-Sharma30, should be good to merge after Valentin's approval.

Copy link
Member

@Saransh-cpp Saransh-cpp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, we should deprecate these functions before making them private, given that they are visible in the API docs, but this might be fine if not a lot of users are using them. However, this should be documented in the CHANGELOG (as a breaking change) and the tests should be fixed (you can look at the logs in GH Actions to see where these functions are being used).

@Akhil-Sharma30
Copy link
Contributor Author

Akhil-Sharma30 commented Jan 22, 2024

Ideally, we should deprecate these functions before making them private, given that they are visible in the API docs, but this might be fine if not a lot of users are using them. However, this should be documented in the CHANGELOG (as a breaking change) and the tests should be fixed (you can look at the logs in GH Actions to see where these functions are being used).

Added a deprecated warning inside the function and made them public and also mentioned this in the CHANGELOG.md

@Akhil-Sharma30 Akhil-Sharma30 force-pushed the simulation_func_private branch 2 times, most recently from a2baa6b to 4672625 Compare January 22, 2024 10:30
Comment on lines 190 to 191
msg = "pybamm.simulation.set_up_and_parameterise_experiment is not meant to be accessed directly."
warn(msg, DeprecationWarning)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that not a lot of users are using these methods and we want to make them private in the next release - we could create dummy public methods that throw NameError on being invoked -

def set_up_and_parameterise_experiment(self):
    """
    A note here for users that this should not be used and is not private
    with the name _set_up_and_parameterise_experiment
    """
    raise NameError(...)

Just suggestions. We should go ahead with the strategy that most maintainers agree with.

Copy link
Contributor Author

@Akhil-Sharma30 Akhil-Sharma30 Jan 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

happy to take suggestions and do what is decided upon

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's a good idea to make them private right in the next release, since it doesn't conform to our policy of three releases – even if the popularity of this API not being relatively high is the question. Keeping them public plus raising a DeprecationWarning should be enough, a NameError sounds a bit odd IMO (I don't think we have used this before).

@arjxn-py arjxn-py self-requested a review February 12, 2024 08:47
Copy link
Member

@Saransh-cpp Saransh-cpp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for taking too long to review, but the deprecation path sounds good to me!

@@ -177,6 +178,7 @@ def _set_random_seed(self):

def set_up_and_parameterise_experiment(self):
"""
This is a helper function.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This is a helper function.

CHANGELOG.md Outdated
@@ -37,6 +37,7 @@

## Breaking changes

- Added a deprecated warning for `pybamm.Simulation.set_parameters`, `pybamm.Simulation.set_up_and_parameterise_experiment` and `pybamm.Simulation.set_up_and_parameterise_model_for_experiment` functions in `pybamm.simulation.py`. ([#3752](https://github.com/pybamm-team/PyBaMM/pull/3752))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll also need to shift it to the unreleased section

Suggested change
- Added a deprecated warning for `pybamm.Simulation.set_parameters`, `pybamm.Simulation.set_up_and_parameterise_experiment` and `pybamm.Simulation.set_up_and_parameterise_model_for_experiment` functions in `pybamm.simulation.py`. ([#3752](https://github.com/pybamm-team/PyBaMM/pull/3752))
- Deprecated `pybamm.Simulation.set_parameters`, `pybamm.Simulation.set_up_and_parameterise_experiment` and `pybamm.Simulation.set_up_and_parameterise_model_for_experiment` functions in `pybamm.simulation.py`. ([#3752](https://github.com/pybamm-team/PyBaMM/pull/3752))

@@ -11,6 +11,7 @@
from datetime import timedelta
from pybamm.util import have_optional_dependency
from typing import Optional
from warnings import warn
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpicking here, but we should keep this uniform throughout the codebase -

Suggested change
from warnings import warn
import warnings

and then warnings.warn everywhere

@@ -185,6 +187,8 @@ def set_up_and_parameterise_experiment(self):
This needs to be done here and not in the Experiment class because the nominal
cell capacity (from the parameters) is used to convert C-rate to current.
"""
msg = "pybamm.simulation.set_up_and_parameterise_experiment is not meant to be accessed directly."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
msg = "pybamm.simulation.set_up_and_parameterise_experiment is not meant to be accessed directly."
msg = "pybamm.simulation.set_up_and_parameterise_experiment is deprecated and not meant to be accessed by users"

@@ -209,12 +213,15 @@ def set_up_and_parameterise_experiment(self):

def set_up_and_parameterise_model_for_experiment(self):
"""
This is a helper function.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This is a helper function.

Set up self._model to be able to run the experiment (new version).
In this version, a new model is created for each step.

This increases set-up time since several models to be processed, but
reduces simulation time since the model formulation is efficient.
"""
msg = "pybamm.simulation.set_up_and_parameterise_model_for_experiment is not meant to be accessed directly."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
msg = "pybamm.simulation.set_up_and_parameterise_model_for_experiment is not meant to be accessed directly."
msg = "pybamm.simulation.set_up_and_parameterise_model_for_experiment is deprecated not meant to be accessed by users"

@@ -325,7 +332,8 @@ def set_parameters(self):
"""
A method to set the parameters in the model and the associated geometry.
"""

msg = "pybamm.set_paramters is meant to be accessed directly."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
msg = "pybamm.set_paramters is meant to be accessed directly."
msg = "pybamm.set_paramters is deprecated and not meant to be accessed by users"

@Saransh-cpp Saransh-cpp mentioned this pull request Feb 29, 2024
8 tasks
@Akhil-Sharma30
Copy link
Contributor Author

I am not able to reset my branch I made a mess of it. Could someone provide me instruction on how to fix this issue?

@arjxn-py
Copy link
Member

arjxn-py commented Mar 11, 2024

I am not able to reset my branch I made a mess of it. Could someone provide me instruction on how to fix this issue?

Can you provide some logs while you're trying to reset your branch?

Although assuming that you might be getting merge conflicts while trying to reset to your branch i.e. :

  • I have resolved a merge conflict in simulation.py and while doing that i have also removed import warn by mistake. Sorry, I'd now recommend you to make sure that your local working tree is clean before resetting your branch and post logs in case you're still not able to. Plus also add import warn again to fix the failing CI.

@Akhil-Sharma30
Copy link
Contributor Author

Akhil-Sharma30 commented Mar 12, 2024

I am not able to reset my branch I made a mess of it. Could someone provide me instruction on how to fix this issue?

Can you provide some logs while you're trying to reset your branch?

Although assuming that you might be getting merge conflicts while trying to reset to your branch i.e. :

  • I have resolved a merge conflict in simulation.py and while doing that i have also removed import warn by mistake. Sorry, I'd now recommend you to make sure that your local working tree is clean before resetting your branch and post logs in case you're still not able to. Plus also add import warn again to fix the failing CI.

Thanks for the help. I by mistake deleted the branch but when I was trying to bring the branch locally it was causing issue so I tried the gh pr checkout 3752 it showed me this error GraphQL: Could not resolve to a PullRequest with the number of 3752. (repository.pullRequest)

If possible could you suggest me any method to bring that branch locally again so that I can do the changes.

@Saransh-cpp
Copy link
Member

I am not very familiar with the GitHub CLI, but with git you should be able to do something like this -

git fetch --all   # fetch everything locally (there must be a way to just fetch 1 branch)
git checkout <your_branch>

@brosaplanella
Copy link
Member

Hi @Akhil-Sharma30, any updates on this?

@kratman
Copy link
Contributor

kratman commented Oct 1, 2024

@Akhil-Sharma30 This has been open for quite a while are you working on this still? If not we should close it because there have been a lot of changes to PyBaMM since this was opened

@kratman kratman added the needs-reply Needs further information from the author and may be closed if no response is received label Oct 1, 2024
@Akhil-Sharma30
Copy link
Contributor Author

@Akhil-Sharma30 This has been open for quite a while are you working on this still? If not we should close it because there have been a lot of changes to PyBaMM since this was opened

Apologize for the delay, I was busy with some work I will fix the changes in 1-2 days maximum.

@github-actions github-actions bot removed the needs-reply Needs further information from the author and may be closed if no response is received label Oct 2, 2024
@agriyakhetarpal
Copy link
Member

Could you also resolve the merge conflicts, @Akhil-Sharma30?

@Akhil-Sharma30
Copy link
Contributor Author

Could you also resolve the merge conflicts, @Akhil-Sharma30?

If possible could you guide me from where can I solve these conflict?

@kratman
Copy link
Contributor

kratman commented Oct 3, 2024

Could you also resolve the merge conflicts, @Akhil-Sharma30?

If possible could you guide me from where can I solve these conflict?

@Akhil-Sharma30 Honestly, your change is ~10 lines. It is probably easier to just redo this in a fresh PR. Just check out develop and redo the small changes

@Akhil-Sharma30
Copy link
Contributor Author

Akhil-Sharma30 commented Oct 4, 2024

Could you also resolve the merge conflicts, @Akhil-Sharma30?

If possible could you guide me from where can I solve these conflict?

@Akhil-Sharma30 Honestly, your change is ~10 lines. It is probably easier to just redo this in a fresh PR. Just check out develop and redo the small changes

Okay I have created a fresh PR for this. Just wanted to know if this pybamm.Simulation.set_up_and_parameterise_model_for_experiment func is removed from the simulation.py before a push the new PR?

@Saransh-cpp
Copy link
Member

Hi, it would be easier to open a new PR and request a review / ask your queries there. We'll be able to help you better in a fresh space. This PR is a bit too tangled now.

@Akhil-Sharma30
Copy link
Contributor Author

I have created a new PR for this fix #4489

@Saransh-cpp Saransh-cpp closed this Oct 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
7 participants