cottax.consumers.execution

Running a realised graph in plain Python.

Dependency:

interface_types (what a driver’s implementation is handed (Posed) and tries

|| values through (ConditionMap)) /

interface refusals (interface: what a feature registers, of a place, the

|| || DataStructure for its class; what a study chooses, what / || runs a driver (DriverImplementation);

run <———–’ refusals: every refusal kind)

|| (run: CallableGraph over realisation.RealisedGraph, every || implementation callable, a driver’s one of it; run, || refusing a graph proved below a CallableGraph; walk, its || loop over the steps with an Env and a Solve handed to an || AtSolve; InteriorConditionMap, || a problem posed by its interior) /

jax_jit (JitGraph, every node a jit cache key; Traced, the run

traced once: the graph’s jaxpr, every place’s shape)

interface, refusals

|| /

structures (Inputs, the key of a variable’s own value; slots, each place

|| a run takes a value at and what the caller calls it; || read_from, each read where a caller’s structure holds it; || valued_once, one value per input; write_back, || write_role) /

drive (Drive: every undriven problem driven and implemented by the

|| first implementation accepting it, its data and reports at || the places a rule it is handed gives) /

part <– declaration.interface (part: Driving, drive as a surface’s method, its contracts

and places the fields it holds; Running, a model valued and run by name or from a caller’s structures)

Imported by name, not here: jax_jit; run’s blamed and check_callable.

class CallableGraph[N: Label, V: Place](graph: NestingGraph[N, V])[source]

Bases: RealisedGraph[N, V], Generic[N, V]

A realised graph whose every implementation is callable / driver implemented

checks_node: PerLevel[tuple[Callable[[N, NodeDefinition[V]], Iterator[Violation]], ...]] = (<function check_function_callable>, <function check_implements_its_driver>)

the one thing a level below adds.

Type:

(name, node) -> violations

run[N: Label, V: Place](valued: GraphWithValues[CallableGraph[N, V], V])[source]

Every place with a value: the inputs, and everything the graph computes.

Return type:

OrderedMap[V, Any]

class Inputs[source]

Bases: object

The key for a variable’s own value, by name or in a structure, beside a driver’s roles: s.run(model, {Inputs: {‘x’: 1.0}}, read_from={Inputs: state}). Not a role.

read_from[V: Place](graph: NestingGraph[Any, V], table: tuple[Slot, ...], structures: Mapping[type, Any])[source]

Each value a structure of structures gives an open slot of table, where its key reads it: under Inputs, an input where the structure holds it; under a per-unknown role, the datum at its unknown’s place. What a structure holds beyond is never asked; a slot holding None gives nothing. Refused: a per-problem role, a role no driver takes.

Return type:

tuple[tuple[Any, Any, str], ...]

slots[V: Place](graph: NestingGraph[Any, V], at: Callable[[V], V])[source]

Every place a run of graph takes a value at, by what the caller calls it: each driver datum, also one it computes (a warm start), then each boundary input. A place two problems take is there twice.

Return type:

tuple[Slot, ...]

valued_once[V: Place](table: tuple[Slot, ...], inputs: tuple[V, ...], candidates: Iterable[tuple[Any, Any, str]])[source]

The one value at each input: refused, a place proposed twice (ValuedTwice, naming both sources) and an input none is proposed for (Unvalued, saying how to give it).

Return type:

OrderedMap[V, Any]

write_back[V: Place](graph: NestingGraph[Any, V], state: Any, values: Mapping[V, Any])[source]

state with each place graph computes written where the state holds it, its value from values (a run’s); an input is never written.

Return type:

Any

write_role[V: Place](graph: NestingGraph[Any, V], state: Any, values: Mapping[V, Any], role: type, at: Callable[[V], V])[source]

state with the value of each place a driver takes or reports a per-unknown role at, written at at(unknown) where the state holds it: a structure keyed as the unknowns are. Refused: a per-problem role, one no driver has.

Return type:

Any

class Drive(implementations: tuple[DriverImplementation, ...], contracts: tuple[DriverContract, ...], places: Callable[[object, tuple, DriverContract], tuple[tuple, tuple]])[source]

Bases: ComposedOp

Every problem no driver answers yet, driven by the first implementation whose contract accepts its shape, under the first of contracts it implements, at the places places(at, unknowns, contract) gives (its data and its reports, as Assign takes them), and implemented by it. A problem already driven and not implemented is implemented by the first implementation whose implements covers its contract; one already implemented is left alone.

implementations: tuple[DriverImplementation, ...]
contracts: tuple[DriverContract, ...]
places: Callable[[object, tuple, DriverContract], tuple[tuple, tuple]]
composed(graph: NestingGraph)[source]

The ops this one is. Takes a graph, so an expansion may depend on what it meets.

Return type:

tuple[GraphOp, ...]

chosen(name, problem)[source]
Return type:

DriverImplementation

covering(name, contract: DriverContract)[source]

The first implementation of contract, a problem’s already.

Return type:

DriverImplementation

contract_for(implementation: DriverImplementation)[source]

The default contract an implementation answers: the first it implements.

Return type:

DriverContract

class Driving(locator: Locator[V, N])[source]

Bases: Part

Driving problems: one by its contract (assign), or every undriven one by the first of the implementations accepting it (drive), tried under contracts; each role where role_places puts it.

contracts: AbstractVar[tuple[DriverContract, ...]]

The contracts a problem is driven under, the first an implementation implements.

role_places: AbstractVar[RolePlaces]

Where a driver’s data and reports go, a rule per role.

assign(problem: Label, contract: DriverContract)[source]

The problem driven by contract, each of its roles where role_places puts it, read off the problem when the op is applied.

Return type:

AssignByRule

drive(*implementations: Any)[source]

Every undriven problem driven by the first of implementations accepting it, under the first of the contracts it implements; a problem driven already implemented by the first covering its contract.

Return type:

Drive

class Running(locator: Locator[V, N])[source]

Bases: Part

A model run on values written by name (values) or read from a caller’s structures (read_from), each keyed by Inputs or a driver’s role: run(model, values, read_from), through valued. A datum of a per-unknown role is read in a structure at its unknown’s place, or, the unknown a copy by this surface’s copies, at what it copies.

copies: AbstractVar[PlaceToPlace]

a copy’s datum is read at what it copies.

Type:

Where a cut’s copy of a place goes

valued(model: NestingGraph | ProvedGraph | Model, values: Mapping[type, Mapping[Any, Any]] = OrderedMap(), read_from: Mapping[type, Any] = OrderedMap(), *, proof: type = CallableGraph)[source]

model (a graph, a proof, or a Model: a Declared), proved a proof unless it is one, with a value at each boundary input, from exactly one source: the declaration’s own values; values, by name, {Inputs: {‘x’: 1.}, Start: {‘z_1’: 5., s.copy(‘y_2’): 1.}}, a driver’s data by role and unknown, a per-problem role at any one unknown of its problem; or read_from, a structure per key, {Inputs: state, Start: state}. Refused: a value nothing reads, a place given twice, a key that is no problem’s unknown, a role its driver does not take, and any input left without a value.

Return type:

GraphWithValues

run(model: NestingGraph | ProvedGraph | Model, values: Mapping[type, Mapping[Any, Any]] = OrderedMap(), read_from: Mapping[type, Any] = OrderedMap())[source]

model run, valued as valued says: every place’s value, read by name.

Return type:

Results

class Results(values: OrderedMap, surface: Surface, graph: NestingGraph)[source]

Bases: Mapping

Every place’s value after a run, read by any name the surface reads: out[‘y_1’], out[V.y_1], or the place itself; a driver’s datum or report by role at an unknown, out[Trajectory, ‘x’]. out.into(state) writes them into a structure, out.into(history, Trajectory) a role’s at each unknown’s place.

into(state: Any, key: type = Inputs)[source]

state with each place the run computed written where the state holds it, an input never; under a per-unknown role, that role’s value at each unknown’s place (at what a copy copies), as read_from reads it.

Return type:

Any

Submodules