-
-
Notifications
You must be signed in to change notification settings - Fork 563
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
Make parameters importable #1475
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #1475 +/- ##
===========================================
- Coverage 98.37% 98.30% -0.07%
===========================================
Files 282 295 +13
Lines 16602 16742 +140
===========================================
+ Hits 16332 16459 +127
- Misses 270 283 +13
Continue to review full report at Codecov.
|
111c546
to
f0581c0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @priyanshuone6 , changes look good. Is there a way to test that saving and loading a sim now works in the case it didn't before?
pybamm/util.py
Outdated
|
||
# Else, search in the whole PyBaMM directory for matches | ||
if "PyBaMM" in filename: | ||
root_path = filename[filename.rfind("PyBaMM") :][7:] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe worth adding a comment explaining what this does and why?
Is it because you want to strip the full path to the module from ../PyBaMM/pybamm/input/example.py
to pybamm/input/example.py
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I'll add a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So that works if pybamm
is imported from a directory named PyBaMM
(which is indeed default when cloning from github). But what happens if pybamm
is imported from its installed location (e.g. ../site-packages/pybamm
)? This would be the case when installing PyBaMM with pip instead of importing it directly from the sources
tests/unit/test_simulation.py
Outdated
# Test load_sim for parameters imports | ||
pkl_obj = pybamm.load_sim( | ||
os.path.join( | ||
"tests", "unit", "test_parameters", "data", "test_load_param.p" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You committed the pickle file test_load_param.p
but we don't really know what it corresponds to. How about, instead, this tests saves a simulation before trying to load it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tlestang The bug is reproducible only when the pickle file is loaded afresh in a new terminal. If we'll save and then load it then the parameter will already be imported and the error won't occur.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes. Alternatively we could write the pickle from another process, something like
save_sim = "import pybamm; model = pybamm.lithium_ion.SPM(); pybamm.Simulation(model).save("test_load_param.p")"
subprocess.run("python -c {save_sim}")
Relying on the binary pickle only may make debugging hard in the future, when nobody remembers what is contains :)
Which makes me think another option is adding a comment that describes how you generated the pickle file.
@tlestang Thank you for all the suggestions, I have added the subprocess.run in the test and also tested it with the develop branch and it worked. |
59a2fdf
to
06f4ec9
Compare
Looks good @priyanshuone6 , nice one :) |
Description
sys.modules
to avoid namespace clashes.__init__.py
in parameters to convert them to modules and make them importable through pybammFixes #960
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.
Key checklist:
$ flake8
$ python run-tests.py --unit
$ cd docs
and then$ make clean; make html
You can run all three at once, using
$ python run-tests.py --quick
.Further checks: