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

Hypothesis tests #353

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[run]
source = symfit
branch = True
concurrency = multiprocessing
omit =
tests/*
4 changes: 2 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install wheel
pip install pytest
pip install -r requirements.txt
pip install -r requirements_test.txt
pip install matplotlib
pip install -e .
- name: Test with coverage
run:
pytest
pytest --cov=symfit --hypothesis-show-statistics
4 changes: 1 addition & 3 deletions .github/workflows/test_and_coveralls.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install wheel
pip install coveralls
pip install pytest
pip install -r requirements.txt
pip install -r requirements_test.txt
pip install matplotlib
pip install -e .
- name: Test with coverage
Expand All @@ -28,5 +27,4 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
pip install --upgrade coveralls
coveralls --service=github
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,11 @@ build
docs/_build
docs/_doctrees
dist

.hypothesis/

.eggs/

symfit.egg-info/

.coverage
6 changes: 6 additions & 0 deletions requirements_test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pytest
pytest-cov
coverage
coveralls
hypothesis[numpy]

1 change: 1 addition & 0 deletions symfit/core/fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
else:
import funcsigs as inspect_sig


class TakesData(object):
"""
An base class for everything that takes data. Most importantly, it takes care
Expand Down
11 changes: 11 additions & 0 deletions symfit/core/minimizers.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,17 @@ def execute(self, bounds=None, jacobian=None, hessian=None, constraints=None, **
:func:`scipy.optimize.minimize`. Note that your `method` will
usually be filled by a specific subclass.
"""
if not self.params:
return FitResults(
model=DummyModel(params=[]),
popt=[],
covariance_matrix=np.array([]),
objective=self.objective,
minimizer=self,
message="No free parameters",
fun=self.objective(),
niter=0,
)
ans = minimize(
self.objective,
self.initial_guesses,
Expand Down
20 changes: 16 additions & 4 deletions symfit/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,14 @@ def _init_from_dict(self, model_dict):
# Everything at the bottom of the toposort is independent, at the top
# dependent, and the rest interdependent.
ordered = list(toposort(self.connectivity_mapping))
independent = sorted(ordered.pop(0), key=sort_func)
self.dependent_vars = sorted(ordered.pop(-1), key=sort_func)
if ordered:
independent = sorted(ordered.pop(0), key=sort_func)
else:
independent = []
if ordered:
self.dependent_vars = sorted(ordered.pop(-1), key=sort_func)
else:
self.dependent_vars = []
self.interdependent_vars = sorted(
[item for items in ordered for item in items],
key=sort_func
Expand Down Expand Up @@ -907,7 +913,10 @@ def eval_jacobian(self, *args, **kwargs):
# the parameter dimension. We do not include the component direction in
# this, because the components can have independent shapes.
for idx, comp in enumerate(jac):
jac[idx] = np.stack(np.broadcast_arrays(*comp))
if comp:
jac[idx] = np.stack(np.broadcast_arrays(*comp))
else:
jac[idx] = np.array([])

return ModelOutput(self.keys(), jac)

Expand Down Expand Up @@ -951,7 +960,10 @@ def eval_hessian(self, *args, **kwargs):
# the parameter dimension. We do not include the component direction in
# this, because the components can have independent shapes.
for idx, comp in enumerate(hess):
hess[idx] = np.stack(np.broadcast_arrays(*comp))
if comp:
hess[idx] = np.stack(np.broadcast_arrays(*comp))
else:
hess[idx] = np.array([])

return ModelOutput(self.keys(), hess)

Expand Down
Loading