Skip to content

Commit

Permalink
Merge 3dc219e into 2dada60
Browse files Browse the repository at this point in the history
  • Loading branch information
pckroon committed Oct 21, 2022
2 parents 2dada60 + 3dc219e commit 6126732
Show file tree
Hide file tree
Showing 10 changed files with 693 additions and 9 deletions.
6 changes: 6 additions & 0 deletions .coveragerc
@@ -0,0 +1,6 @@
[run]
source = symfit
branch = True
concurrency = multiprocessing
omit =
tests/*
4 changes: 2 additions & 2 deletions .github/workflows/test.yaml
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
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
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
@@ -0,0 +1,6 @@
pytest
pytest-cov
coverage
coveralls
hypothesis[numpy]

1 change: 1 addition & 0 deletions symfit/core/fit.py
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
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
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

0 comments on commit 6126732

Please sign in to comment.