gotran package¶
Subpackages¶
- gotran.algorithms package
- gotran.codegeneration package
- Submodules
- gotran.codegeneration.algorithmcomponents module
- gotran.codegeneration.avoidsympycontractions module
- gotran.codegeneration.codecomponent module
- gotran.codegeneration.codegenerators module
- gotran.codegeneration.compilemodule module
- gotran.codegeneration.latexcodegenerator module
- gotran.codegeneration.oderepresentation module
- gotran.codegeneration.solvercomponents module
- gotran.codegeneration.sympy_cse module
- Module contents
- gotran.common package
- gotran.input package
- gotran.model package
- gotran.solver package
Module contents¶
-
exception
gotran.
GotranException
[source]¶ Bases:
RuntimeError
Base class for ModelParameters exceptions
-
class
gotran.
ODEObject
(name, dependent=None)[source]¶ Bases:
object
Base container class for all ODEObjects
-
name
¶
-
-
class
gotran.
Comment
(comment, dependent=None)[source]¶ Bases:
gotran.model.odeobjects.ODEObject
A Comment. To keep track of user comments in an ODE
-
class
gotran.
ODEValueObject
(name, value, dependent=None)[source]¶ Bases:
gotran.model.odeobjects.ODEObject
A class for all ODE objects which has a value
-
param
¶
-
sym
¶
-
unit
¶
-
value
¶
-
-
class
gotran.
Parameter
(name, init)[source]¶ Bases:
gotran.model.odeobjects.ODEValueObject
class for a Parameter
-
init
¶
-
-
class
gotran.
State
(name, init, time)[source]¶ Bases:
gotran.model.odeobjects.ODEValueObject
class for a State variable
-
init
¶
-
is_solved
¶
-
sym
¶
-
-
class
gotran.
Time
(name, unit='ms')[source]¶ Bases:
gotran.model.odeobjects.ODEValueObject
Specialization for a Time class
-
class
gotran.
Dt
(name, unit='ms')[source]¶ Bases:
gotran.model.odeobjects.ODEValueObject
Specialization for a time step class
-
class
gotran.
IndexedObject
(basename, indices, shape=None, array_params=None, add_offset='', dependent=None)[source]¶ Bases:
gotran.model.odeobjects.ODEObject
An object with a fixed index associated with it
-
basename
¶
-
indices
¶
-
offset_str
¶
-
shape
¶
-
sym
¶
-
-
gotran.
cmp_to_key
()¶ Convert a cmp= function into a key= function.
-
class
gotran.
ODEComponent
(name, parent)[source]¶ Bases:
gotran.model.odeobjects.ODEObject
Base class for all ODE components.
-
add_algebraic
(state, expr, dependent=None)[source]¶ Add an algebraic expression which relates a State with an expression which should equal to 0
Parameters: - state (gotran.State) – The State which the algebraic expression should determine
- expr (sympy.Basic) – The expression that should equal 0
- dependent (gotran.ODEObject) – If given the count of this expression will follow as a fractional count based on the count of the dependent object
-
add_comment
(comment, dependent=None)[source]¶ Add a comment to the ODE component
Parameters: - comment (str) – The comment
- dependent (gotran.ODEObject) – If given the count of this comment will follow as a fractional count based on the count of the dependent object
-
add_derivative
(der_expr, dep_var, expr, dependent=None)[source]¶ Add a derivative expression
Parameters: - der_expr (gotran.Expression, gotran.State, sympy.AppliedUndef) – The Expression or State which is differentiated
- dep_var (gotran.State, gotran.Time, gotran.Expression, sympy.AppliedUndef, sympy.Symbol) – The dependent variable
- expr (sympy.Basic) – The expression which the differetiation should be equal
- dependent (gotran.ODEObject) – If given the count of this expression will follow as a fractional count based on the count of the dependent object
-
add_intermediate
(name, expr, dependent=None)[source]¶ Register an intermediate math expression
Parameters: - name (str) – The name of the expression
- expr (sympy.Basic, scalar) – The expression
- dependent (gotran.ODEObject) – If given the count of this expression will follow as a fractional count based on the count of the dependent object
-
add_parameter
(name, init)[source]¶ Add a parameter to the component
Parameters: - name (str) – The name of the parameter
- init (scalar, modelparameters.ScalarParam) – The initial value of the parameter
-
add_parameters
(*args, **kwargs)[source]¶ Add a number of parameters to the current ODEComponent
Parameters: - args (list of tuples) – A list of tuples with parameters and init values. Use this to set parameters if you need them ordered.
- kwargs (dict) – A dict with parameters
-
add_solve_state
(state, expr, dependent=None, **solve_flags)[source]¶ Add a solve state expression which tries to find a solution to a state by solving an algebraic expression
Parameters: - state (gotran.State, AppliedUndef) – The State that is solved
- expr (sympy.Basic) – The expression that determines the state
- dependent (gotran.ODEObject) – If given the count of this expression will follow as a fractional count based on the count of the dependent object
- solve_flags (dict) – Flags that are passed directly to sympy.solve
-
add_state
(name, init)[source]¶ Add a state to the component
Parameters: - name (str) – The name of the state variable
- init (scalar, modelparameters.ScalarParam) – The initial value of the state
-
add_state_solution
(state, expr, dependent=None)[source]¶ Add a solution expression for a state
Parameters: - state (gotran.State, AppliedUndef) – The State that is solved
- expr (sympy.Basic) – The expression that determines the state
- dependent (gotran.ODEObject) – If given the count of this expression will follow as a fractional count based on the count of the dependent object
-
add_states
(*args, **kwargs)[source]¶ Add a number of states to the current ODEComponent
Parameters: - args (list of tuples) – A list of tuples with states and init values. Use this to set states if you need them ordered.
- kwargs (dict) – A dict with states
-
comments
¶
-
components
¶ Return a list of all child components in the component
-
full_state_vector
¶ Return a sympy column vector with all full states
-
full_states
¶ Return a list of all states in the component and its children that are not solved and determined by a state expression
-
intermediates
¶ Return a list of all intermediates
-
is_complete
¶ True if the component and all its children are locally complete
-
is_finalized
¶
-
is_locally_complete
¶ True if the number of non-solved states are the same as the number of registered state expressions
-
num_components
¶ Return the number of all components including it self
-
num_full_states
¶ Return the number of all full states
-
num_intermediates
¶ Return the number of all intermediates
-
num_parameters
¶ Return the number of all parameters
-
num_rate_expressions
¶ Return the number rate expressions
-
num_state_expressions
¶ Return the number state expressions
-
num_states
¶ Return the number of all states
-
parameters
¶ Return a list of all parameters in the component
-
parent
¶ Return the the parent if it is still alive. Otherwise it will return None
-
rate_expressions
¶ Return a list of rate expressions
-
root
¶ Return the root ODE component (the ode)
-
state_expressions
¶ Return a list of state expressions
-
states
¶ Return a list of all states in the component and its children
-
t
¶ Return the time symbol
-
time
¶ Return the time
-
-
class
gotran.
Expression
(name, expr, dependent=None)[source]¶ Bases:
gotran.model.odeobjects.ODEValueObject
class for all expressions such as intermediates and derivatives
-
dependent
¶
-
expr
¶ Return the stored expression
-
is_state_expression
¶ True of expression is a state expression
-
sym
¶
-
-
class
gotran.
DerivativeExpression
(der_expr, dep_var, expr, dependent=None)[source]¶ Bases:
gotran.model.expressions.Intermediate
A class for Intermediate derivative expressions
-
dep_var
¶
-
der_expr
¶
-
-
class
gotran.
AlgebraicExpression
(state, expr, dependent=None)[source]¶ Bases:
gotran.model.expressions.StateExpression
A class for algebraic expressions which relates a State with an expression which should equal to 0
-
class
gotran.
StateExpression
(name, state, expr, dependent=None)[source]¶ Bases:
gotran.model.expressions.Expression
An expression which determines a State.
-
state
¶
-
-
class
gotran.
StateSolution
(state, expr, dependent=None)[source]¶ Bases:
gotran.model.expressions.Intermediate
Sub class of Expression for state solution expressions
-
state
¶
-
-
class
gotran.
RateExpression
(to_state, from_state, expr, dependent=None)[source]¶ Bases:
gotran.model.expressions.Intermediate
A sub class of Expression holding single rates
-
states
¶ Return a tuple of the two states the rate expression describes the rate between
-
-
class
gotran.
Intermediate
(name, expr, dependent=None)[source]¶ Bases:
gotran.model.expressions.Expression
A class for all Intermediate classes
-
class
gotran.
StateDerivative
(state, expr, dependent=None)[source]¶ Bases:
gotran.model.expressions.StateExpression
A class for all state derivatives
-
sym
¶
-
-
class
gotran.
IndexedExpression
(basename, indices, expr, shape=None, array_params=None, add_offset='', dependent=None)[source]¶ Bases:
gotran.model.odeobjects.IndexedObject
,gotran.model.expressions.Expression
An expression which represents an expression with a fixed index associated with it
-
gotran.
recreate_expression
(expr, *replace_dicts, **kwargs)[source]¶ Recreate an Expression while applying replace dicts in given order
-
class
gotran.
ODE
(name, ns=None)[source]¶ Bases:
gotran.model.odecomponent.ODEComponent
Root ODEComponent
Parameters: -
expanded_expression
(expr)[source]¶ Return the expanded expression.
The returned expanded expression consists of the original expression given by it basics objects (States, Parameters and IndexedObjects)
-
extract_components
(name, *components)[source]¶ Create an ODE from a number of components
Returns an ODE including the components
Parameters:
-
import_ode
(ode, prefix='', components=None, **arguments)[source]¶ Import a Model into the present Model
Parameters: - ode (str, gotran.ODE) – The ode which should be added. If ode is a str an ODE stored in that file will be loaded. If it is an ODE it will be added directly to the present ODE.
- prefix (str (optional)) – A prefix which all state, parameters and intermediates are prefixed with.
- components (list, tuple of str (optional)) – A list of components which will either be extracted or excluded from the imported model. If not given the whole ODE will be imported.
- arguments (dict (optional)) – Optional arguments which can control loading of model
-
is_dae
¶ Return True if ODE is a DAE
-
mass_matrix
¶ Return the mass matrix as a sympy.Matrix
-
ns
¶
-
present_component
¶ Return the present component
-
register_ode_object
(obj, comp, dependent=None)[source]¶ Register an ODE object in the root ODEComponent
-
-
class
gotran.
CellModel
(name_, ns=None)[source]¶ Bases:
gotran.model.ode.ODE
Basic class for storing information of a cell model You can either initialize an empty CellModel similar to an ODE. (Maybe if we can create a library of th cellmodels then it the string matched that of the library we return the model in the library, e.g cell = CellModel(“Noble_1962”)) Or you can initialize the cell using an existing ODE If you have an ODE and want to have a cell, then save the ODE to an .ode file and load it using load_cell (in stead of load_ode)
Example
Example
-
component_names
¶
-
currents
¶ Return a list of the currents used in the computation of the membrane potential. Note that intermediate currents (not involved in th computation of the membrane potential) are not retured
-
get_component
(name)[source]¶ Get the component with the given name
Parameters: name (str) – Name of the component Returns: par – The component Return type: gotran.ODECompoenent
-
get_intermediate
(name)[source]¶ Get the intermediate with the given name
Parameters: name (str) – Name of the intermediate Returns: par – The parameter Return type: gotran.Parameter
-
get_parameter
(name)[source]¶ Get the parameter with the given name
Parameters: name (str) – Name of the parameter Returns: par – The parameter Return type: gotran.Parameter
-
get_state
(name)[source]¶ Get the state with the given name
Parameters: name (str) – Name of the state variable Returns: par – The state Return type: gotran.Parameter
-
get_time_steps
(nbeats=1, t1=None, dt=1.0, t0=0.0)[source]¶ Get list with time steps given the number of beats and time increment
Parameters: - nbeats (int) – Nuber of beats (Default:1)
- dt (float) – Time increament between two time steps in ms. (Default:1.0) Note that you can provide dt as a Parameter with unit different from ms.
- t1 (float) – End time. If not provided then end time will determined from the number of beats
- t0 (float) – Start time (Default: 0.0)
-
intermediate_symbols
¶
-
intermediate_unit
(name, unit_type='si', return_factor=False)[source]¶ Get unit of intermediate expression Note that we neglect units within a funtion like exponential and logaritm.
Parameters: Returns: unit – Unit of the expression for the intermediate
Return type:
-
parameter_symbols
¶
-
set_parameter
(name, value)[source]¶ Set the parameter in the model to a given value
Parameters: - name (str) – Name of the parmaeter
- value (scalar, gotran.ScalarParam) – The new value of the parameter. Note that if the parameter is of type ScalarParam while the provided value is a scalar then the value will be updated while keeping the unit
-
set_residual_current
(t, current)[source]¶ Set rediual current
Parameters: - t (array) – List of times
- current (array) – List with residual current
-
simulate
(**kwargs)[source]¶ Simulate the ODE to \(t_{\mathrm{end}}\) with the given number points
Parameters: - t_end (scalar) – The end time
- nbeats (scalar) – Number of beats based on stimulus protocol
- npts (int) – Number of communication points used in the solver
-
state_symbols
¶
-
stimulation_parameters
¶
-
stimulation_protocol
¶
-
-
gotran.
load_ode
(filename, name=None, **arguments)[source]¶ Load an ODE from file and return the instance
The method looks for a file with .ode extension.
Parameters:
-
gotran.
load_cell
(filename, name=None, **arguments)[source]¶ Load a Cell from file and return the instance
The method looks for a file with .ode extension.
Parameters:
-
class
gotran.
CodeComponent
(name, ode, function_name, description, params=None, use_default_arguments=True, additional_arguments=None, **results)[source]¶ Bases:
gotran.model.odecomponent.ODEComponent
A wrapper class around an ODE. Its primary purpose is to help generate code.
The class alows extraction and manipulation of the ODE expressions.
-
add_indexed_expression
(basename, indices, expr, add_offset=False, dependent=None)[source]¶ Add an indexed expression using a basename and the indices
Parameters: - basename (str) – The basename of the indexed expression
- indices (int, tuple of int) – The fixed indices identifying the expression
- expr (sympy.Basic, scalar) – The expression.
- add_offset (bool) – Add offset to indices
- dependent (gotran.ODEObject) – If given the count of this expression will follow as a fractional count based on the count of the dependent object
-
-
class
gotran.
JacobianComponent
(ode, function_name='compute_jacobian', result_name='jac', params=None)[source]¶ Bases:
gotran.codegeneration.codecomponent.CodeComponent
An ODEComponent which keeps all expressions for the Jacobian of the rhs
-
class
gotran.
JacobianActionComponent
(jacobian, with_body=True, function_name='compute_jacobian_action', result_name='jac_action', params=None)[source]¶ Bases:
gotran.codegeneration.codecomponent.CodeComponent
Jacobian action component which returns the expressions for Jac*x
-
class
gotran.
FactorizedJacobianComponent
(jacobian, function_name='lu_factorize', params=None)[source]¶ Bases:
gotran.codegeneration.codecomponent.CodeComponent
Class to generate expressions for symbolicaly factorizing a jacobian
-
class
gotran.
ForwardBackwardSubstitutionComponent
(factorized, function_name='forward_backward_subst', result_name='dx', residual_name='F', params=None)[source]¶ Bases:
gotran.codegeneration.codecomponent.CodeComponent
Class to generate a forward backward substiution algorithm for symbolically factorized jacobian
-
class
gotran.
LinearizedDerivativeComponent
(ode, function_name='linear_derivatives', result_names=['linearized', 'rhs'], only_linear=True, include_rhs=False, nonlinear_last=False, params=None)[source]¶ Bases:
gotran.codegeneration.codecomponent.CodeComponent
A component for all linear and linearized derivatives
-
class
gotran.
CommonSubExpressionODE
(ode)[source]¶ Bases:
gotran.model.ode.ODE
Class which flattens the component structue of an ODE to just one. It uses common sub expressions as intermediates to reduce complexity of the derivative expressions.
-
gotran.
componentwise_derivative
(ode, indices, params=None, result_name='dy')[source]¶ Return an ODEComponent holding the expressions for the ith state derivative
Parameters: - ode (gotran.ODE) – The finalized ODE for which the ith derivative should be computed
- indices (int, list of ints) – The index
- params (dict) – Parameters determining how the code should be generated
- result_name (str) – The name of the result variable
-
gotran.
linearized_derivatives
(ode, function_name='linear_derivatives', result_names=['linearized', 'dy'], only_linear=True, include_rhs=False, nonlinear_last=False, params=None)[source]¶ Return an ODEComponent holding the linearized derivative expressions
Parameters: - ode (gotran.ODE) – The ODE for which derivatives should be linearized
- function_name (str) – The name of the function which should be generated
- result_names (str) – The name of the variable storing the linearized derivatives and the rhs evaluation if that is included.
- only_linear (bool) – If True, only linear terms will be linearized
- include_rhs (bool) – If True, rhs evaluation will be included in the generated code.
- nonlinear_last (bool) – If True the nonlinear expressions are added last after a comment
- params (dict) – Parameters determining how the code should be generated
-
gotran.
jacobian_expressions
(ode, function_name='compute_jacobian', result_name='jac', params=None)[source]¶ Return an ODEComponent holding expressions for the jacobian
Parameters: - ode (gotran.ODE) – The ODE for which the jacobian expressions should be computed
- function_name (str) – The name of the function which should be generated
- result_name (str) – The name of the variable storing the jacobian result
- params (dict) – Parameters determining how the code should be generated
-
gotran.
jacobian_action_expressions
(jacobian, with_body=True, function_name='compute_jacobian_action', result_name='jac_action', params=None)[source]¶ Return an ODEComponent holding expressions for the jacobian action
Parameters: - jacobian (gotran.JacobianComponent) – The ODEComponent holding expressions for the jacobian
- with_body (bool) – If true, the body for computing the jacobian will be included
- function_name (str) – The name of the function which should be generated
- result_name (str) – The name of the variable storing the jacobian diagonal result
- params (dict) – Parameters determining how the code should be generated
-
gotran.
factorized_jacobian_expressions
(jacobian, function_name='lu_factorize', params=None)[source]¶ Return an ODEComponent holding expressions for the factorized jacobian
Parameters: - jacobian (gotran.JacobianComponent) – The ODEComponent holding expressions for the jacobian
- params (dict) – Parameters determining how the code should be generated
-
gotran.
forward_backward_subst_expressions
(factorized, function_name='forward_backward_subst', result_name='dx', residual_name='F', params=None)[source]¶ Return an ODEComponent holding expressions for the forward backward substitions for a factorized jacobian
Parameters: - factorized (gotran.FactorizedJacobianComponent) – The ODEComponent holding expressions for the factorized jacobian
- function_name (str) – The name of the function which should be generated
- result_name (str) – The name of the result (increment)
- residual_name (str) – The name of the residual
- params (dict) – Parameters determining how the code should be generated
-
gotran.
diagonal_jacobian_expressions
(jacobian, function_name='compute_diagonal_jacobian', result_name='diag_jac', params=None)[source]¶ Return an ODEComponent holding expressions for the diagonal jacobian
Parameters: - jacobian (gotran.JacobianComponent) – The Jacobian of the ODE
- function_name (str) – The name of the function which should be generated
- result_name (str) – The name of the variable storing the jacobian diagonal result
- params (dict) – Parameters determining how the code should be generated
-
gotran.
rhs_expressions
(ode, function_name='rhs', result_name='dy', params=None)[source]¶ Return a code component with body expressions for the right hand side
Parameters: - ode (gotran.ODE) – The finalized ODE
- function_name (str) – The name of the function which should be generated
- result_name (str) – The name of the variable storing the rhs result
- params (dict) – Parameters determining how the code should be generated
-
gotran.
diagonal_jacobian_action_expressions
(diagonal_jacobian, with_body=True, function_name='compute_diagonal_jacobian_action', result_name='diag_jac_action', params=None)[source]¶ Return an ODEComponent holding expressions for the diagonal jacobian action
Parameters: - diagonal_jacobian (gotran.DiagonalJacobianComponent) – The ODEComponent holding expressions for the diagonal jacobian
- with_body (bool) – If true, the body for computing the jacobian will be included
- function_name (str) – The name of the function which should be generated
- result_name (str) – The name of the variable storing the jacobian diagonal result
- params (dict) – Parameters determining how the code should be generated
-
gotran.
monitored_expressions
(ode, monitored, function_name='monitored_expressions', result_name='monitored', params=None)[source]¶ Return a code component with body expressions to calculate monitored expressions
Parameters: - ode (gotran.ODE) – The finalized ODE for which the monitored expression should be computed
- monitored (tuple, list) – A tuple/list of strings containing the name of the monitored expressions
- function_name (str) – The name of the function which should be generated
- result_name (str) – The name of the variable storing the rhs result
- params (dict) – Parameters determining how the code should be generated
-
class
gotran.
PythonCodeGenerator
(params=None, ns='math')[source]¶ Bases:
gotran.codegeneration.codegenerators.BaseCodeGenerator
-
float_types
= {'double': 'float_', 'single': 'float32'}¶
-
function_code
(comp, indent=0, include_signature=True)[source]¶ Generate code for a single function given by a CodeComponent
-
language
= 'python'¶
-
monitor_name_to_index_code
(ode, monitored, indent=0)[source]¶ Return code for index handling for monitored
-
to_code
(expr, name)¶
-
-
class
gotran.
CCodeGenerator
(params=None)[source]¶ Bases:
gotran.codegeneration.codegenerators.BaseCodeGenerator
-
closure_end
= '}'¶
-
closure_start
= '{'¶
-
comment
= '//'¶
-
componentwise_code
(ode, indent=0, default_arguments=None, include_signature=True, return_body_lines=False)[source]¶
-
float_types
= {'double': 'double', 'single': 'float'}¶
-
function_code
(comp, indent=0, default_arguments=None, include_signature=True, return_body_lines=False)[source]¶
-
indent
= 2¶
-
indent_str
= ' '¶
-
index
(i)¶
-
language
= 'C'¶
-
line_cont
= ''¶
-
line_ending
= ';'¶
-
monitor_name_to_index_code
(ode, monitored, indent=0)[source]¶ Return code for index handling for monitored
-
to_code
(expr, name)¶
-
-
class
gotran.
CppCodeGenerator
(params=None)[source]¶ Bases:
gotran.codegeneration.codegenerators.CCodeGenerator
-
language
= 'C++'¶
-
to_code
(expr, name)¶
-
-
class
gotran.
MatlabCodeGenerator
(params=None)[source]¶ Bases:
gotran.codegeneration.codegenerators.BaseCodeGenerator
A Matlab Code generator
-
closure_end
= 'end'¶
-
closure_start
= ''¶
-
code_dict
(ode, monitored=None, include_init=True)[source]¶ Generates a dict of code snippets
Parameters: - ode (gotran.ODE) – The ODE for which code will be generated
- monitored (list) – A list of name of monitored intermediates for which evaluation code will be generated.
- include_init (bool) – If True, code for initializing the states and parameters will be generated.
- include_index_map (bool) – If True, code for mapping a str to a index for the corresponding, state, parameters or monitored will be generated.
- indent (int) – The indentation level for the generated code
-
comment
= '%'¶
-
indent
= 2¶
-
indent_str
= ' '¶
-
index
(i)¶
-
language
= 'Matlab'¶
-
line_cont
= '...'¶
-
line_ending
= ';'¶
-
to_code
(expr, name)¶
-
-
class
gotran.
CUDACodeGenerator
(params=None)[source]¶ Bases:
gotran.codegeneration.codegenerators.CCodeGenerator
-
function_code
(comp, indent=0, default_arguments=None, include_signature=True, return_body_lines=False)[source]¶
-
language
= 'CUDA'¶
-
-
class
gotran.
JuliaCodeGenerator
(params=None)[source]¶ Bases:
gotran.codegeneration.codegenerators.BaseCodeGenerator
A Julia Code generator
-
closure_end
= 'end'¶
-
closure_start
= ''¶
-
comment
= '#'¶
-
function_code
(comp, indent=0, include_signature=True)[source]¶ Generate code for a single function given by a CodeComponent
-
indent
= 4¶
-
indent_str
= ' '¶
-
index
(i)¶
-
language
= 'Julia'¶
-
line_cont
= ''¶
-
line_ending
= ''¶
-
monitor_name_to_index_code
(ode, monitored, indent=0)[source]¶ Return code for index handling for monitored
-
to_code
(expr, name)¶
-
-
class
gotran.
LatexCodeGenerator
(ode, params=None)[source]¶ Bases:
object
-
format_component_label
(label)[source]¶ Return a LaTeX-formatted string of an ODE component group label.
-
format_description
(description, name)[source]¶ If auto-format flag is set, attempt to automatically format description, setting references to states and parameters in math mode.
-
format_expr
(expr)[source]¶ Return a LaTeX-formatted string for a sympy expression. E.g.: >>> LatexCodeGenerator.format_expr(“exp(i*pi) + 1”) ‘e^{i pi} + 1’
-
format_global_options
(option_template, params=None)[source]¶ Inject additional options into the global option template
-
format_options
(exclude=None, override=None, params=None)[source]¶ Wrap options around a LaTeX string, excluding specified elements. If override is not empty, only those elements will be used, ignoring exclude.
-
format_packages
(package_list)[source]¶ Return list of packages and options as a LaTeX-formatted string. Assumes package list is on the form ((“package1”, “[options1]”), …).
-
format_param_table_row
(param)[source]¶ Return a LaTeX-formatted string for a longtable row describing a parameter. E.g.: >>> LatexCodeGenerator.format_param_table_row( … Parameter(“g_earth”, … ScalarParam(9.81, unit=”m/s**2”, … description=”Surface gravity”)) ‘ $g_{earth}$hspace{0.5cm} & $9.81 mathrm{frac{m}{s^{2}}}$ hspace{0.5cm} & Surface gravity’
-
format_state_table_row
(state)[source]¶ Return a LaTeX-formatted string for a longtable row describing a state’s initial value. E.g.: >>> LatexCodeGenerator.format_state_table_row(“amu”, … “Atomic mass unit”, 931.46, “MeV/c**2”) ‘ $amu$hspace{0.5cm} & $931.46 mathrm{frac{MeV}{c^{2}}}$ hspace{0.5cm} & Atomic mass unit’
-
format_unit
(unit)[source]¶ Return sympified and LaTeX-formatted string describing given unit. E.g.: >>> LatexCodeGenerator.format_unit(“m/s**2”) ‘mathrm{frac{m}{s^{2}}}’
-
generate_components
(params=None)[source]¶ Return a LaTeX-formatted string of the ODE’s derivative components and intermediate calculations.
-
generate_parameter_table
(params=None)[source]¶ Return a LaTeX-formatted string for a longtable describing the ODE’s parameters.
-
generate_state_table
(params=None)[source]¶ Return a LaTeX-formatted string for a longtable describing the ode’s states.
-
packages
= [('fullpage', ''), ('longtable,tabu', ''), ('multicol', ''), ('amsmath', ''), ('mathpazo', ''), ('flexisym', '[mathpazo]'), ('breqn', '')]¶
-
print_settings
= {}¶
-
-
class
gotran.
CellMLParser
(model_source, params=None, targets=None)[source]¶ Bases:
object
This module parses a CellML XML-file and converts it to PyCC code
-
check_and_register_component_variables
(comp, collected_states, collected_parameters, collected_equations)[source]¶ Check if component variables are allready collected
-
get_parents
(grouping, element=None)[source]¶ If group was used in the cellml use it to gather parent information about the components
-
parse_components
(targets)[source]¶ Build a dictionary containing dictionarys describing each component of the cellml model
-
-
gotran.
ODESolver
(ode, method='scipy', **options)[source]¶ A generic ODE solver for solving problem of the types on the form,
\[\dot{y} = f(t,y), \quad y(t_0) = y_0.\]Here one need to specific the backend which is either Scipy or Assimulo.
Arguments
- ode : gotran.ODE or gotran.CellModel
- The ode you want to solve in a gotran object
- method : str
- Solver method. Possible inputs are or ‘scipy’ (Default:’sundials’)
- options : dict:
- Options for the solver, see list_solver_options
-
class
gotran.
ScalarParam
(value, ge=None, le=None, gt=None, lt=None, unit='1', name='', description='')[source]¶ Bases:
modelparameters.parameters.Param
A simple type and range checking class for a scalar value
-
copy
(include_checkarg=True, include_name=True, include_description=True, include_unit=True)[source]¶ Return a copy of the parameter
Parameters:
-
name
¶
-
repr
(include_checkarg=True, include_name=True, include_description=True, include_unit=True)[source]¶ Returns an executable version of the Param including optional arguments
Parameters:
-
sym
¶
-
unit
¶ Return the unit
-
-
class
gotran.
ParameterDict
(**params)[source]¶ Bases:
dict
A dictionary with attribute-style access, that maps attribute access to the real dictionary.
-
copy
(to_dict=False)[source]¶ Make a deep copy of self, including recursive copying of parameter subsets.
Parameters: to_dict (bool (optional)) – Return a dict with items representing the values of the Parameters
-
format_data
(indent=None)[source]¶ Make a recursive indented pretty-print string of self and parameter subsets.
-
iterparameterdicts
()[source]¶ Iterate over all ParameterDicts
Parameters: recurse (bool (optional)) – If True each encountered ParameterDict will also be entered
-
iterparams
(recurse=False)[source]¶ Iterate over all Param
Parameters: recurse (bool (optional)) – If True each encountered ParameterDict will be entered
-
optstr
()[source]¶ Return a string with option set
An option string can be sent to a script using a parameter dict to set its parameters from command line options
-
parse_args
(options=None, usage='')[source]¶ Parse a list of options. use sys.argv as default
Parameters: options (list of str (optional)) – List of options. By default sys.argv[1:] is used. This argument is mostly for debugging.
-