Skip to content

Commit

Permalink
Merge pull request #365 from tBuLi/py3_migration
Browse files Browse the repository at this point in the history
Py3 final migration
  • Loading branch information
pckroon authored Feb 14, 2023
2 parents 098fc27 + 2c251cd commit 43816a5
Show file tree
Hide file tree
Showing 16 changed files with 75 additions and 581 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
os: [ubuntu-latest]
python-version: [3.7, 3.8, 3.9, "3.10", 3.11]
steps:
- uses: actions/checkout@v3
Expand Down
15 changes: 6 additions & 9 deletions symfit/contrib/interactive_guess/interactive_guess.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from ... import ODEModel, Derivative, latex
from ...core.fit import TakesData
from ...core.support import keywordonly, key2str, deprecated
from ...core.support import key2str, deprecated

import itertools

Expand All @@ -21,8 +21,7 @@ class InteractiveGuess(TakesData):
"""A class that provides an graphical, interactive way of guessing initial
fitting parameters."""

@keywordonly(n_points=50, log_contour=True, percentile=(5, 95))
def __init__(self, *args, **kwargs):
def __init__(self, *args, n_points=50, log_contour=True, percentile=(5, 95), **kwargs):
"""Create a matplotlib window with sliders for all parameters
in this model, so that you may graphically guess initial fitting
parameters. n_points is the number of points drawn for the plot.
Expand Down Expand Up @@ -51,9 +50,8 @@ def __init__(self, *args, **kwargs):
corresponds to a 90% percentile. Should be a list of 2 numbers.
:type percentile: list
"""
self.log_contour = kwargs.pop('log_contour')
n_points = kwargs.pop('n_points')
self.percentile = kwargs.pop('percentile')
self.log_contour = log_contour
self.percentile = percentile
super(InteractiveGuess, self).__init__(*args, **kwargs)
if len(self.independent_data) > 1:
self._dimension_strategy = StrategynD(self)
Expand Down Expand Up @@ -99,8 +97,7 @@ def __init__(self, *args, **kwargs):
self._set_up_sliders()
self._update_plot(None)

@keywordonly(show=True, block=True)
def execute(self, **kwargs):
def execute(self, *, show=True, block=True, **kwargs):
"""
Execute the interactive guessing procedure.
Expand All @@ -112,7 +109,7 @@ def execute(self, **kwargs):
Any additional keyword arguments are passed to
matplotlib.pyplot.show().
"""
show = kwargs.pop('show')
kwargs.update(block=block)
if show:
# self.fig.show() # Apparently this does something else,
# see https://github.com/matplotlib/matplotlib/issues/6138
Expand Down
45 changes: 0 additions & 45 deletions symfit/core/_repeatable_partial.py

This file was deleted.

31 changes: 10 additions & 21 deletions symfit/core/fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@

from collections import OrderedDict
from collections.abc import Sequence
import sys

import sympy
import numpy as np

from symfit.core.argument import Variable
from .support import keywordonly, key2str
from .support import key2str
from .minimizers import (
BFGS, SLSQP, LBFGSB, BaseMinimizer, GradientMinimizer, HessianMinimizer,
ConstrainedMinimizer, MINPACK, ChainedMinimizer, BasinHopping
Expand All @@ -21,19 +20,15 @@
)
from .models import BaseModel, Model, BaseNumericalModel, CallableModel

if sys.version_info >= (3,0):
import inspect as inspect_sig
else:
import funcsigs as inspect_sig
import inspect

class TakesData(object):
"""
An base class for everything that takes data. Most importantly, it takes care
of linking the provided data to variables. The allowed variables are extracted
from the model.
"""
@keywordonly(absolute_sigma=None)
def __init__(self, model, *ordered_data, **named_data):
def __init__(self, model, *ordered_data, absolute_sigma=None, **named_data):
"""
:param model: (dict of) sympy expression or ``Model`` object.
:param bool absolute_sigma: True by default. If the sigma is only used
Expand All @@ -51,7 +46,6 @@ def __init__(self, model, *ordered_data, **named_data):
with sigma\_. For example, let x be a Variable. Then sigma_x will give the
stdev in x.
"""
absolute_sigma = named_data.pop('absolute_sigma')
if isinstance(model, BaseModel):
self.model = model
else:
Expand Down Expand Up @@ -130,7 +124,7 @@ def _make_signature(self):
"""
parameters = self._make_parameters(self.model)
parameters = sorted(parameters, key=lambda p: p.default is None)
return inspect_sig.Signature(parameters=parameters)
return inspect.Signature(parameters=parameters)

@staticmethod
def _make_parameters(model, none_allowed=None):
Expand All @@ -149,10 +143,10 @@ def _make_parameters(model, none_allowed=None):
if none_allowed is None:
none_allowed = model.sigmas.values()
parameters = [
inspect_sig.Parameter(
inspect.Parameter(
var.name,
kind=inspect_sig.Parameter.POSITIONAL_OR_KEYWORD,
default=None if var in none_allowed else inspect_sig.Parameter.empty
kind=inspect.Parameter.POSITIONAL_OR_KEYWORD,
default=None if var in none_allowed else inspect.Parameter.empty
)
for var in model.vars
]
Expand Down Expand Up @@ -338,9 +332,8 @@ class Fit(HasCovarianceMatrix):
fit_result = fit.execute(minimizer_kwargs=[dict(xatol=0.1), {}])
"""

@keywordonly(objective=None, minimizer=None, constraints=None,
absolute_sigma=None)
def __init__(self, model, *ordered_data, **named_data):
def __init__(self, model, *ordered_data, objective=None, minimizer=None,
constraints=None, absolute_sigma=None, **named_data):
"""
:param model: (dict of) sympy expression(s) or ``Model`` object.
Expand All @@ -364,10 +357,6 @@ def __init__(self, model, *ordered_data, **named_data):
:param named_data: assign dependent, independent and sigma variables
data by name.
"""
objective = named_data.pop('objective')
minimizer = named_data.pop('minimizer')
constraints = named_data.pop('constraints')
absolute_sigma = named_data.pop('absolute_sigma')
# Should be a list of Constraint objects
constraints = [] if constraints is None else constraints

Expand Down Expand Up @@ -439,7 +428,7 @@ def _make_signature(self):
unique_parameters.append(par)

parameters = sorted(unique_parameters, key=lambda p: p.default is None)
return inspect_sig.Signature(parameters=parameters)
return inspect.Signature(parameters=parameters)

def _determine_minimizer(self):
"""
Expand Down
5 changes: 1 addition & 4 deletions symfit/core/fit_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from symfit.core.objectives import (
LeastSquares, VectorLeastSquares, LogLikelihood
)
from symfit.core.support import keywordonly

class FitResults(object):
"""
Expand All @@ -26,8 +25,7 @@ class FitResults(object):
their optimized values. Can be `**` unpacked when evaluating
:class:`~symfit.core.models.Model`'s.
"""
@keywordonly(constraints=None)
def __init__(self, model, popt, covariance_matrix, minimizer, objective, message, **minimizer_output):
def __init__(self, model, popt, covariance_matrix, minimizer, objective, message, *, constraints=None, **minimizer_output):
"""
:param model: :class:`~symfit.core.models.Model` that was fit to.
:param popt: best fit parameters, same ordering as in model.params.
Expand All @@ -37,7 +35,6 @@ def __init__(self, model, popt, covariance_matrix, minimizer, objective, message
:param message: Status message returned by the minimizer.
:param \**minimizer_output: Raw output as given by the minimizer.
"""
constraints = minimizer_output.pop('constraints')
self.constraints = constraints if constraints is not None else []
self.minimizer_output = minimizer_output
self.model = model
Expand Down
121 changes: 0 additions & 121 deletions symfit/core/keywordonly.py

This file was deleted.

Loading

0 comments on commit 43816a5

Please sign in to comment.