synthesizer.emission_models.model_queue

Queue machinery for executing emission model dependency graphs.

This module defines the runtime queue used by EmissionModel._get_spectra and EmissionModel._get_lines. The queue is responsible for constructing the executable closure of models for a single call, compiling the direct dependency graph between those models, and then tracking when each model becomes ready to execute.

The queue first discovers the full model closure, including any related model trees that may contribute saved outputs. It then identifies the active subset of that closure by starting from saved models and recursively marking the dependencies they require. Active state is stored explicitly as a boolean mapping keyed by model label, and only active models are queued. This means dead unsaved branches can be skipped entirely before any emission generation work is done.

The queue also manages emission lifetimes. Once a model’s emission has been consumed by all downstream dependents, and the model is not marked to be saved, the queue deletes that emission from the working output dictionaries. Keeping this logic in a dedicated module keeps execution-specific state out of EmissionModel and makes the scheduling logic easier to reason about.

Classes

class synthesizer.emission_models.model_queue.ModelQueue(root_model)[source]

Runtime queue for executing an emission model dependency graph.

The queue performs three related tasks for a single execution:

  • walk the model tree and collect the full executable closure

  • compile the dependency graph between models in that closure

  • prune the graph down to the active models needed by saved outputs

  • manage ready-to-run models and eagerly delete expired unsaved emissions

Parameters:

root_model (EmissionModel) – The root emission model being executed.

models

Mapping from model label to the EmissionModel instance in the executable closure for this run.

Type:

dict

dependencies

Mapping from model label to the labels of its direct upstream dependencies.

Type:

dict

dependents

Mapping from model label to the labels of its direct downstream dependents.

Type:

dict

execution_rank

Mapping from model label to its stable discovery order in the queue. This is used to keep execution deterministic when multiple models become ready at the same time.

Type:

dict

active

Mapping from model label to a boolean flag indicating whether that model is required to produce a saved output for this execution.

Type:

dict

pending_dependencies

Mapping from model label to the number of upstream dependencies that are still unresolved.

Type:

dict

lifetime

Mapping from model label to the number of downstream consumers that still need the model’s emission.

Type:

dict

_queue

The ready queue containing the labels of active models whose dependencies have all been satisfied.

Type:

collections.deque

_processed

The set of active model labels that have already been processed.

Type:

set

assert_finished()[source]

Ensure the dependency graph was fully traversed.

Parameters:

None

Returns:

None

Raises:

exceptions.InconsistentArguments – Raised if some models were never processed, which indicates the dependency graph could not be fully resolved.

done(model, emissions, particle_emissions)[source]

Mark a model as processed and update queue state.

Parameters:
  • model (EmissionModel) – The model that has just finished execution.

  • emissions (dict) – The integrated emission dictionary to clean up.

  • particle_emissions (dict) – The particle emission dictionary to clean up.

Returns:

None

is_active(label)[source]

Return whether a discovered model label is active.

Parameters:

label (str) – The model label to query.

Returns:

True if the model is required to produce a saved output, otherwise False.

Return type:

bool

pop()[source]

Pop and return the next ready model from the queue.

Parameters:

None

Returns:

The next model that is ready to be executed.

Return type:

EmissionModel