tg_model.integrations

Integration boundaries for external computation and async-capable backends.

Bindings declared at definition time are compiled into graph nodes; sync evaluation uses ExternalCompute, while AsyncExternalCompute requires evaluate_async.

See also

tg_model.execution.graph_compiler.compile_graph, tg_model.execution.evaluator.Evaluator

class tg_model.integrations.AsyncExternalCompute(*args, **kwargs)[source]

Bases: Protocol

Coroutine compute backend (requires evaluate_async()).

property name: str
async compute(inputs)[source]
Parameters:

inputs (dict[str, Quantity])

Return type:

ExternalComputeResult

class tg_model.integrations.ExternalCompute(*args, **kwargs)[source]

Bases: Protocol

Synchronous external backend (safe for evaluate()).

property name: str
compute(inputs)[source]
Parameters:

inputs (dict[str, Quantity])

Return type:

ExternalComputeResult

class tg_model.integrations.ExternalComputeBinding(external, inputs, output_routes=None)[source]

Bases: object

Bind a callable to named input refs and optional output route refs.

Parameters:
external: object
inputs: dict[str, AttributeRef]
output_routes: dict[str, AttributeRef] | None = None
class tg_model.integrations.ExternalComputeResult(value, provenance=<factory>)[source]

Bases: object

Return value from ExternalCompute.compute() / AsyncExternalCompute.compute().

Parameters:
  • value (Quantity | Mapping[str, Quantity])

  • provenance (Mapping[str, Any])

value: Quantity | Mapping[str, Quantity]
provenance: Mapping[str, Any]
exception tg_model.integrations.ExternalComputeValidationError[source]

Bases: ValueError

Raised when ValidatableExternalCompute.validate_binding() rejects a spec.

class tg_model.integrations.ValidatableExternalCompute(*args, **kwargs)[source]

Bases: Protocol

Optional static validation hook used by tg_model.execution.validation.validate_graph().

validate_binding(*, input_specs, output_specs)[source]

Raise ExternalComputeValidationError or ValueError when specs are inconsistent.

Parameters:
  • input_specs (Mapping[str, Any])

  • output_specs (Mapping[str, Any])

Return type:

None

tg_model.integrations.assert_sync_external(obj, *, context='')[source]

Raise TypeError if obj is an async external.

Parameters:
  • obj (object) – External implementation about to run under sync evaluation.

  • context (str, optional) – Suffix appended to the error message.

Raises:

TypeError – When is_async_external() is true.

Return type:

None

tg_model.integrations.is_async_external(obj)[source]

Return True when compute is a coroutine function.

Notes

Async externals must not run under evaluate().

Parameters:

obj (object)

Return type:

bool

Mutate binding.output_routes in place (authoring convenience).

Parameters:
Return type:

None