Skip to content

Compilation

CompiledPort(port, assignment)

Bases: Port

A port object together with the assignment it exposes.

Note

This class is not designed to be instantiated directly.

PARAMETER DESCRIPTION
port

port to compile

TYPE: Port

assignment

assignment to assign to the port

TYPE: Assignment

Source code in psymple/build/compiled_ports.py
def __init__(self, port: Port, assignment: Assignment):
    """
    Instantiate from a port and assignment.

    Args:
        port: port to compile
        assignment: assignment to assign to the port
    """
    self.name = port.name
    self.assignment = deepcopy(assignment)
    self.description = port.description

CompiledPortedObject(name, parsing_locals={}, **kwargs)

Bases: CompositePortedObject

A ported object with compiled ports store exposable assignments, together with internal assignments.

Note:

This class should not be instantiated on its own. It is formed from the compile methods of 1PortedObject1 subclasses.

PARAMETER DESCRIPTION
name

a string which must be unique for each PortedObject inside a common CompositePortedObject.

TYPE: str

parsing_locals

a dictionary mapping strings to sympy objects.

TYPE: dict DEFAULT: {}

**kwargs

arguments passed to super().init(). No user arguments should be supplied.

DEFAULT: {}

Source code in psymple/build/ported_objects.py
def __init__(self, name: str, parsing_locals: dict = {}, **kwargs):
    """
    Instantiate a CompiledPortedObject.

    Args:
        name: a string which must be unique for each `PortedObject` inside a common
            [`CompositePortedObject`][psymple.build.CompositePortedObject].
        parsing_locals: a dictionary mapping strings to `sympy` objects.
        **kwargs: arguments passed to super().__init__(). No user arguments should be supplied.
    """
    super().__init__(name, parsing_locals=parsing_locals, **kwargs)
    # free input parameters and (possibly) their default values
    self.input_ports = {}
    # values of output parameters in terms of input parameters
    self.output_ports = {}
    # ODEs of variables in terms of input parameters and other variables
    self.variable_ports = {}
    # ODEs of unexposed variables in terms of other parameters and variables
    self.internal_variable_assignments = {}
    # Parameters that are initialized via default parameters, and whose values are fully determined
    self.internal_parameter_assignments = {}
    # Inputs of self which must be provided before simulation
    self.required_inputs = {}

get_assignments()

Returns all assignments of self.

  • The first return value is all assignments at variable ports and all internal variable assignments,
  • The second return value is all assignments at output ports and all internal parameter assignments.
Source code in psymple/build/ported_objects.py
def get_assignments(
    self,
) -> tuple[list[DifferentialAssignment], list[ParameterAssignment]]:
    """
    Returns all assignments of self.

    - The first return value is all assignments at variable ports and all
        internal variable assignments,
    - The second return value is all assignments at output ports and all
        internal parameter assignments.
    """
    self._set_input_parameters()

    parameter_assignments = list(
        itertools.chain(
            (p.assignment for p in self.output_ports.values()),
            self.internal_parameter_assignments.values(),
        )
    )
    variable_assignments = list(
        itertools.chain(
            (p.assignment for p in self.variable_ports.values()),
            self.internal_variable_assignments.values(),
        )
    )

    return variable_assignments, parameter_assignments

get_required_inputs()

Returns the input parameters of self which do not have a default value.

Source code in psymple/build/ported_objects.py
def get_required_inputs(self) -> set[RequiredInputParameter]:
    """
    Returns the input parameters of `self` which do not have a default value.
    """
    return list(self.required_inputs.values())