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

chore: cleanup mypy config #3853

Draft
wants to merge 8 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ a63e49ece0f9336d1f5c2562f7459e555c6e6693
ff6d81c01331c7d269303b4a8321d9881bdf98fa
# migrated to ruff-format - https://github.com/pybamm-team/PyBaMM/pull/3655
60ebd4148059a95428a496f4f55c1175ead362d3
# activated isort - https://github.com/pybamm-team/PyBaMM/pull/3853
36e6c5a5a36976591275ed4de700dc1b27567ba1
9 changes: 9 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,12 @@ repos:
- id: rst-backticks
- id: rst-directive-colons
- id: rst-inline-touching-normal

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.8.0
hooks:
- id: mypy
files: pybamm
additional_dependencies:
- numpy
- packaging
2 changes: 2 additions & 0 deletions benchmarks/benchmark_utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import numpy as np


Expand Down
5 changes: 4 additions & 1 deletion benchmarks/different_model_options.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from __future__ import annotations

import numpy as np

import pybamm
from benchmarks.benchmark_utils import set_random_seed
import numpy as np


def compute_discretisation(model, param):
Expand Down
2 changes: 2 additions & 0 deletions benchmarks/memory_sims.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import pybamm
from benchmarks.benchmark_utils import set_random_seed

Expand Down
5 changes: 4 additions & 1 deletion benchmarks/memory_unit_benchmarks.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from __future__ import annotations

import numpy as np

import pybamm
from benchmarks.benchmark_utils import set_random_seed
import numpy as np


class MemCreateExpression:
Expand Down
2 changes: 2 additions & 0 deletions benchmarks/time_setup_models_and_sims.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import pybamm
from benchmarks.benchmark_utils import set_random_seed

Expand Down
2 changes: 2 additions & 0 deletions benchmarks/time_sims_experiments.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import pybamm
from benchmarks.benchmark_utils import set_random_seed

Expand Down
4 changes: 3 additions & 1 deletion benchmarks/time_solve_models.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# Write the benchmarking functions here.
# See "Writing benchmarks" in the asv docs for more information.
from __future__ import annotations

import numpy as np

import pybamm
from benchmarks.benchmark_utils import set_random_seed
import numpy as np


def solve_model_once(model, solver, t_eval):
Expand Down
5 changes: 4 additions & 1 deletion benchmarks/unit_benchmarks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import pybamm
from __future__ import annotations

import numpy as np

import pybamm
from benchmarks.benchmark_utils import set_random_seed


Expand Down
9 changes: 6 additions & 3 deletions benchmarks/work_precision_sets/time_vs_abstols.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import pybamm
import numpy as np
import matplotlib.pyplot as plt
from __future__ import annotations

import itertools

import matplotlib.pyplot as plt
import numpy as np

import pybamm

parameters = ["Marquis2019", "Ecker2015", "Ramadass2004", "Chen2020"]

Expand Down
6 changes: 4 additions & 2 deletions benchmarks/work_precision_sets/time_vs_dt_max.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import pybamm
import numpy as np
from __future__ import annotations

import matplotlib.pyplot as plt
import numpy as np

import pybamm

parameters = [
"Marquis2019",
Expand Down
6 changes: 4 additions & 2 deletions benchmarks/work_precision_sets/time_vs_mesh_size.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import pybamm
from __future__ import annotations

import matplotlib.pyplot as plt
import itertools

import matplotlib.pyplot as plt

import pybamm

parameters = [
"Marquis2019",
Expand Down
7 changes: 5 additions & 2 deletions benchmarks/work_precision_sets/time_vs_no_of_states.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import pybamm
import matplotlib.pyplot as plt
from __future__ import annotations

import itertools

import matplotlib.pyplot as plt

import pybamm

parameters = [
"Marquis2019",
Expand Down
9 changes: 6 additions & 3 deletions benchmarks/work_precision_sets/time_vs_reltols.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import pybamm
import numpy as np
import matplotlib.pyplot as plt
from __future__ import annotations

import itertools

import matplotlib.pyplot as plt
import numpy as np

import pybamm

parameters = [
"Marquis2019",
Expand Down
3 changes: 3 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
from __future__ import annotations

import os
import sys

import pybamm

# Path for repository root
Expand Down
2 changes: 2 additions & 0 deletions docs/source/examples/notebooks/batch_study.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
}
],
"source": [
"from __future__ import annotations\n",
"\n",
"%pip install \"pybamm[plot,cite]\" -q # install PyBaMM if it is not installed\n",
"import pybamm\n",
"\n",
Expand Down
8 changes: 6 additions & 2 deletions docs/source/examples/notebooks/change-settings.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,15 @@
}
],
"source": [
"from __future__ import annotations\n",
"\n",
"%pip install \"pybamm[plot,cite]\" -q # install PyBaMM if it is not installed\n",
"import pybamm\n",
"import numpy as np\n",
"import os\n",
"\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
"import pybamm\n",
"\n",
"os.chdir(pybamm.__path__[0] + \"/..\")\n",
"\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,13 @@
}
],
"source": [
"from __future__ import annotations\n",
"\n",
"%pip install \"pybamm[plot,cite]\" -q # install PyBaMM if it is not installed\n",
"import pybamm\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt"
"\n",
"import pybamm"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,13 @@
}
],
"source": [
"from __future__ import annotations\n",
"\n",
"%pip install \"pybamm[plot,cite]\" -q # install PyBaMM if it is not installed\n",
"import pybamm\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt"
"\n",
"import pybamm"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,13 @@
}
],
"source": [
"from __future__ import annotations\n",
"\n",
"%pip install \"pybamm[plot,cite]\" -q # install PyBaMM if it is not installed\n",
"import pybamm\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
"import pybamm\n",
"\n",
"model = pybamm.BaseModel()"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,13 @@
}
],
"source": [
"from __future__ import annotations\n",
"\n",
"%pip install \"pybamm[plot,cite]\" -q # install PyBaMM if it is not installed\n",
"import pybamm\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
"import pybamm\n",
"\n",
"full_model = pybamm.BaseModel(name=\"full model\")\n",
"reduced_model = pybamm.BaseModel(name=\"reduced model\")"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,13 @@
}
],
"source": [
"from __future__ import annotations\n",
"\n",
"%pip install \"pybamm[plot,cite]\" -q # install PyBaMM if it is not installed\n",
"import pybamm\n",
"import numpy as np\n",
"\n",
"import pybamm\n",
"\n",
"model = pybamm.BaseModel()"
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,15 @@
}
],
"source": [
"from __future__ import annotations\n",
"\n",
"%pip install \"pybamm[plot,cite]\" -q # install PyBaMM if it is not installed\n",
"import pybamm\n",
"import numpy as np\n",
"import os\n",
"\n",
"import numpy as np\n",
"\n",
"import pybamm\n",
"\n",
"os.chdir(pybamm.__path__[0] + \"/..\")"
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@
}
],
"source": [
"from __future__ import annotations\n",
"\n",
"%pip install \"pybamm[plot,cite]\" -q # install PyBaMM if it is not installed\n",
"import pybamm\n",
"import numpy as np"
"import numpy as np\n",
"\n",
"import pybamm"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,13 @@
}
],
"source": [
"from __future__ import annotations\n",
"\n",
"%pip install \"pybamm[plot,cite]\" -q # install PyBaMM if it is not installed\n",
"import pybamm\n",
"import numpy as np\n",
"\n",
"import pybamm\n",
"\n",
"y = pybamm.StateVector(slice(0, 1))\n",
"t = pybamm.t\n",
"equation = 2 * y * (1 - y) + t\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
}
],
"source": [
"from __future__ import annotations\n",
"\n",
"%pip install \"pybamm[plot,cite]\" -q # install PyBaMM if it is not installed\n",
"import pybamm"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
}
],
"source": [
"from __future__ import annotations\n",
"\n",
"%pip install \"pybamm[plot,cite]\" -q # install PyBaMM if it is not installed\n",
"import pybamm"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
"metadata": {},
"outputs": [],
"source": [
"from __future__ import annotations\n",
"\n",
"%pip install \"pybamm[plot,cite]\" -q # install PyBaMM if it is not installed\n",
"import pybamm"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
}
],
"source": [
"from __future__ import annotations\n",
"\n",
"%pip install \"pybamm[plot,cite]\" -q # install PyBaMM if it is not installed\n",
"import pybamm"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,13 @@
}
],
"source": [
"from __future__ import annotations\n",
"\n",
"%pip install \"pybamm[plot,cite]\" -q # install PyBaMM if it is not installed\n",
"import pybamm\n",
"import matplotlib.pyplot as plt\n",
"\n",
"import pybamm\n",
"\n",
"model_dfn = pybamm.lithium_ion.DFN()\n",
"sim_dfn = pybamm.Simulation(model_dfn)\n",
"sim_dfn.solve([0, 3600])"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,13 @@
}
],
"source": [
"from __future__ import annotations\n",
"\n",
"%pip install \"pybamm[plot,cite]\" -q # install PyBaMM if it is not installed\n",
"import pybamm\n",
"import os\n",
"\n",
"import pybamm\n",
"\n",
"os.chdir(pybamm.__path__[0] + \"/..\")"
]
},
Expand Down