Skip to content

Commit

Permalink
Add pre-commit and ruff config (#73)
Browse files Browse the repository at this point in the history
Closes #72
  • Loading branch information
dweindl authored Jul 1, 2024
1 parent 7ddd3da commit 0f34f23
Show file tree
Hide file tree
Showing 88 changed files with 2,813 additions and 1,942 deletions.
2 changes: 1 addition & 1 deletion .ci_pip_reqs.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pytest
flake8
ruff
git+https://github.com/PEtab-dev/libpetab-python@develop
sympy>=1.12.1
9 changes: 4 additions & 5 deletions .github/workflows/ci_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@ jobs:
run: |
python -m pip install --upgrade pip wheel
pip install -e .
# uninstall, otherwise git+... installation from .ci_pip_reqs.txt won't do anything
pip uninstall -y petab
pip install -r .ci_pip_reqs.txt
- name: Check style
run: ruff check
- name: Run tests
run: |
python -m flake8 \
--exclude=build,doc,tmp,_model.py,conversion_modified_pysb.py,conversion_pysb.py \
--extend-ignore=F403,F405
pytest test
run: pytest test
30 changes: 30 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
exclude: |
(?x)^(
petabtests/cases/.*\.(md|tsv)|
petabtests/cases/.*/_model\.py|
petabtests/cases/.*/conversion_modified_pysb\.py|
cases/.*
)$
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: check-added-large-files
- id: check-merge-conflict
- id: check-yaml
args: [--allow-multiple-documents]
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.5.0
hooks:
# Run the linter.
- id: ruff
args:
- --fix

# Run the formatter.
- id: ruff-format
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ The PEtab test suite can be downloaded from GitHub via

git clone https://github.com/petab-dev/petab_test_suite

The test suite comes with all necessary files pregenerated.
The test suite comes with all necessary files pregenerated.
In the [petabtests](petabtests) subdirectory, it contains a python module for
generating the tests and evaluating results. This can be installed via

Expand All @@ -25,7 +25,7 @@ of enumerated tests.
Each test contains a descriptive `wxyz.md` file, and a script file `wxyz.py`
file that can be used to generate all problem and solution files for the test.
The necessary files are in the same case-specific folder, starting with an
underscore.
underscore.
In each case folder, there is a file `_wxyz.yaml` containing the parameter
estimation problem description, and a file `_wxyz_solution.yaml` containing
information on the expected results: chi2 value, log-likelihood, simulation
Expand Down
20 changes: 10 additions & 10 deletions petabtests/C.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
# paths
BASE_DIR = Path(__file__).parent

CASES_DIR = BASE_DIR / 'cases'
CASES_DIR = BASE_DIR / "cases"

DEFAULT_SBML_FILE = BASE_DIR / 'conversion.xml'
DEFAULT_PYSB_FILE = BASE_DIR / 'conversion_pysb.py'
DEFAULT_SBML_FILE = BASE_DIR / "conversion.xml"
DEFAULT_PYSB_FILE = BASE_DIR / "conversion_pysb.py"

# constants

LLH = 'llh'
CHI2 = 'chi2'
SIMULATION_DFS = 'simulation_dfs'
SIMULATION_FILES = 'simulation_files'
LLH = "llh"
CHI2 = "chi2"
SIMULATION_DFS = "simulation_dfs"
SIMULATION_FILES = "simulation_files"

TOL_SIMULATIONS = 'tol_simulations'
TOL_CHI2 = 'tol_chi2'
TOL_LLH = 'tol_llh'
TOL_SIMULATIONS = "tol_simulations"
TOL_CHI2 = "tol_chi2"
TOL_LLH = "tol_llh"
60 changes: 35 additions & 25 deletions petabtests/cases/v1.0.0/sbml/0001/0001.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,38 +19,48 @@

# problem --------------------------------------------------------------------

condition_df = pd.DataFrame(data={
CONDITION_ID: ['c0'],
}).set_index([CONDITION_ID])
condition_df = pd.DataFrame(
data={
CONDITION_ID: ["c0"],
}
).set_index([CONDITION_ID])

measurement_df = pd.DataFrame(data={
OBSERVABLE_ID: ['obs_a', 'obs_a'],
SIMULATION_CONDITION_ID: ['c0', 'c0'],
TIME: [0, 10],
MEASUREMENT: [0.7, 0.1]
})
measurement_df = pd.DataFrame(
data={
OBSERVABLE_ID: ["obs_a", "obs_a"],
SIMULATION_CONDITION_ID: ["c0", "c0"],
TIME: [0, 10],
MEASUREMENT: [0.7, 0.1],
}
)

observable_df = pd.DataFrame(data={
OBSERVABLE_ID: ['obs_a'],
OBSERVABLE_FORMULA: ['A'],
NOISE_FORMULA: [0.5]
}).set_index([OBSERVABLE_ID])
observable_df = pd.DataFrame(
data={
OBSERVABLE_ID: ["obs_a"],
OBSERVABLE_FORMULA: ["A"],
NOISE_FORMULA: [0.5],
}
).set_index([OBSERVABLE_ID])

parameter_df = pd.DataFrame(data={
PARAMETER_ID: ['a0', 'b0', 'k1', 'k2'],
PARAMETER_SCALE: [LIN] * 4,
LOWER_BOUND: [0] * 4,
UPPER_BOUND: [10] * 4,
NOMINAL_VALUE: [1, 0, 0.8, 0.6],
ESTIMATE: [1] * 4,
}).set_index(PARAMETER_ID)
parameter_df = pd.DataFrame(
data={
PARAMETER_ID: ["a0", "b0", "k1", "k2"],
PARAMETER_SCALE: [LIN] * 4,
LOWER_BOUND: [0] * 4,
UPPER_BOUND: [10] * 4,
NOMINAL_VALUE: [1, 0, 0.8, 0.6],
ESTIMATE: [1] * 4,
}
).set_index(PARAMETER_ID)

# solutions ------------------------------------------------------------------

simulation_df = measurement_df.copy(deep=True).rename(
columns={MEASUREMENT: SIMULATION})
simulation_df[SIMULATION] = [analytical_a(t, 1, 0, 0.8, 0.6)
for t in simulation_df[TIME]]
columns={MEASUREMENT: SIMULATION}
)
simulation_df[SIMULATION] = [
analytical_a(t, 1, 0, 0.8, 0.6) for t in simulation_df[TIME]
]


case = PetabTestCase(
Expand Down
73 changes: 41 additions & 32 deletions petabtests/cases/v1.0.0/sbml/0002/0002.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,42 +25,51 @@

# problem --------------------------------------------------------------------

condition_df = pd.DataFrame(data={
CONDITION_ID: ['c0', 'c1'],
'a0': [0.8, 0.9],
'b0': [nan, nan],
}).set_index([CONDITION_ID])

measurement_df = pd.DataFrame(data={
OBSERVABLE_ID: ['obs_a'] * 4,
SIMULATION_CONDITION_ID: ['c0', 'c0', 'c1', 'c1'],
TIME: [0, 10, 0, 10],
MEASUREMENT: [0.7, 0.1, 0.8, 0.2]
})

observable_df = pd.DataFrame(data={
OBSERVABLE_ID: ['obs_a'],
OBSERVABLE_FORMULA: ['A'],
NOISE_FORMULA: [1]
}).set_index([OBSERVABLE_ID])

parameter_df = pd.DataFrame(data={
PARAMETER_ID: ['k1', 'k2'],
PARAMETER_SCALE: [LIN] * 2,
LOWER_BOUND: [0] * 2,
UPPER_BOUND: [10] * 2,
NOMINAL_VALUE: [0.8, 0.6],
ESTIMATE: [1] * 2,
}).set_index(PARAMETER_ID)
condition_df = pd.DataFrame(
data={
CONDITION_ID: ["c0", "c1"],
"a0": [0.8, 0.9],
"b0": [nan, nan],
}
).set_index([CONDITION_ID])

measurement_df = pd.DataFrame(
data={
OBSERVABLE_ID: ["obs_a"] * 4,
SIMULATION_CONDITION_ID: ["c0", "c0", "c1", "c1"],
TIME: [0, 10, 0, 10],
MEASUREMENT: [0.7, 0.1, 0.8, 0.2],
}
)

observable_df = pd.DataFrame(
data={
OBSERVABLE_ID: ["obs_a"],
OBSERVABLE_FORMULA: ["A"],
NOISE_FORMULA: [1],
}
).set_index([OBSERVABLE_ID])

parameter_df = pd.DataFrame(
data={
PARAMETER_ID: ["k1", "k2"],
PARAMETER_SCALE: [LIN] * 2,
LOWER_BOUND: [0] * 2,
UPPER_BOUND: [10] * 2,
NOMINAL_VALUE: [0.8, 0.6],
ESTIMATE: [1] * 2,
}
).set_index(PARAMETER_ID)

# solutions ------------------------------------------------------------------

simulation_df = measurement_df.copy(deep=True).rename(
columns={MEASUREMENT: SIMULATION})
simulation_df[SIMULATION] = [*[analytical_a(t, 0.8, 1, 0.8, 0.6)
for t in [0, 10]],
*[analytical_a(t, 0.9, 1, 0.8, 0.6)
for t in [0, 10]]]
columns={MEASUREMENT: SIMULATION}
)
simulation_df[SIMULATION] = [
*[analytical_a(t, 0.8, 1, 0.8, 0.6) for t in [0, 10]],
*[analytical_a(t, 0.9, 1, 0.8, 0.6) for t in [0, 10]],
]

case = PetabTestCase(
id=2,
Expand Down
67 changes: 39 additions & 28 deletions petabtests/cases/v1.0.0/sbml/0003/0003.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,45 +25,56 @@

# problem --------------------------------------------------------------------

condition_df = pd.DataFrame(data={
CONDITION_ID: ['c0'],
}).set_index([CONDITION_ID])
condition_df = pd.DataFrame(
data={
CONDITION_ID: ["c0"],
}
).set_index([CONDITION_ID])

measurement_df = pd.DataFrame(data={
OBSERVABLE_ID: ['obs_a', 'obs_a'],
SIMULATION_CONDITION_ID: ['c0', 'c0'],
TIME: [0, 10],
MEASUREMENT: [0.7, 0.1],
OBSERVABLE_PARAMETERS: ['0.5;2', '0.5;2']
})
measurement_df = pd.DataFrame(
data={
OBSERVABLE_ID: ["obs_a", "obs_a"],
SIMULATION_CONDITION_ID: ["c0", "c0"],
TIME: [0, 10],
MEASUREMENT: [0.7, 0.1],
OBSERVABLE_PARAMETERS: ["0.5;2", "0.5;2"],
}
)

observable_df = pd.DataFrame(data={
OBSERVABLE_ID: ['obs_a'],
OBSERVABLE_FORMULA: ['observableParameter1_obs_a * A + '
'observableParameter2_obs_a'],
NOISE_FORMULA: [0.5]
}).set_index([OBSERVABLE_ID])
observable_df = pd.DataFrame(
data={
OBSERVABLE_ID: ["obs_a"],
OBSERVABLE_FORMULA: [
"observableParameter1_obs_a * A + " "observableParameter2_obs_a"
],
NOISE_FORMULA: [0.5],
}
).set_index([OBSERVABLE_ID])

parameter_df = pd.DataFrame(data={
PARAMETER_ID: ['a0', 'b0', 'k1', 'k2'],
PARAMETER_SCALE: [LIN] * 4,
LOWER_BOUND: [0] * 4,
UPPER_BOUND: [10] * 4,
NOMINAL_VALUE: [1, 0, 0.8, 0.6],
ESTIMATE: [1] * 4,
}).set_index(PARAMETER_ID)
parameter_df = pd.DataFrame(
data={
PARAMETER_ID: ["a0", "b0", "k1", "k2"],
PARAMETER_SCALE: [LIN] * 4,
LOWER_BOUND: [0] * 4,
UPPER_BOUND: [10] * 4,
NOMINAL_VALUE: [1, 0, 0.8, 0.6],
ESTIMATE: [1] * 4,
}
).set_index(PARAMETER_ID)

# solutions ------------------------------------------------------------------

simulation_df = measurement_df.copy(deep=True).rename(
columns={MEASUREMENT: SIMULATION})
simulation_df[SIMULATION] = [0.5 * analytical_a(t, 1, 0, 0.8, 0.6) + 2
for t in simulation_df[TIME]]
columns={MEASUREMENT: SIMULATION}
)
simulation_df[SIMULATION] = [
0.5 * analytical_a(t, 1, 0, 0.8, 0.6) + 2 for t in simulation_df[TIME]
]

case = PetabTestCase(
id=3,
brief="Simulation. Numeric observable parameter overrides in measurement "
"table.",
"table.",
description=DESCRIPTION,
model=DEFAULT_SBML_FILE,
condition_dfs=[condition_df],
Expand Down
Loading

0 comments on commit 0f34f23

Please sign in to comment.