-
Notifications
You must be signed in to change notification settings - Fork 107
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
Improved parameter handling #923
Conversation
except for public methods of Models and sys-mor reductors
remove parse_parameter from Parametric and from_parameter_type from Parameter in favor of ParameterType.parse. Only use ParameterType.parse when mu is not a Parameter.
and inherit from ImmutableObject to make it a proper base class instead of a mixin.
and remove parameters.spaces in favor of new ParameterSpace class in parameters.base
to agree with new nomenclature
Disallow passing objects which are not an instance of ParametericObject but have a 'parameters' attribute.
Either a single number of dict of numbers should be passed.
From my point of view this can now be merged. Any final comments @pymor/pymor-devs, @TiKeil, @HenKlei? @pmli, I decided to keep the calls to I also decided to keep the name |
The latest changes look good to me. |
Is it necessary to put It is also unclear to me how to sample parameters for a model that is not defined by a |
It is not necessary but avoids the unnecessary function call when running with
Yes. The idea is that in general a
or
I certainly can be more convenient, to have the space attached to the |
I agree with Petars comment, but I would rather rename the method to remove the redundant assert. What about something like
|
assert self.parameters.is_compatible(mu) To me assert self.parameters.is_compatibe(mu), self.parameters.why_incomaptible(mu) or assert mu >= self.parameters, self.parameters.why_incomaptible(mu) which is the actual implementation of
|
Ah, I overlooked this part. Sorry
+1
-1, I will always forget the 2nd part... |
Ok, let's keep |
I guess |
This pull request contains a large amount of improvements and simplifications as to how parameters are handled in pyMOR:
New nomenclature: the
Parameter
class has been renamed toMu
,ParameterType
has been renamed toParameters
. Correspondingly, theparamter_type
attribute ofParametric
has been renamed toparameters
. An item of theparameters
dict is called a parameter of theParametric
object. Thus, aMu
objects represents a mapping of (free) parameters to concrete values. The i-th 'component of a parameter' is now simply the i-th number in the array to which the parameter is mapped.Parameters are now always one-dimensional NumPy arrays.
parameters[p]
is now anint
specifying the size of the array for parameterp
. In particular, scalar parametersp
should now be defined as{p: 1}
instead of{p: ()}
, and the scalar value is retrieved asmu[p][0]
. In particular this affectsExpressionParameterFunctional
andExpressionFunction
, where the user now has to writep[0]
instead ofp
.Passing
Mu
instances asmu
is now mandatory. Apart from clearly defining, which values are allowed asmu
arguments, the implementor of a parametric object no longer has to invokeparse_parameter
to ensure thatmu
is well-formed. At the same time, amu
which is accepted by a given object will almost always also be accepted by any child object. Furthermore, givingmu
a fixed type will simplify introducing time-dependentMu
s (which will be subject to a later PR). The only exception to the rule are interface methods ofModel
andReductors
which still allow passing lists of numbers or dicts of numbers/lists.To assert that a given
mu
is compatible with the object'sparameters
(previously ensured by callingparse_parameter
), the new idiom isassert self.parameters.assert_compatible(mu)
.Mu
instances are now immutable and have awith_
method similar toImmutableObject
.Parametric
has been renamed toParametricObject
and is now a proper base class instead of a mixin class.Instead of calling
build_parameter_type
(which has been moved to the class methodParameters.of
) in__init__
, theparameters
of aParametricObject
are now automatically inferred from the object's__init__
arguments together withparameters_own
andparameters_internal
properties, which can be set in__init__
to indicate that the object itself introduces new parameters (parameters_own
) or assigns fixed values to parameters of it's child objects (parameters_internal
). It is still possible to assign to theparameters
property in__init__
to override this automatic behavior.The notion of
ParameterSpace
has been simplified and decoupled fromModels
: every parameter space is now aCubicParameterSpace
, which has been renamed topymor.parameters.base.ParameterSpace
. Thepymor.parameters.spaces
module has been removed. To instantiate aParameterSpace
, thespace
method ofParameters
can be used. E.g., we can writefom.parameters.space(0.1, 10)
to obtain aParameterSpace
for theParameters
offom
, where each parameter can range from 0.1 to 10. Individual ranges can be specified as a dict:fom.parameters.space({'diffusion': (0.1, 10), 'advection': (1, 2)})
. Attaching a fixedParameterSpace
to aModel
lead to some technical complications (to instantiate theParameterSpace
the exactParameterType
had to be known, which often forced the user to explicitly specify it even though it was derived by theModel
, andReductors
had to ensure to pass the space to the ROM). Moreover, often the parameter range of interest is not a fixed property of theModel
but depends on the usage of theModel
. Consequently,Models
no longer have aparameter_space
attribute. However, mostanalyticalproblems
still have aParameterSpace
of interest attached.The parameter used for time in
timestepping
algorithms has been renamed from_t
tot
.The implementations of
Parameters
,ParametricObject
,Mu
andParameterSpace
have been overhauled.Fixes #869.