pymor.models.interface

Module Contents

class pymor.models.interface.Model(dim_input=0, products=None, error_estimator=None, visualizer=None, name=None)[source]

Bases: pymor.core.cache.CacheableObject, pymor.parameters.base.ParametricObject

Interface for model objects.

A model object defines a discrete problem via its class and the Operators it contains. Furthermore, models can be solved for given parameter values resulting in a solution VectorArray.

solution_space[source]

VectorSpace of the solution VectorArrays returned by solve.

dim_output[source]

Dimension of the model output returned by output. 0 if the model has no output.

linear[source]

True if the model describes a linear problem.

products[source]

Dict of inner product operators associated with the model.

order[source]

Dimension of the solution_space.

Methods

computable_quantities

Set of quantities that can be compute via compute.

compute

Compute the solution of the model and associated quantities.

estimate_error

Estimate the error for the computed internal state.

estimate_output_error

Estimate the error for the computed output.

output

Return the model output for given parameter values mu.

output_d_mu

Compute the output sensitivities w.r.t. the model's parameters.

solve

Solve the discrete problem for the parameter values mu.

solve_d_mu

Compute the solution sensitivity w.r.t. a single parameter.

visualize

Visualize a VectorArray U of the model's solution_space.

computable_quantities()[source]

Set of quantities that can be compute via compute.

compute(data=None, *, solution=False, output=False, solution_d_mu=False, output_d_mu=False, solution_error_estimate=False, output_error_estimate=False, mu=None, input=None, **kwargs)[source]

Compute the solution of the model and associated quantities.

This method computes the output of the model, its internal state, and various associated quantities for given parameter values mu.

Parameters:
  • data – If not None, a dict of already computed quantities for the given mu and input. If used, newly computed quantities are added to the given dict and the same dict is returned. Providing a data dict can be helpful when some quantities (e.g., output) depend on already known quantities (e.g, solution) and caching has not been activated.

  • solution – If True, return the model’s internal state.

  • output – If True, return the model output.

  • solution_d_mu – If not False, either True to return the sensitivities of the model’s solution w.r.t. all parameters, or a sequence of tuples (parameter, index) to compute the solution sensitivities for selected parameters.

  • output_d_mu – If True, return the output sensitivities w.r.t. the model’s parameters.

  • solution_error_estimate – If True, return an error estimate for the computed internal state.

  • output_error_estimate – If True, return an error estimate for the computed output.

  • muParameter values for which to compute the values.

  • input – The model input. Either a NumPy array of shape (self.dim_input,), a Function with dim_domain == 1 and shape_range == (self.dim_input,) mapping time to input, or a str expression with t as variable that can be used to instantiate an ExpressionFunction of this type. Can be None if self.dim_input == 0.

  • kwargs – Additional keyword arguments to select further quantities that should be computed.

Returns:

A dict with the computed values.

estimate_error(mu=None, input=None)[source]

Estimate the error for the computed internal state.

For given parameter values mu this method returns an error estimate for the computed internal model state as returned by solve. It is a convenience wrapper around compute.

The model error could be the error w.r.t. the analytical solution of the given problem or the model reduction error w.r.t. a corresponding high-dimensional Model.

Parameters:
  • muParameter values for which to estimate the error.

  • input – The model input. Either a NumPy array of shape (self.dim_input,), a Function with dim_domain == 1 and shape_range == (self.dim_input,) mapping time to input, or a str expression with t as variable that can be used to instantiate an ExpressionFunction of this type. Can be None if self.dim_input == 0.

Returns:

  • The estimated solution_space error as a 1D NumPy array.

  • For stationary problems, the returned array has length 1.

  • For time-dependent problems, the length depends on the number of time

  • steps. The norm w.r.t. which the error is estimated depends on the given

  • problem.

estimate_output_error(mu=None, input=None)[source]

Estimate the error for the computed output.

For given parameter values mu this method returns an error estimate for the computed model output as returned by output. It is a convenience wrapper around compute.

The output error could be the error w.r.t. the analytical solution of the given problem or the model reduction error w.r.t. a corresponding high-dimensional Model.

Parameters:
  • muParameter values for which to estimate the error.

  • input – The model input. Either a NumPy array of shape (self.dim_input,), a Function with dim_domain == 1 and shape_range == (self.dim_input,) mapping time to input, or a str expression with t as variable that can be used to instantiate an ExpressionFunction of this type. Can be None if self.dim_input == 0.

Returns:

  • The estimated model output as a 2D |NumPy array|. The dimension

  • of axis 0 is dim_output. For stationary problems, axis 1 has

  • dimension 1. For time-dependent problems, the dimension of axis 1

  • depends on the number of time steps. The spatial/temporal norms

  • w.r.t. which the error is estimated depend on the given problem.

output(mu=None, input=None, return_error_estimate=False)[source]

Return the model output for given parameter values mu.

This method is a convenience wrapper around compute.

Parameters:
  • muParameter values for which to compute the output.

  • input – The model input. Either a NumPy array of shape (self.dim_input,), a Function with dim_domain == 1 and shape_range == (self.dim_input,) mapping time to input, or a str expression with t as variable that can be used to instantiate an ExpressionFunction of this type. Can be None if self.dim_input == 0.

  • return_error_estimate – If True, also return an error estimate for the computed output.

Returns:

  • The computed model output as a 2D |NumPy array|. The dimension

  • of axis 0 is dim_output. (For stationary problems, axis 1 has

  • dimension 1. For time-dependent problems, the dimension of axis 1

  • depends on the number of time steps.)

  • When return_error_estimate is True, the estimate is returned as

  • second value.

output_d_mu(mu=None, input=None)[source]

Compute the output sensitivities w.r.t. the model’s parameters.

Parameters:
  • muParameter value at which to compute the output sensitivities.

  • input – The model input. Either a NumPy array of shape (self.dim_input,), a Function with dim_domain == 1 and shape_range == (self.dim_input,) mapping time to input, or a str expression with t as variable that can be used to instantiate an ExpressionFunction of this type. Can be None if self.dim_input == 0.

Returns:

  • The output sensitivities as a dict `{(parameter, index) (sensitivity}` where)

  • sensitivity is a 2D NumPy arrays with axis 0 corresponding to time and axis 1

  • corresponding to the output component.

  • The returned :class:`OutputDMuResult` object has a `meth` (~OutputDMuResult.to_numpy`)

  • method to convert it into a single NumPy array, e.g., for use in optimization

  • libraries.

solve(mu=None, input=None, return_error_estimate=False)[source]

Solve the discrete problem for the parameter values mu.

This method returns a VectorArray with a internal state representation of the model’s solution for given parameter values. It is a convenience wrapper around compute.

The result may be cached in case caching has been activated for the given model.

Parameters:
  • muParameter values for which to solve.

  • input – The model input. Either a NumPy array of shape (self.dim_input,), a Function with dim_domain == 1 and shape_range == (self.dim_input,) mapping time to input, or a str expression with t as variable that can be used to instantiate an ExpressionFunction of this type. Can be None if self.dim_input == 0.

  • return_error_estimate – If True, also return an error estimate for the computed solution.

Returns:

  • The solution VectorArray. When return_error_estimate is True,

  • the estimate is returned as second value.

solve_d_mu(parameter, index, mu=None, input=None)[source]

Compute the solution sensitivity w.r.t. a single parameter.

Parameters:
  • parameter – Parameter for which to compute the sensitivity.

  • index – Parameter index for which to compute the sensitivity.

  • muParameter value at which to compute the sensitivity.

  • input – The model input. Either a NumPy array of shape (self.dim_input,), a Function with dim_domain == 1 and shape_range == (self.dim_input,) mapping time to input, or a str expression with t as variable that can be used to instantiate an ExpressionFunction of this type. Can be None if self.dim_input == 0.

Returns:

The sensitivity of the solution as a |VectorArray|.

visualize(U, **kwargs)[source]

Visualize a VectorArray U of the model’s solution_space.

Parameters:
  • U – The VectorArray from solution_space that shall be visualized.

  • kwargs – Additional keyword arguments to customize the visualization. See the docstring of self.visualizer.visualize.

class pymor.models.interface.OutputDMuResult(*args, **kwargs)[source]

Bases: pymor.tools.frozendict.FrozenDict

Immutable dict of gradients returned by output_d_mu.

Methods

to_numpy

Return gradients as a single 3D NumPy array.

to_numpy()[source]

Return gradients as a single 3D NumPy array.

The array is obtained by stacking the individual arrays along an additional axis 2, ordered by alphabetically ordered parameter name.