Skip to content

Commit 847a596

Browse files
committed
Fix pre-commit configuration (#2171)
Relevant changes are only in .pre-commit-config.yaml * run black on notebooks via pre-commit * set proper line width (pyproject.toml is not used if we are running things from the repo root) * compatible line width for black + isort * fix json error in binder/overview.ipynb * re-blacken everything
1 parent 890b993 commit 847a596

File tree

82 files changed

+3426
-1250
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+3426
-1250
lines changed

.pre-commit-config.yaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ repos:
66
hooks:
77
- id: isort
88
name: isort (python)
9-
args: ["--profile", "black", "--filter-files"]
9+
args: ["--profile", "black", "--filter-files", "--line-length", "79"]
1010
- repo: https://github.com/pre-commit/pre-commit-hooks
1111
rev: v4.4.0
1212
hooks:
@@ -17,12 +17,14 @@ repos:
1717
- id: end-of-file-fixer
1818
- id: trailing-whitespace
1919
- repo: https://github.com/psf/black
20-
rev: 23.3.0
20+
rev: 23.7.0
2121
hooks:
22-
- id: black
22+
- id: black-jupyter
2323
# It is recommended to specify the latest version of Python
2424
# supported by your project here, or alternatively use
2525
# pre-commit's default_language_version, see
2626
# https://pre-commit.com/#top_level-default_language_version
2727
language_version: python3.11
28+
args: ["--line-length", "79"]
29+
2830
exclude: '^(ThirdParty|models)/'

binder/overview.ipynb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
"\n",
3535
"* [Interfacing JAX](../python/examples/example_jax/ExampleJax.ipynb)\n",
3636
"\n",
37-
" Provides guidance on how to combine AMICI with differential programming frameworks such as JAX.\n"
37+
" Provides guidance on how to combine AMICI with differential programming frameworks such as JAX.\n",
38+
"\n",
3839
"* [Efficient spline interpolation](../python/examples/example_splines/ExampleSplines.ipynb)\n",
3940
"\n",
4041
" Shows how to add annotated spline formulas to existing SBML models in order to speed up AMICI's model import.\n",

documentation/ExampleJax.ipynb

Lines changed: 57 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@
4646
"output_type": "stream",
4747
"text": [
4848
"Cloning into 'tmp/benchmark-models'...\n",
49-
"remote: Enumerating objects: 336, done.\u001B[K\n",
50-
"remote: Counting objects: 100% (336/336), done.\u001B[K\n",
51-
"remote: Compressing objects: 100% (285/285), done.\u001B[K\n",
52-
"remote: Total 336 (delta 88), reused 216 (delta 39), pack-reused 0\u001B[K\n",
49+
"remote: Enumerating objects: 336, done.\u001b[K\n",
50+
"remote: Counting objects: 100% (336/336), done.\u001b[K\n",
51+
"remote: Compressing objects: 100% (285/285), done.\u001b[K\n",
52+
"remote: Total 336 (delta 88), reused 216 (delta 39), pack-reused 0\u001b[K\n",
5353
"Receiving objects: 100% (336/336), 2.11 MiB | 7.48 MiB/s, done.\n",
5454
"Resolving deltas: 100% (88/88), done.\n"
5555
]
@@ -58,7 +58,8 @@
5858
"source": [
5959
"!git clone --depth 1 https://github.com/Benchmarking-Initiative/Benchmark-Models-PEtab.git tmp/benchmark-models || (cd tmp/benchmark-models && git pull)\n",
6060
"from pathlib import Path\n",
61-
"folder_base = Path('.') / \"tmp\" / \"benchmark-models\" / \"Benchmark-Models\""
61+
"\n",
62+
"folder_base = Path(\".\") / \"tmp\" / \"benchmark-models\" / \"Benchmark-Models\""
6263
]
6364
},
6465
{
@@ -77,6 +78,7 @@
7778
"outputs": [],
7879
"source": [
7980
"import petab\n",
81+
"\n",
8082
"model_name = \"Boehm_JProteomeRes2014\"\n",
8183
"yaml_file = folder_base / model_name / (model_name + \".yaml\")\n",
8284
"petab_problem = petab.Problem.from_yaml(yaml_file)"
@@ -570,6 +572,7 @@
570572
],
571573
"source": [
572574
"from amici.petab_import import import_petab_problem\n",
575+
"\n",
573576
"amici_model = import_petab_problem(petab_problem, force_compile=True)"
574577
]
575578
},
@@ -606,14 +609,16 @@
606609
"source": [
607610
"from amici.petab_objective import simulate_petab\n",
608611
"import amici\n",
612+
"\n",
609613
"amici_solver = amici_model.getSolver()\n",
610614
"amici_solver.setSensitivityOrder(amici.SensitivityOrder.first)\n",
611615
"\n",
616+
"\n",
612617
"def amici_hcb_base(parameters: jnp.array):\n",
613618
" return simulate_petab(\n",
614-
" petab_problem, \n",
615-
" amici_model, \n",
616-
" problem_parameters=dict(zip(petab_problem.x_free_ids, parameters)), \n",
619+
" petab_problem,\n",
620+
" amici_model,\n",
621+
" problem_parameters=dict(zip(petab_problem.x_free_ids, parameters)),\n",
617622
" scaled_parameters=True,\n",
618623
" solver=amici_solver,\n",
619624
" )"
@@ -635,13 +640,14 @@
635640
"outputs": [],
636641
"source": [
637642
"def amici_hcb_llh(parameters: jnp.array):\n",
638-
" return amici_hcb_base(parameters)['llh']\n",
643+
" return amici_hcb_base(parameters)[\"llh\"]\n",
644+
"\n",
639645
"\n",
640646
"def amici_hcb_sllh(parameters: jnp.array):\n",
641-
" sllh = amici_hcb_base(parameters)['sllh']\n",
642-
" return jnp.asarray(tuple(\n",
643-
" sllh[par_id] for par_id in petab_problem.x_free_ids\n",
644-
" ))"
647+
" sllh = amici_hcb_base(parameters)[\"sllh\"]\n",
648+
" return jnp.asarray(\n",
649+
" tuple(sllh[par_id] for par_id in petab_problem.x_free_ids)\n",
650+
" )"
645651
]
646652
},
647653
{
@@ -663,6 +669,8 @@
663669
"from jax import custom_jvp\n",
664670
"\n",
665671
"import numpy as np\n",
672+
"\n",
673+
"\n",
666674
"@custom_jvp\n",
667675
"def jax_objective(parameters: jnp.array):\n",
668676
" return hcb.call(\n",
@@ -695,7 +703,9 @@
695703
" sllh = hcb.call(\n",
696704
" amici_hcb_sllh,\n",
697705
" parameters,\n",
698-
" result_shape=jax.ShapeDtypeStruct((petab_problem.parameter_df.estimate.sum(),), np.float64),\n",
706+
" result_shape=jax.ShapeDtypeStruct(\n",
707+
" (petab_problem.parameter_df.estimate.sum(),), np.float64\n",
708+
" ),\n",
699709
" )\n",
700710
" return llh, sllh.dot(x_dot)"
701711
]
@@ -717,19 +727,25 @@
717727
"source": [
718728
"from jax import value_and_grad\n",
719729
"\n",
720-
"parameter_scales = petab_problem.parameter_df.loc[petab_problem.x_free_ids, petab.PARAMETER_SCALE].values\n",
730+
"parameter_scales = petab_problem.parameter_df.loc[\n",
731+
" petab_problem.x_free_ids, petab.PARAMETER_SCALE\n",
732+
"].values\n",
733+
"\n",
721734
"\n",
722735
"@jax.jit\n",
723736
"@value_and_grad\n",
724737
"def jax_objective_with_parameter_transform(parameters: jnp.array):\n",
725-
" par_scaled = jnp.asarray(tuple(\n",
726-
" value if scale == petab.LIN\n",
727-
" else jnp.log(value) if scale == petab.LOG\n",
728-
" else jnp.log10(value)\n",
729-
" for value, scale in zip(parameters, parameter_scales)\n",
730-
" ))\n",
731-
" return jax_objective(par_scaled)\n",
732-
" "
738+
" par_scaled = jnp.asarray(\n",
739+
" tuple(\n",
740+
" value\n",
741+
" if scale == petab.LIN\n",
742+
" else jnp.log(value)\n",
743+
" if scale == petab.LOG\n",
744+
" else jnp.log10(value)\n",
745+
" for value, scale in zip(parameters, parameter_scales)\n",
746+
" )\n",
747+
" )\n",
748+
" return jax_objective(par_scaled)"
733749
]
734750
},
735751
{
@@ -755,7 +771,9 @@
755771
"metadata": {},
756772
"outputs": [],
757773
"source": [
758-
"llh_jax, sllh_jax = jax_objective_with_parameter_transform(petab_problem.x_nominal_free)"
774+
"llh_jax, sllh_jax = jax_objective_with_parameter_transform(\n",
775+
" petab_problem.x_nominal_free\n",
776+
")"
759777
]
760778
},
761779
{
@@ -777,7 +795,9 @@
777795
"# TODO remove me as soon as sllh in simulate_petab is fixed\n",
778796
"sllh = {\n",
779797
" name: value / (np.log(10) * par_value)\n",
780-
" for (name, value), par_value in zip(r['sllh'].items(), petab_problem.x_nominal_free)\n",
798+
" for (name, value), par_value in zip(\n",
799+
" r[\"sllh\"].items(), petab_problem.x_nominal_free\n",
800+
" )\n",
781801
"}"
782802
]
783803
},
@@ -802,7 +822,8 @@
802822
],
803823
"source": [
804824
"import pandas as pd\n",
805-
"pd.Series(dict(amici=r['llh'], jax=float(llh_jax)))"
825+
"\n",
826+
"pd.Series(dict(amici=r[\"llh\"], jax=float(llh_jax)))"
806827
]
807828
},
808829
{
@@ -905,7 +926,9 @@
905926
}
906927
],
907928
"source": [
908-
"pd.DataFrame(index=sllh.keys(), data=dict(amici=sllh.values(), jax=np.asarray(sllh_jax)))"
929+
"pd.DataFrame(\n",
930+
" index=sllh.keys(), data=dict(amici=sllh.values(), jax=np.asarray(sllh_jax))\n",
931+
")"
909932
]
910933
},
911934
{
@@ -925,7 +948,9 @@
925948
"outputs": [],
926949
"source": [
927950
"jax.config.update(\"jax_enable_x64\", True)\n",
928-
"llh_jax, sllh_jax = jax_objective_with_parameter_transform(petab_problem.x_nominal_free)"
951+
"llh_jax, sllh_jax = jax_objective_with_parameter_transform(\n",
952+
" petab_problem.x_nominal_free\n",
953+
")"
929954
]
930955
},
931956
{
@@ -956,7 +981,7 @@
956981
}
957982
],
958983
"source": [
959-
"pd.Series(dict(amici=r['llh'], jax=float(llh_jax)))"
984+
"pd.Series(dict(amici=r[\"llh\"], jax=float(llh_jax)))"
960985
]
961986
},
962987
{
@@ -1059,7 +1084,9 @@
10591084
}
10601085
],
10611086
"source": [
1062-
"pd.DataFrame(index=sllh.keys(), data=dict(amici=sllh.values(), jax=np.asarray(sllh_jax)))"
1087+
"pd.DataFrame(\n",
1088+
" index=sllh.keys(), data=dict(amici=sllh.values(), jax=np.asarray(sllh_jax))\n",
1089+
")"
10631090
]
10641091
}
10651092
],

documentation/GettingStarted.ipynb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
"outputs": [],
2727
"source": [
2828
"import amici\n",
29-
"sbml_importer = amici.SbmlImporter('model_steadystate_scaled.xml')"
29+
"\n",
30+
"sbml_importer = amici.SbmlImporter(\"model_steadystate_scaled.xml\")"
3031
]
3132
},
3233
{
@@ -42,8 +43,8 @@
4243
"metadata": {},
4344
"outputs": [],
4445
"source": [
45-
"model_name = 'model_steadystate'\n",
46-
"model_dir = 'model_dir'\n",
46+
"model_name = \"model_steadystate\"\n",
47+
"model_dir = \"model_dir\"\n",
4748
"sbml_importer.sbml2amici(model_name, model_dir)"
4849
]
4950
},
@@ -82,7 +83,7 @@
8283
"metadata": {},
8384
"outputs": [],
8485
"source": [
85-
"model.setParameterByName('p1',1e-3)"
86+
"model.setParameterByName(\"p1\", 1e-3)"
8687
]
8788
},
8889
{
@@ -122,7 +123,7 @@
122123
"outputs": [],
123124
"source": [
124125
"# set timepoints\n",
125-
"model.setTimepoints([0,1])\n",
126+
"model.setTimepoints([0, 1])\n",
126127
"rdata = amici.runAmiciSimulation(model, solver)"
127128
]
128129
},

documentation/conf.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ def my_exhale_generate_doxygen(doxygen_input):
5252
DomainDirectiveFactory as breathe_DomainDirectiveFactory,
5353
)
5454

55-
old_breathe_DomainDirectiveFactory_create = breathe_DomainDirectiveFactory.create
55+
old_breathe_DomainDirectiveFactory_create = (
56+
breathe_DomainDirectiveFactory.create
57+
)
5658

5759

5860
def my_breathe_DomainDirectiveFactory_create(domain: str, args):
@@ -67,7 +69,9 @@ def my_breathe_DomainDirectiveFactory_create(domain: str, args):
6769
return cls(domain + ":" + name, *args[1:])
6870

6971

70-
breathe_DomainDirectiveFactory.create = my_breathe_DomainDirectiveFactory_create
72+
breathe_DomainDirectiveFactory.create = (
73+
my_breathe_DomainDirectiveFactory_create
74+
)
7175

7276

7377
# END Monkeypatch breathe
@@ -102,7 +106,9 @@ def install_doxygen():
102106
subprocess.run(cmd, shell=True, check=True)
103107
assert os.path.islink(os.path.join(some_dir_on_path, "doxygen"))
104108
# verify it's available
105-
res = subprocess.run(["doxygen", "--version"], check=False, capture_output=True)
109+
res = subprocess.run(
110+
["doxygen", "--version"], check=False, capture_output=True
111+
)
106112
print(res.stdout.decode(), res.stderr.decode())
107113
assert version in res.stdout.decode()
108114

@@ -176,7 +182,10 @@ def install_doxygen():
176182

177183
intersphinx_mapping = {
178184
"pysb": ("https://pysb.readthedocs.io/en/stable/", None),
179-
"petab": ("https://petab.readthedocs.io/projects/libpetab-python/en/latest/", None),
185+
"petab": (
186+
"https://petab.readthedocs.io/projects/libpetab-python/en/latest/",
187+
None,
188+
),
180189
"pandas": ("https://pandas.pydata.org/docs/", None),
181190
"numpy": ("https://numpy.org/devdocs/", None),
182191
"sympy": ("https://docs.sympy.org/latest/", None),
@@ -291,7 +300,9 @@ def install_doxygen():
291300
"verboseBuild": True,
292301
}
293302

294-
mtocpp_filter = os.path.join(amici_dir, "matlab", "mtoc", "config", "mtocpp_filter.sh")
303+
mtocpp_filter = os.path.join(
304+
amici_dir, "matlab", "mtoc", "config", "mtocpp_filter.sh"
305+
)
295306
exhale_projects_args = {
296307
"AMICI_CPP": {
297308
"exhaleDoxygenStdin": "\n".join(
@@ -504,10 +515,14 @@ def process_docstring(app, what, name, obj, options, lines):
504515
for old, new in typemaps.items():
505516
lines[i] = lines[i].replace(old, new)
506517
lines[i] = re.sub(
507-
r"amici::(Model|Solver|ExpData) ", r":class:`amici\.amici\.\1\`", lines[i]
518+
r"amici::(Model|Solver|ExpData) ",
519+
r":class:`amici\.amici\.\1\`",
520+
lines[i],
508521
)
509522
lines[i] = re.sub(
510-
r"amici::(runAmiciSimulation[s]?)", r":func:`amici\.amici\.\1`", lines[i]
523+
r"amici::(runAmiciSimulation[s]?)",
524+
r":func:`amici\.amici\.\1`",
525+
lines[i],
511526
)
512527

513528

documentation/recreate_reference_list.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ def get_sub_bibliography(year, by_year, bibfile):
4242

4343
entries = ",".join(["@" + x for x in by_year[year]])
4444
stdin_input = (
45-
"---\n" f"bibliography: {bibfile}\n" f'nocite: "{entries}"\n...\n' f"# {year}"
45+
"---\n"
46+
f"bibliography: {bibfile}\n"
47+
f'nocite: "{entries}"\n...\n'
48+
f"# {year}"
4649
)
4750

4851
out = subprocess.run(
@@ -67,7 +70,8 @@ def main():
6770
with open(outfile, "w") as f:
6871
f.write("# References\n\n")
6972
f.write(
70-
"List of publications using AMICI. " f"Total number is {num_total}.\n\n"
73+
"List of publications using AMICI. "
74+
f"Total number is {num_total}.\n\n"
7175
)
7276
f.write(
7377
"If you applied AMICI in your work and your publication is "

0 commit comments

Comments
 (0)