Skip to content

Commit

Permalink
Moving to src layout (#4311)
Browse files Browse the repository at this point in the history
* Moving to src layout

Signed-off-by: Pradyot Ranjan <[email protected]>

* Applying require changes according to src path

Signed-off-by: Pradyot Ranjan <[email protected]>

* using src/pybamm

Signed-off-by: Pradyot Ranjan <[email protected]>

* changing path of pybamm.root_dir()

Signed-off-by: Pradyot Ranjan <[email protected]>

* style: pre-commit fixes

* changing path to src/pybamm in CMakeLists.txt

Signed-off-by: Pradyot Ranjan <[email protected]>

* fixing RTD failure

Signed-off-by: Pradyot Ranjan <[email protected]>

* using pybamm.__path__[0]

Signed-off-by: Pradyot Ranjan <[email protected]>

* style: pre-commit fixes

* Update noxfile.py

Co-authored-by: Agriya Khetarpal <[email protected]>

* Fix notebook paths

---------

Signed-off-by: Pradyot Ranjan <[email protected]>
Co-authored-by: Pradyot Ranjan <[email protected]>
Co-authored-by: Arjun Verma <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Agriya Khetarpal <[email protected]>
  • Loading branch information
5 people authored Aug 8, 2024
1 parent fe6230d commit f49189c
Show file tree
Hide file tree
Showing 357 changed files with 93 additions and 97 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
!requirements*
!LICENSE.txt
!CMakeLists.txt
!pybamm/CITATIONS.bib
!pybamm/input/**/*.csv
!src/pybamm/CITATIONS.bib
!src/pybamm/input/**/*.csv
!tests/unit/test_parameters/*.csv
!benchmarks/benchmark_images/*.png

Expand Down
62 changes: 31 additions & 31 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ set(IDAKLU_EXPR_CASADI_SOURCE_FILES "")
if(${PYBAMM_IDAKLU_EXPR_CASADI} STREQUAL "ON" )
add_compile_definitions(CASADI_ENABLE)
set(IDAKLU_EXPR_CASADI_SOURCE_FILES
pybamm/solvers/c_solvers/idaklu/Expressions/Casadi/CasadiFunctions.cpp
pybamm/solvers/c_solvers/idaklu/Expressions/Casadi/CasadiFunctions.hpp
src/pybamm/solvers/c_solvers/idaklu/Expressions/Casadi/CasadiFunctions.cpp
src/pybamm/solvers/c_solvers/idaklu/Expressions/Casadi/CasadiFunctions.hpp
)
endif()

Expand All @@ -65,43 +65,43 @@ if(${PYBAMM_IDAKLU_EXPR_IREE} STREQUAL "ON" )
add_compile_definitions(IREE_ENABLE)
# Source file list
set(IDAKLU_EXPR_IREE_SOURCE_FILES
pybamm/solvers/c_solvers/idaklu/Expressions/IREE/iree_jit.cpp
pybamm/solvers/c_solvers/idaklu/Expressions/IREE/iree_jit.hpp
pybamm/solvers/c_solvers/idaklu/Expressions/IREE/IREEFunctions.cpp
pybamm/solvers/c_solvers/idaklu/Expressions/IREE/IREEFunctions.hpp
pybamm/solvers/c_solvers/idaklu/Expressions/IREE/ModuleParser.cpp
pybamm/solvers/c_solvers/idaklu/Expressions/IREE/ModuleParser.hpp
src/pybamm/solvers/c_solvers/idaklu/Expressions/IREE/iree_jit.cpp
src/pybamm/solvers/c_solvers/idaklu/Expressions/IREE/iree_jit.hpp
src/pybamm/solvers/c_solvers/idaklu/Expressions/IREE/IREEFunctions.cpp
src/pybamm/solvers/c_solvers/idaklu/Expressions/IREE/IREEFunctions.hpp
src/pybamm/solvers/c_solvers/idaklu/Expressions/IREE/ModuleParser.cpp
src/pybamm/solvers/c_solvers/idaklu/Expressions/IREE/ModuleParser.hpp
)
endif()

# The complete (all dependencies) sources list should be mirrored in setup.py
pybind11_add_module(idaklu
# pybind11 interface
pybamm/solvers/c_solvers/idaklu.cpp
src/pybamm/solvers/c_solvers/idaklu.cpp
# IDAKLU solver (SUNDIALS)
pybamm/solvers/c_solvers/idaklu/idaklu_solver.hpp
pybamm/solvers/c_solvers/idaklu/IDAKLUSolver.cpp
pybamm/solvers/c_solvers/idaklu/IDAKLUSolver.hpp
pybamm/solvers/c_solvers/idaklu/IDAKLUSolverOpenMP.inl
pybamm/solvers/c_solvers/idaklu/IDAKLUSolverOpenMP.hpp
pybamm/solvers/c_solvers/idaklu/IDAKLUSolverOpenMP_solvers.cpp
pybamm/solvers/c_solvers/idaklu/IDAKLUSolverOpenMP_solvers.hpp
pybamm/solvers/c_solvers/idaklu/sundials_functions.inl
pybamm/solvers/c_solvers/idaklu/sundials_functions.hpp
pybamm/solvers/c_solvers/idaklu/IdakluJax.cpp
pybamm/solvers/c_solvers/idaklu/IdakluJax.hpp
pybamm/solvers/c_solvers/idaklu/common.hpp
pybamm/solvers/c_solvers/idaklu/python.hpp
pybamm/solvers/c_solvers/idaklu/python.cpp
pybamm/solvers/c_solvers/idaklu/Solution.cpp
pybamm/solvers/c_solvers/idaklu/Solution.hpp
pybamm/solvers/c_solvers/idaklu/Options.hpp
pybamm/solvers/c_solvers/idaklu/Options.cpp
src/pybamm/solvers/c_solvers/idaklu/idaklu_solver.hpp
src/pybamm/solvers/c_solvers/idaklu/IDAKLUSolver.cpp
src/pybamm/solvers/c_solvers/idaklu/IDAKLUSolver.hpp
src/pybamm/solvers/c_solvers/idaklu/IDAKLUSolverOpenMP.inl
src/pybamm/solvers/c_solvers/idaklu/IDAKLUSolverOpenMP.hpp
src/pybamm/solvers/c_solvers/idaklu/IDAKLUSolverOpenMP_solvers.cpp
src/pybamm/solvers/c_solvers/idaklu/IDAKLUSolverOpenMP_solvers.hpp
src/pybamm/solvers/c_solvers/idaklu/sundials_functions.inl
src/pybamm/solvers/c_solvers/idaklu/sundials_functions.hpp
src/pybamm/solvers/c_solvers/idaklu/IdakluJax.cpp
src/pybamm/solvers/c_solvers/idaklu/IdakluJax.hpp
src/pybamm/solvers/c_solvers/idaklu/common.hpp
src/pybamm/solvers/c_solvers/idaklu/python.hpp
src/pybamm/solvers/c_solvers/idaklu/python.cpp
src/pybamm/solvers/c_solvers/idaklu/Solution.cpp
src/pybamm/solvers/c_solvers/idaklu/Solution.hpp
src/pybamm/solvers/c_solvers/idaklu/Options.hpp
src/pybamm/solvers/c_solvers/idaklu/Options.cpp
# IDAKLU expressions / function evaluation [abstract]
pybamm/solvers/c_solvers/idaklu/Expressions/Expressions.hpp
pybamm/solvers/c_solvers/idaklu/Expressions/Base/Expression.hpp
pybamm/solvers/c_solvers/idaklu/Expressions/Base/ExpressionSet.hpp
pybamm/solvers/c_solvers/idaklu/Expressions/Base/ExpressionTypes.hpp
src/pybamm/solvers/c_solvers/idaklu/Expressions/Expressions.hpp
src/pybamm/solvers/c_solvers/idaklu/Expressions/Base/Expression.hpp
src/pybamm/solvers/c_solvers/idaklu/Expressions/Base/ExpressionSet.hpp
src/pybamm/solvers/c_solvers/idaklu/Expressions/Base/ExpressionTypes.hpp
# IDAKLU expressions - concrete implementations
${IDAKLU_EXPR_CASADI_SOURCE_FILES}
${IDAKLU_EXPR_IREE_SOURCE_FILES}
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ We use [GIT](https://en.wikipedia.org/wiki/Git) and [GitHub](https://en.wikipedi
2. Create a [branch](https://help.github.com/articles/creating-and-deleting-branches-within-your-repository/) of this repo (ideally on your own [fork](https://help.github.com/articles/fork-a-repo/)), where all changes will be made
3. Download the source code onto your local system, by [cloning](https://help.github.com/articles/cloning-a-repository/) the repository (or your fork of the repository).
4. [Install](https://docs.pybamm.org/en/latest/source/user_guide/installation/install-from-source.html) PyBaMM with the developer options.
5. [Test](#testing) if your installation worked, using the test script: `$ python run-tests.py --unit`.
5. [Test](#testing) if your installation worked, using pytest: `$ pytest -m unit`.

You now have everything you need to start making changes!

Expand Down Expand Up @@ -405,7 +405,7 @@ pybamm.print_citations()
to the end of a script will print all citations that were used by that script. This will print BibTeX information to the terminal; passing a filename to `print_citations` will print the BibTeX information to the specified file instead.
When you contribute code to PyBaMM, you can add your own papers that you would like to be cited if that code is used. First, add the BibTeX for your paper to [CITATIONS.bib](https://github.com/pybamm-team/PyBaMM/blob/develop/pybamm/CITATIONS.bib). Then, add the line
When you contribute code to PyBaMM, you can add your own papers that you would like to be cited if that code is used. First, add the BibTeX for your paper to [CITATIONS.bib](https://github.com/pybamm-team/PyBaMM/blob/develop/src/pybamm/CITATIONS.bib). Then, add the line
```python3
pybamm.citations.register("your_paper_bibtex_identifier")
Expand Down
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
graft pybamm
graft src
include CITATION.cff
prune tests

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ We would be grateful if you could also cite the relevant papers. These will chan
pybamm.print_citations()
```

to the end of your script. This will print BibTeX information to the terminal; passing a filename to `print_citations` will print the BibTeX information to the specified file instead. A list of all citations can also be found in the [citations file](https://github.com/pybamm-team/PyBaMM/blob/develop/pybamm/CITATIONS.bib). In particular, PyBaMM relies heavily on [CasADi](https://web.casadi.org/publications/).
to the end of your script. This will print BibTeX information to the terminal; passing a filename to `print_citations` will print the BibTeX information to the specified file instead. A list of all citations can also be found in the [citations file](https://github.com/pybamm-team/PyBaMM/blob/develop/src/pybamm/CITATIONS.bib). In particular, PyBaMM relies heavily on [CasADi](https://web.casadi.org/publications/).
See [CONTRIBUTING.md](https://github.com/pybamm-team/PyBaMM/blob/develop/CONTRIBUTING.md#citations) for information on how to add your own citations when you contribute.

## 🛠️ Contributing to PyBaMM
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@

# -- sphinxcontrib-bibtex configuration --------------------------------------

bibtex_bibfiles = ["../pybamm/CITATIONS.bib"]
bibtex_bibfiles = ["../src/pybamm/CITATIONS.bib"]
bibtex_style = "unsrt"
bibtex_footbibliography_header = """.. rubric:: References"""
bibtex_reference_style = "author_year"
Expand Down
5 changes: 2 additions & 3 deletions docs/source/examples/notebooks/models/SPM.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,7 @@
"variable = list(model.rhs.keys())[1]\n",
"equation = list(model.rhs.values())[1]\n",
"print(\"rhs equation for variable '\", variable, \"' is:\")\n",
"path = \"docs/source/examples/notebooks/models/\"\n",
"equation.visualise(path + \"spm1.png\")"
"equation.visualise(\"spm1.png\")"
]
},
{
Expand Down Expand Up @@ -383,7 +382,7 @@
"metadata": {},
"outputs": [],
"source": [
"model.concatenated_rhs.children[1].visualise(path + \"spm2.png\")"
"model.concatenated_rhs.children[1].visualise(\"spm2.png\")"
]
},
{
Expand Down
2 changes: 0 additions & 2 deletions examples/scripts/drive_cycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
#
import pybamm
import pandas as pd
import os

os.chdir(pybamm.__path__[0] + "/..")

pybamm.set_logging_level("INFO")

Expand Down
2 changes: 0 additions & 2 deletions examples/scripts/experiment_drive_cycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
#
import pybamm
import pandas as pd
import os

os.chdir(pybamm.__path__[0] + "/..")

pybamm.set_logging_level("INFO")

Expand Down
2 changes: 1 addition & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def run_doctests(session):
"-m",
"pytest",
"--doctest-plus",
"pybamm",
"src",
)


Expand Down
9 changes: 4 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,12 @@ pybamm = [
"*.md",
"*.csv",
"*.py",
"pybamm/CITATIONS.bib",
"pybamm/plotting/mplstyle",
"src/pybamm/CITATIONS.bib",
"src/pybamm/plotting/mplstyle",
]

[tool.setuptools.packages.find]
include = ["pybamm", "pybamm.*"]

where = ["src"]
[tool.ruff]
extend-include = ["*.ipynb"]
extend-exclude = ["__init__.py"]
Expand Down Expand Up @@ -264,7 +263,7 @@ log_format = "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
log_date_format = "%Y-%m-%d %H:%M:%S"

[tool.coverage.run]
source = ["pybamm"]
source = ["src/pybamm"]
concurrency = ["multiprocessing"]

[tool.repo-review]
Expand Down
4 changes: 3 additions & 1 deletion scripts/update_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ def update_version():
)

# pybamm/version.py
with open(os.path.join(pybamm.root_dir(), "pybamm", "version.py"), "r+") as file:
with open(
os.path.join(pybamm.root_dir(), "src", "pybamm", "version.py"), "r+"
) as file:
output = file.read()
replace_version = re.sub(
'(?<=__version__ = ")(.+)(?=")', release_version, output
Expand Down
68 changes: 34 additions & 34 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,40 +295,40 @@ def compile_KLU():
name="pybamm.solvers.idaklu",
# The sources list should mirror the list in CMakeLists.txt
sources=[
"pybamm/solvers/c_solvers/idaklu/Expressions/Expressions.hpp",
"pybamm/solvers/c_solvers/idaklu/Expressions/Base/Expression.hpp",
"pybamm/solvers/c_solvers/idaklu/Expressions/Base/ExpressionSet.hpp",
"pybamm/solvers/c_solvers/idaklu/Expressions/Base/ExpressionTypes.hpp",
"pybamm/solvers/c_solvers/idaklu/Expressions/Base/ExpressionSparsity.hpp",
"pybamm/solvers/c_solvers/idaklu/Expressions/Casadi/CasadiFunctions.cpp",
"pybamm/solvers/c_solvers/idaklu/Expressions/Casadi/CasadiFunctions.hpp",
"pybamm/solvers/c_solvers/idaklu/Expressions/IREE/IREEBaseFunction.hpp",
"pybamm/solvers/c_solvers/idaklu/Expressions/IREE/IREEFunction.hpp",
"pybamm/solvers/c_solvers/idaklu/Expressions/IREE/IREEFunctions.cpp",
"pybamm/solvers/c_solvers/idaklu/Expressions/IREE/IREEFunctions.hpp",
"pybamm/solvers/c_solvers/idaklu/Expressions/IREE/iree_jit.cpp",
"pybamm/solvers/c_solvers/idaklu/Expressions/IREE/iree_jit.hpp",
"pybamm/solvers/c_solvers/idaklu/Expressions/IREE/ModuleParser.cpp",
"pybamm/solvers/c_solvers/idaklu/Expressions/IREE/ModuleParser.hpp",
"pybamm/solvers/c_solvers/idaklu/idaklu_solver.hpp",
"pybamm/solvers/c_solvers/idaklu/IDAKLUSolver.cpp",
"pybamm/solvers/c_solvers/idaklu/IDAKLUSolver.hpp",
"pybamm/solvers/c_solvers/idaklu/IDAKLUSolverOpenMP.inl",
"pybamm/solvers/c_solvers/idaklu/IDAKLUSolverOpenMP.hpp",
"pybamm/solvers/c_solvers/idaklu/IDAKLUSolverOpenMP_solvers.cpp",
"pybamm/solvers/c_solvers/idaklu/IDAKLUSolverOpenMP_solvers.hpp",
"pybamm/solvers/c_solvers/idaklu/sundials_functions.inl",
"pybamm/solvers/c_solvers/idaklu/sundials_functions.hpp",
"pybamm/solvers/c_solvers/idaklu/IdakluJax.cpp",
"pybamm/solvers/c_solvers/idaklu/IdakluJax.hpp",
"pybamm/solvers/c_solvers/idaklu/common.hpp",
"pybamm/solvers/c_solvers/idaklu/python.hpp",
"pybamm/solvers/c_solvers/idaklu/python.cpp",
"pybamm/solvers/c_solvers/idaklu/Solution.cpp",
"pybamm/solvers/c_solvers/idaklu/Solution.hpp",
"pybamm/solvers/c_solvers/idaklu/Options.hpp",
"pybamm/solvers/c_solvers/idaklu/Options.cpp",
"pybamm/solvers/c_solvers/idaklu.cpp",
"src/pybamm/solvers/c_solvers/idaklu/Expressions/Expressions.hpp",
"src/pybamm/solvers/c_solvers/idaklu/Expressions/Base/Expression.hpp",
"src/pybamm/solvers/c_solvers/idaklu/Expressions/Base/ExpressionSet.hpp",
"src/pybamm/solvers/c_solvers/idaklu/Expressions/Base/ExpressionTypes.hpp",
"src/pybamm/solvers/c_solvers/idaklu/Expressions/Base/ExpressionSparsity.hpp",
"src/pybamm/solvers/c_solvers/idaklu/Expressions/Casadi/CasadiFunctions.cpp",
"src/pybamm/solvers/c_solvers/idaklu/Expressions/Casadi/CasadiFunctions.hpp",
"src/pybamm/solvers/c_solvers/idaklu/Expressions/IREE/IREEBaseFunction.hpp",
"src/pybamm/solvers/c_solvers/idaklu/Expressions/IREE/IREEFunction.hpp",
"src/pybamm/solvers/c_solvers/idaklu/Expressions/IREE/IREEFunctions.cpp",
"src/pybamm/solvers/c_solvers/idaklu/Expressions/IREE/IREEFunctions.hpp",
"src/pybamm/solvers/c_solvers/idaklu/Expressions/IREE/iree_jit.cpp",
"src/pybamm/solvers/c_solvers/idaklu/Expressions/IREE/iree_jit.hpp",
"src/pybamm/solvers/c_solvers/idaklu/Expressions/IREE/ModuleParser.cpp",
"src/pybamm/solvers/c_solvers/idaklu/Expressions/IREE/ModuleParser.hpp",
"src/pybamm/solvers/c_solvers/idaklu/idaklu_solver.hpp",
"src/pybamm/solvers/c_solvers/idaklu/IDAKLUSolver.cpp",
"src/pybamm/solvers/c_solvers/idaklu/IDAKLUSolver.hpp",
"src/pybamm/solvers/c_solvers/idaklu/IDAKLUSolverOpenMP.inl",
"src/pybamm/solvers/c_solvers/idaklu/IDAKLUSolverOpenMP.hpp",
"src/pybamm/solvers/c_solvers/idaklu/IDAKLUSolverOpenMP_solvers.cpp",
"src/pybamm/solvers/c_solvers/idaklu/IDAKLUSolverOpenMP_solvers.hpp",
"src/pybamm/solvers/c_solvers/idaklu/sundials_functions.inl",
"src/pybamm/solvers/c_solvers/idaklu/sundials_functions.hpp",
"src/pybamm/solvers/c_solvers/idaklu/IdakluJax.cpp",
"src/pybamm/solvers/c_solvers/idaklu/IdakluJax.hpp",
"src/pybamm/solvers/c_solvers/idaklu/common.hpp",
"src/pybamm/solvers/c_solvers/idaklu/python.hpp",
"src/pybamm/solvers/c_solvers/idaklu/python.cpp",
"src/pybamm/solvers/c_solvers/idaklu/Solution.cpp",
"src/pybamm/solvers/c_solvers/idaklu/Solution.hpp",
"src/pybamm/solvers/c_solvers/idaklu/Options.hpp",
"src/pybamm/solvers/c_solvers/idaklu/Options.cpp",
"src/pybamm/solvers/c_solvers/idaklu.cpp",
],
)
ext_modules = [idaklu_ext] if compile_KLU() else []
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion pybamm/citations.py → src/pybamm/citations.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def read_citations(self):
"""
try:
parse_file = import_optional_dependency("pybtex.database", "parse_file")
citations_file = os.path.join(pybamm.root_dir(), "pybamm", "CITATIONS.bib")
citations_file = os.path.join(pybamm.__path__[0], "CITATIONS.bib")
bib_data = parse_file(citations_file, bib_format="bibtex")
for key, entry in bib_data.entries.items():
self._add_citation(key, entry)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit f49189c

Please sign in to comment.