atomica.model.ResidualJunctionCompartment

class atomica.model.ResidualJunctionCompartment(pop, name, duration_group=None)[source]

Bases: JunctionCompartment

Junction with a residual outflow

A residual outflow junction has a single additional outflow link

A TimedCompartment has a duration group by virtue of having a .parameter attribute and a flush link. A junction might belong to a duration group by having inflows and outflows exclusively from that group. However, it might not be directly attached to any timed compartments, if the connections are entirely via upstream and downstream junctions. Junctions also do not have flush links. Therefore, we record membership in the duration group by specifying the name of the parameter in the (indirect) upstream and downstream compartments.

Note that having connections to timed compartments does not itself indicate membership in the duration group - the junction is only a member if all of the upstream and downstream compartments belong to the same duration group. The duration group is determined in framework validation and stored in the framework.

Parameters
  • pop

  • name (str) –

  • duration_group (Optional[str]) – Optionally specify a duration group

Attributes

name

Variable code name

outflow

Return the outflow at all times

Methods

balance

Balance junction inflows and outflows

connect

Construct link out of this compartment

expected_duration

expected_outflow

initial_flush

Perform an initial junction flush

plot

Produce a time series plot

preallocate

Preallocate junction values

relink

resolve_outflows

Resolve outgoing links and convert to number

set_dynamic

Make the variable a dependency

unlink

update

Update the junction at given time index

balance(ti)[source]

Balance junction inflows and outflows

For a ResidualJunctionCompartment, if the outflows sum to less than 1, rather than scaling them up proportionately, the residual is assigned to the residual link.

Parameters

ti (int) – Time index to update (scalar only, as this function is only called during integration)

Return type

None

connect(dest, par)

Construct link out of this compartment

For junctions, outgoing links are normal links unless the junction belongs to a duration group. If the junction belongs to a duration group, then the output links should all be TimedLink instances.

Parameters
  • dest – A Compartment instance

  • par – The parameter that the Link will be associated with

Return type

None

duration_group

Store the name of the duration group, if the junction belongs to one

id

Unique identifier for the integration object

initial_flush()[source]

Perform an initial junction flush

Return type

None

property name: str

Variable code name

This is implemented as a property method because the id of the Variable is a tuple containing the population name and the variable code name, so this property method returns just the variable code name portion. That way, storage does not need to be duplicated.

Return type

str

Returns

A code name

property outflow: array

Return the outflow at all times

Return type

array

Returns

The sum of outgoing links at all time indices

plot()

Produce a time series plot

This is a quick function to make a basic line plot of this Variable. Mainly intended for debugging. Production-ready plots should be generated using the plotting library functions instead

Return type

None

pop

Reference back to the Population containing this object

preallocate(tvec, dt)

Preallocate junction values

Junction preallocation pre-fills the values with zeros, since the junction must be empty at all times.

Parameters
  • tvec (array) – An array of time values

  • dt (float) – Time step size

Return type

None

resolve_outflows(ti)

Resolve outgoing links and convert to number

For junctions, links are updated in a separate step because the logic is different - instead of the value of links coming from parameters, they come from the inflow into the junction. We cannot update the junctions in the same step as compartments because while the junction subgraphs must be acyclic, the entire system may contain cycles. Therefore it is not possible to determine a topological ordering for the entire system. The system is solvable because for normal compartments, only one transition per timestep is allowed. But regardless, this prevents using graph analysis to determine an execution order for the entire system that would allow junction computation in the same step.

Parameters

ti (int) – Time index to resolve outflows

Return type

None

set_dynamic(**kwargs)

Make the variable a dependency

For Compartments and Links, this does nothing. For Characteristics and Parameters, it will set the dynamic flag, but in addition, any validation constraints e.g. a Parameter that depends on Links cannot itself be dynamic, will be enforced.

This method generally must be overloaded in derived classes e.g. Parameter.set_dynamic()

Return type

None

units

The units for the quantity, used for plotting and for validation. Note that the default 'unknown' units are distinct to dimensionless units, which have value ''

update(ti)

Update the junction at given time index

For compartments the update methods steps them forward in time. However, for junctions the value never needs to be stepped forward, because it’s always zero. Thus, this function does nothing.

Parameters

ti (int) – Time index to update

Return type

None