Formulas

This module provides the framework for formulas. All formulas should inherit from the Formula class in this module. Formula sources must include a formula importer, or can subclass one of the formula importers here.

Formula Parameter

class simkit.core.formulas.FormulaParameter(*args, **kwargs)[source]

Field for data parameters.

Parameters
  • islinear (bool) – flag to indicate nonlinear formulas [not used]

  • args (list) – list of names of input arguments

  • units (list) – list of return value and input argument units for Pint wrapping

  • isconstant (list) – list of arguments that don’t have any covariance

Formula Registry

class simkit.core.formulas.FormulaRegistry[source]

A registry for formulas. The meta names are islinear, args, units and isconstant.

register(new_formulas, *args, **kwargs)[source]

Register formula and meta data.

  • islinear - True if formula is linear, False if non-linear.

  • args - position of arguments

  • units - units of returns and arguments as pair of tuples

  • isconstant - constant arguments not included in covariance

Parameters

new_formulas – new formulas to add to registry.

Formula Importers

class simkit.core.formulas.FormulaImporter(parameters, meta=None)[source]

A class that imports formulas.

Parameters
  • parameters (dict) – Parameters used to import formulas.

  • meta (Meta) – Options for formulas and formula inporters

import_formulas()[source]

This method must be implemented by each formula importer.

Returns

formulas

Return type

dict

Raises

NotImplementedError

meta = None

options for importer

parameters = None

parameters to be read by reader

Python Module Importer

class simkit.core.formulas.PyModuleImporter(parameters, meta=None)[source]

Import formulas from a Python module.

import_formulas()[source]

Import formulas specified in parameters.

Returns

formulas

Return type

dict

Numerical Expression Importer

class simkit.core.formulas.NumericalExpressionImporter(parameters, meta=None)[source]

Import formulas from numerical expressions using Python Numexpr.

import_formulas()[source]

This method must be implemented by each formula importer.

Returns

formulas

Return type

dict

Raises

NotImplementedError

Formula Base

class simkit.core.formulas.FormulaBase[source]

Metaclass for formulas.

Formula

class simkit.core.formulas.Formula[source]

A class for formulas.

Specify formula_importer which must subclass FormulaImporter to import formula source files as class. If no formula_importer is specified, the default is PyModuleImporter.

Specify formula_path and formula_file that contains formulas in string form or parameters used to import the formula source file.

This is the required interface for all source files containing formulas used in SimKit.

args = None

positional arguments

formulas = None

formulas loaded by the importer using specified parameters

isconstant = None

constant arguments that are not included in covariance calculation

islinear = None

linearity determined by each data source?

units = None

expected units of returns and arguments as pair of tuples