Skip to content

Structural runtime

This module runs checked encoder, decoder, and structural loss computations through registered Python implementations (differentiating through a run). A run needs a provider for each requested operation, and a transpile target must support those operations to run the translated computation.

FiniteDecoderSupport checks a supplied set of closed structural terms against one object sort of the decoder's shared rule presentation. Its distribution(code) produces a finite law on those terms in the presentation's nominal QIEC family.

structural_runtime

Run host-backed structural computations on the reference machine.

PreparedDecoderSupport didactic-model

PreparedDecoderSupport(*, sort: str, max_candidates: int, families: SignatureFamilies = field(opaque=True, extras=OPAQUE_BY_VALUE), candidates: tuple = field(opaque=True, extras=OPAQUE_BY_VALUE), layout: tuple = field(opaque=True, extras=OPAQUE_BY_VALUE))

Bases: ValueModel

Static candidates, kept independently of a live neural decoder.

PARAMETER DESCRIPTION
sort

The structural sort.

TYPE: str

max_candidates

The bound used to prepare this support.

TYPE: int

families

The signature's families, whose root family the points inhabit.

TYPE: SignatureFamilies DEFAULT: field(opaque=True, extras=OPAQUE_BY_VALUE)

candidates

Pairs of typed run-time values and their source structural terms.

TYPE: tuple DEFAULT: field(opaque=True, extras=OPAQUE_BY_VALUE)

layout

The support-defining decoder declarations.

TYPE: tuple DEFAULT: field(opaque=True, extras=OPAQUE_BY_VALUE)

element property

element: TypeApplication

The type of a point.

RETURNS DESCRIPTION
TypeApplication

The family of the support's sort.

distribution

distribution(decoder: Decoder, code: Tensor) -> FiniteSampleable

Score this support with the decoder at the current invocation.

PARAMETER DESCRIPTION
decoder

The same structural decoder configuration and a floating code of the declared width, with any live parameters.

TYPE: Decoder

code

The same structural decoder configuration and a floating code of the declared width, with any live parameters.

TYPE: Decoder

RETURNS DESCRIPTION
FiniteSampleable

The fixed typed points with fresh differentiable log weights.

RAISES DESCRIPTION
ValueError

If the code or decoder configuration does not match the support.

Source code in src/quivers/qiec/structural_runtime.py
def distribution(self, decoder: Decoder, code: torch.Tensor) -> FiniteSampleable:
    """Score this support with the decoder at the current invocation.

    Parameters
    ----------
    decoder, code
        The same structural decoder configuration and a floating code of
        the declared width, with any live parameters.

    Returns
    -------
    FiniteSampleable
        The fixed typed points with fresh differentiable log weights.

    Raises
    ------
    ValueError
        If the code or decoder configuration does not match the support.
    """
    width = decoder.sort_dims.get(self.sort)
    if width is None:
        raise ValueError(
            f"the decoder has no embedding width for sort {self.sort!r}"
        )
    if (
        not isinstance(code, torch.Tensor)
        or code.shape != (width,)
        or not code.is_floating_point()
    ):
        raise ValueError(
            f"decoder support expects one code of shape ({width},) with floating dtype"
        )
    if _decoder_layout(decoder) != self.layout:
        raise ValueError(
            "the finite decoder support's signature, depth or vocabulary changed"
        )
    values, terms = zip(*self.candidates, strict=True)
    masses = torch.stack(
        [decoder.log_prob(term, code, sort=self.sort) for term in terms]
    )
    return FiniteSampleable(
        element=self.element,
        values=values,
        log_weights=masses,
        registry=self.families.registry,
    )

FiniteDecoderSupport didactic-model

FiniteDecoderSupport(*, decoder: Decoder = field(opaque=True, extras=OPAQUE_BY_IDENTITY), sort: str, candidates: tuple[Term, ...] = field(opaque=True, extras=OPAQUE_BY_VALUE), max_candidates: int, module: str = '')

Bases: QiecModel

A decoder restricted to an explicit finite set of closed terms.

The candidates are values of the signature's sort family in a module (see quivers.structural.families), so a draw from the law is an ordinary family value that computations analyze by cases. Repeated identical candidates name the same term. Only first-order term signatures are supported, since a closed candidate of a binding signature would need variables in its scopes.

PARAMETER DESCRIPTION
decoder

The decoder whose log probability determines the conditional law.

TYPE: Decoder DEFAULT: field(opaque=True, extras=OPAQUE_BY_IDENTITY)

sort

The object sort of the candidates.

TYPE: str

candidates

The supplied finite support. Every term must be in the decoder's domain, including its depth and data-vocabulary restrictions.

TYPE: tuple[Term, ...] DEFAULT: field(opaque=True, extras=OPAQUE_BY_VALUE)

max_candidates

A positive bound on the number of supplied entries, checked before validating terms. Exceeding the bound refuses the entire support.

TYPE: int

module

The module whose families the candidates are values of; the signature's own name when empty.

TYPE: str DEFAULT: ''

families cached property

The families the candidates are values of.

RETURNS DESCRIPTION
SignatureFamilies

The signature's families in the support's module.

element property

element: TypeApplication

The nominal QIEC type of a point of this support.

RETURNS DESCRIPTION
TypeApplication

The family of the selected structural sort.

complete classmethod

complete(decoder: Decoder, *, sort: str, max_candidates: int, module: str = '') -> FiniteDecoderSupport

Prepare the complete support of a productive depth-bounded decoder.

PARAMETER DESCRIPTION
decoder

The first-order decoder and its depth bound.

TYPE: Decoder

sort

The root object sort to expand.

TYPE: str

max_candidates

The most terms to materialize. It must be positive.

TYPE: int

module

The module whose families the candidates are values of.

TYPE: str DEFAULT: ''

RETURNS DESCRIPTION
FiniteDecoderSupport

Every term admitted by the given structural decoder at this root. When its local distributions are valid, its normalized law agrees with the original decoder.

RAISES DESCRIPTION
ValueError

If a reachable branch is unproductive, the domain is unsupported, or the number of terms exceeds the bound.

Source code in src/quivers/qiec/structural_runtime.py
@classmethod
def complete(
    cls,
    decoder: Decoder,
    *,
    sort: str,
    max_candidates: int,
    module: str = "",
) -> FiniteDecoderSupport:
    """Prepare the complete support of a productive depth-bounded decoder.

    Parameters
    ----------
    decoder
        The first-order decoder and its depth bound.
    sort
        The root object sort to expand.
    max_candidates
        The most terms to materialize. It must be positive.
    module
        The module whose families the candidates are values of.

    Returns
    -------
    FiniteDecoderSupport
        Every term admitted by the given structural decoder at this root.
        When its local distributions are valid, its normalized law
        agrees with the original decoder.

    Raises
    ------
    ValueError
        If a reachable branch is unproductive, the domain is unsupported,
        or the number of terms exceeds the bound.
    """
    if not decoder.signature.is_first_order():
        raise ValueError("finite decoder support requires a first-order signature")
    return cls(
        decoder=decoder,
        candidates=decoder.complete_support(sort, max_candidates),
        sort=sort,
        max_candidates=max_candidates,
        module=module,
    )

distribution

distribution(code: Tensor) -> FiniteSampleable

Build the conditional decoder law at one unbatched code.

PARAMETER DESCRIPTION
code

One embedding of the selected object sort.

TYPE: Tensor

RETURNS DESCRIPTION
FiniteSampleable

The same supplied terms with freshly evaluated log masses, normalized over this set by the finite sampleable.

RAISES DESCRIPTION
ValueError

If the code has the wrong shape or the decoder's signature, depth or vocabularies have changed.

RuntimeError

If a supplied term violates the decoder's depth or vocabulary restriction, or the decoder lacks a required component.

DistributionError

If the finite law has no positive mass or invalid log masses.

Source code in src/quivers/qiec/structural_runtime.py
def distribution(self, code: torch.Tensor) -> FiniteSampleable:
    """Build the conditional decoder law at one unbatched code.

    Parameters
    ----------
    code
        One embedding of the selected object sort.

    Returns
    -------
    FiniteSampleable
        The same supplied terms with freshly evaluated log masses,
        normalized over this set by the finite sampleable.

    Raises
    ------
    ValueError
        If the code has the wrong shape or the decoder's signature,
        depth or vocabularies have changed.
    RuntimeError
        If a supplied term violates the decoder's depth or vocabulary
        restriction, or the decoder lacks a required component.
    DistributionError
        If the finite law has no positive mass or invalid log masses.
    """
    return self._prepared.distribution(self.decoder, code)

StructuralRuntimeProvider didactic-model

StructuralRuntimeProvider(*, runtimes: tuple[RuntimeHandler, ...] = field(opaque=True, extras=OPAQUE_BY_IDENTITY), term_types: Mapping[TypeId, tuple[SignatureFamilies, str]] = field(default=MappingProxyType({}), opaque=True, extras=OPAQUE_BY_VALUE), graph_types: frozenset[TypeId] = field(default=frozenset(), opaque=True, extras=OPAQUE_BY_VALUE), name: str = 'structural')

Bases: QiecModel

PyTorch components and validators for one structural invocation.

PARAMETER DESCRIPTION
runtimes

The host handlers implementing the module's structural computations.

TYPE: tuple[RuntimeHandler, ...] DEFAULT: field(opaque=True, extras=OPAQUE_BY_IDENTITY)

term_types

Type identities of signature sort families, with their families and sorts; a value of one is a runtime constructor of the family.

TYPE: Mapping[TypeId, tuple[SignatureFamilies, str]] DEFAULT: field(default=MappingProxyType({}), opaque=True, extras=OPAQUE_BY_VALUE)

graph_types

Type identities of graph families, whose host values are structural :class:Term instances.

TYPE: frozenset[TypeId] DEFAULT: field(default=frozenset(), opaque=True, extras=OPAQUE_BY_VALUE)

name

The provider name recorded in execution results and traces.

TYPE: str DEFAULT: 'structural'

attach

attach(module: QiecModule, attachments: RuntimeAttachments) -> None

Attach each host computation handler.

PARAMETER DESCRIPTION
module

The checked module, unused because the handlers were selected while constructing this provider.

TYPE: QiecModule

attachments

The invocation's attachment table.

TYPE: RuntimeAttachments

Source code in src/quivers/qiec/structural_runtime.py
def attach(self, module: QiecModule, attachments: RuntimeAttachments) -> None:
    """Attach each host computation handler.

    Parameters
    ----------
    module
        The checked module, unused because the handlers were selected
        while constructing this provider.
    attachments
        The invocation's attachment table.
    """

    del module
    for runtime in self.runtimes:
        attachments.bind_handler(runtime)

validator_for

validator_for(type_: TypeExpr) -> RuntimeValidator | None

Return the validator for structural values and torch values.

PARAMETER DESCRIPTION
type_

The closed QIEC type a host argument or result must inhabit.

TYPE: TypeExpr

RETURNS DESCRIPTION
RuntimeValidator | None

A predicate for scalar weights, family values, graphs, tensors, and structural products, or None when the provider does not cover type_.

Source code in src/quivers/qiec/structural_runtime.py
def validator_for(self, type_: TypeExpr) -> RuntimeValidator | None:
    """Return the validator for structural values and torch values.

    Parameters
    ----------
    type_
        The closed QIEC type a host argument or result must inhabit.

    Returns
    -------
    RuntimeValidator | None
        A predicate for scalar weights, family values, graphs, tensors,
        and structural products, or ``None`` when the provider does not
        cover ``type_``.
    """

    if type_ == REAL or type_ == LOG_WEIGHT:
        return lambda value: (
            isinstance(value, int | float)
            and not isinstance(value, bool)
            or isinstance(value, torch.Tensor)
            and value.shape == ()
        )
    if (
        isinstance(type_, TypeApplication)
        and type_.constructor.id in self.term_types
    ):
        return lambda value: (
            isinstance(value, RuntimeConstructor) and value.result_type == type_
        )
    if (
        isinstance(type_, TypeApplication)
        and type_.constructor.id in self.graph_types
    ):
        return lambda value: isinstance(value, Term)
    if tensor_shape(type_) is not None:
        return lambda value: _tensor_value(type_, value)
    if isinstance(type_, TypeApplication) and type_.constructor.name.startswith(
        "Product"
    ):
        components = tuple(
            item for item in type_.arguments if isinstance(item, TypeApplication)
        )
        validators = tuple(self.validator_for(item) for item in components)
        if len(validators) != len(type_.arguments) or any(
            validator is None for validator in validators
        ):
            return None

        def product(value: object) -> bool:
            """Check a structural product componentwise.

            Parameters
            ----------
            value
                The host value to validate against the product type.

            Returns
            -------
            bool
                Whether ``value`` is a tuple whose components pass the
                corresponding validators.
            """

            return (
                isinstance(value, tuple)
                and len(value) == len(validators)
                and all(
                    validator is not None and validator(item)
                    for validator, item in zip(validators, value, strict=True)
                )
            )

        return product
    return None

prepared_support

prepared_support(decoder: Decoder, module: str) -> PreparedDecoderSupport

A bounded decoder's complete support as values of a module's families.

PARAMETER DESCRIPTION
decoder

A decoder whose declaration bounds its support; compilation records the bound and the checked candidate terms on it.

TYPE: Decoder

module

The module whose families the points are values of.

TYPE: str

RETURNS DESCRIPTION
PreparedDecoderSupport

The support, prepared once per decoder and module.

RAISES DESCRIPTION
TypeError

If the decoder declares no bounded support.

Source code in src/quivers/qiec/structural_runtime.py
def prepared_support(decoder: Decoder, module: str) -> PreparedDecoderSupport:
    """A bounded decoder's complete support as values of a module's families.

    Parameters
    ----------
    decoder
        A decoder whose declaration bounds its support; compilation records
        the bound and the checked candidate terms on it.
    module
        The module whose families the points are values of.

    Returns
    -------
    PreparedDecoderSupport
        The support, prepared once per decoder and module.

    Raises
    ------
    TypeError
        If the decoder declares no bounded support.
    """
    terms = decoder.support_terms
    limit = decoder.support_limit
    if terms is None or limit is None:
        raise TypeError(f"decoder {decoder.name!r} declares no bounded support")
    by_module = _PREPARED.setdefault(decoder, {})
    known = by_module.get(module)
    if known is None:
        known = FiniteDecoderSupport(
            decoder=decoder,
            sort=decoder._resolve_sort(None),
            candidates=terms,
            max_candidates=limit,
            module=module,
        )._prepared
        by_module[module] = known
    return known

module_families

module_families(module: QiecModule, program: Program) -> dict[TypeId, tuple[SignatureFamilies, str]]

The sort families of a compiled program's term signatures in a module.

PARAMETER DESCRIPTION
module

The checked module.

TYPE: QiecModule

program

The compiled program, which holds the runtime signatures.

TYPE: Program

RETURNS DESCRIPTION
dict

Each family's type identity with its families and sort.

Source code in src/quivers/qiec/structural_runtime.py
def module_families(
    module: QiecModule, program: quivers.program.Program
) -> dict[TypeId, tuple[SignatureFamilies, str]]:
    """The sort families of a compiled program's term signatures in a module.

    Parameters
    ----------
    module
        The checked module.
    program
        The compiled program, which holds the runtime signatures.

    Returns
    -------
    dict
        Each family's type identity with its families and sort.
    """
    found: dict[TypeId, tuple[SignatureFamilies, str]] = {}
    declared = {family.type_constructor.id for family in module.families}
    for signature in getattr(program, "syntaxes", {}).values():
        if not isinstance(signature, Signature) or signature.is_graph():
            continue
        families = signature_families(signature, module.module)
        for sort, family in families.families.items():
            identity = family.type_constructor.id
            if identity in declared:
                found[identity] = (families, sort)
    return found

structural_handler_definition

structural_handler_definition(effect: EffectRef, result: TypeExpr, *, instance_name: str, computation_name: str) -> HandlerDef

Build the stable checked handler signature for one neural attachment.

PARAMETER DESCRIPTION
effect

The applied Compute interface served by the attachment.

TYPE: EffectRef

result

The closed result type returned by the host component.

TYPE: TypeExpr

instance_name

The source-derived effect-instance name.

TYPE: str

computation_name

The source-derived structural computation name.

TYPE: str

RETURNS DESCRIPTION
HandlerDef

A stable foreign handler declaration for the component.

Source code in src/quivers/qiec/structural_runtime.py
def structural_handler_definition(
    effect: EffectRef,
    result: TypeExpr,
    *,
    instance_name: str,
    computation_name: str,
) -> HandlerDef:
    """Build the stable checked handler signature for one neural attachment.

    Parameters
    ----------
    effect
        The applied ``Compute`` interface served by the attachment.
    result
        The closed result type returned by the host component.
    instance_name
        The source-derived effect-instance name.
    computation_name
        The source-derived structural computation name.

    Returns
    -------
    HandlerDef
        A stable foreign handler declaration for the component.
    """

    runtime = compute_handler(
        lambda argument, _context: argument,
        effect=effect,
        result_validator=lambda _value: True,
        answer_type=result,
        key=f"structural-{instance_name}-{computation_name}",
    )
    return runtime.definition.with_(
        name=f"__structural_{instance_name}_{computation_name}",
    )

structural_runtime_provider

structural_runtime_provider(module: QiecModule, program: Program) -> StructuralRuntimeProvider

Build the typed neural-attachment provider for a compiled module.

PARAMETER DESCRIPTION
module

The checked QIEC module whose structural instances need handlers.

TYPE: QiecModule

program

The compiled container supplying the corresponding PyTorch objects.

TYPE: Program

RETURNS DESCRIPTION
StructuralRuntimeProvider

A provider containing one validated runtime handler per structural instance.

RAISES DESCRIPTION
TypeError

If a structural component returns a type with no host validator.

Source code in src/quivers/qiec/structural_runtime.py
def structural_runtime_provider(
    module: QiecModule,
    program: quivers.program.Program,
) -> StructuralRuntimeProvider:
    """Build the typed neural-attachment provider for a compiled module.

    Parameters
    ----------
    module
        The checked QIEC module whose structural instances need handlers.
    program
        The compiled container supplying the corresponding PyTorch objects.

    Returns
    -------
    StructuralRuntimeProvider
        A provider containing one validated runtime handler per structural
        instance.

    Raises
    ------
    TypeError
        If a structural component returns a type with no host validator.
    """

    types = StructuralRuntimeProvider(
        runtimes=(),
        term_types=MappingProxyType(module_families(module, program)),
        graph_types=_graph_types(module, program),
    )
    runtimes: list[RuntimeHandler] = []
    for instance in module.instances:
        if instance.origin.structural_path[:1] != ("structural",):
            continue
        result_type = instance.entry.effect.arguments[1]
        assert isinstance(result_type, TypeApplication)
        component_name = str(instance.origin.structural_path[2])
        validator = _validator_for(
            result_type,
            types,
            decoder_law=instance.origin.structural_path[1] == "decoder-law",
        )
        if validator is None:
            raise TypeError(
                f"structural component {component_name!r} has no validator for "
                f"{result_type!r}"
            )
        runtime = compute_handler(
            _component_function(program, module, instance),
            effect=instance.entry.effect,
            result_validator=validator,
            answer_type=result_type,
            key=f"structural-{instance.name}-{component_name}",
        )
        runtime = runtime.with_(
            definition=structural_handler_definition(
                instance.entry.effect,
                result_type,
                instance_name=instance.name,
                computation_name=component_name,
            )
        )
        runtimes.append(runtime)
    return types.with_(runtimes=tuple(runtimes))

structural_runtime_configuration

structural_runtime_configuration(module: QiecModule, program: Program) -> RuntimeConfiguration

Return the standard runtime configuration for structural entries.

PARAMETER DESCRIPTION
module

The checked QIEC module whose structural entries may be invoked.

TYPE: QiecModule

program

The compiled container supplying their PyTorch attachments.

TYPE: Program

RETURNS DESCRIPTION
RuntimeConfiguration

A configuration selecting the structural provider when the module has structural runtimes, or no providers otherwise.

Source code in src/quivers/qiec/structural_runtime.py
def structural_runtime_configuration(
    module: QiecModule,
    program: quivers.program.Program,
) -> RuntimeConfiguration:
    """Return the standard runtime configuration for structural entries.

    Parameters
    ----------
    module
        The checked QIEC module whose structural entries may be invoked.
    program
        The compiled container supplying their PyTorch attachments.

    Returns
    -------
    RuntimeConfiguration
        A configuration selecting the structural provider when the module has
        structural runtimes, or no providers otherwise.
    """

    provider = structural_runtime_provider(module, program)
    return RuntimeConfiguration(
        providers=(provider,) if provider.runtimes else (),
    )

host_arguments

host_arguments(module: QiecModule, program: Program, name: str, arguments: Sequence[object]) -> tuple[object, ...]

Read structural terms given to a computation as family values.

A value of a signature's sort family is a structural Term at the host boundary; each argument whose parameter is such a family and which is given as a term is converted to the family's runtime value.

PARAMETER DESCRIPTION
module

The checked module.

TYPE: QiecModule

program

The compiled program.

TYPE: Program

name

The computation's name.

TYPE: str

arguments

Its host arguments.

TYPE: Sequence[object]

RETURNS DESCRIPTION
tuple

The arguments, terms converted.

Source code in src/quivers/qiec/structural_runtime.py
def host_arguments(
    module: QiecModule,
    program: quivers.program.Program,
    name: str,
    arguments: Sequence[object],
) -> tuple[object, ...]:
    """Read structural terms given to a computation as family values.

    A value of a signature's sort family is a structural `Term` at the
    host boundary; each argument whose parameter is such a family and which
    is given as a term is converted to the family's runtime value.

    Parameters
    ----------
    module
        The checked module.
    program
        The compiled program.
    name
        The computation's name.
    arguments
        Its host arguments.

    Returns
    -------
    tuple
        The arguments, terms converted.
    """
    computation = next((c for c in module.computations if c.name == name), None)
    if computation is None:
        return tuple(arguments)
    families = module_families(module, program)
    converted: list[object] = []
    for parameter, argument in zip(computation.parameters, arguments):
        found = (
            families.get(parameter.type.constructor.id)
            if isinstance(parameter.type, TypeApplication)
            else None
        )
        if found is not None and isinstance(argument, Term):
            converted.append(found[0].value(argument, found[1]))
        else:
            converted.append(argument)
    converted.extend(arguments[len(converted) :])
    return tuple(converted)

host_result

host_result(module: QiecModule, program: Program, value: object) -> object

Read a family value returned to the host as a structural term.

PARAMETER DESCRIPTION
module

The checked module.

TYPE: QiecModule

program

The compiled program.

TYPE: Program

value

A returned value.

TYPE: object

RETURNS DESCRIPTION
object

The structural term when the value belongs to a signature family, the value unchanged otherwise.

Source code in src/quivers/qiec/structural_runtime.py
def host_result(
    module: QiecModule, program: quivers.program.Program, value: object
) -> object:
    """Read a family value returned to the host as a structural term.

    Parameters
    ----------
    module
        The checked module.
    program
        The compiled program.
    value
        A returned value.

    Returns
    -------
    object
        The structural term when the value belongs to a signature family,
        the value unchanged otherwise.
    """
    if not isinstance(value, RuntimeConstructor) or not isinstance(
        value.result_type, TypeApplication
    ):
        return value
    found = module_families(module, program).get(value.result_type.constructor.id)
    if found is None:
        return value
    return found[0].term(value)

run_structural

run_structural(module: QiecModule, program: Program, name: str, arguments: Sequence[object], *, fuel: int | None = None) -> ExecutionResult

Run a structural computation through the compiled PyTorch attachments.

Structural terms given for a family parameter are converted to family values; the result keeps the machine's representation.

PARAMETER DESCRIPTION
module

The checked QIEC module.

TYPE: QiecModule

program

The classic compiled container supplying encoders, decoders, losses, and their learned tensors.

TYPE: Program

name

The structural computation name.

TYPE: str

arguments

Its host arguments.

TYPE: Sequence[object]

fuel

Optional reference-machine step budget.

TYPE: int | None DEFAULT: None

RETURNS DESCRIPTION
ExecutionResult

The typed result and trace. Torch tensor results retain their autograd graph back to the attached component parameters.

RAISES DESCRIPTION
KeyError

If name is not a structural computation.

Source code in src/quivers/qiec/structural_runtime.py
def run_structural(
    module: QiecModule,
    program: quivers.program.Program,
    name: str,
    arguments: Sequence[object],
    *,
    fuel: int | None = None,
) -> ExecutionResult:
    """Run a structural computation through the compiled PyTorch attachments.

    Structural terms given for a family parameter are converted to family
    values; the result keeps the machine's representation.

    Parameters
    ----------
    module
        The checked QIEC module.
    program
        The classic compiled container supplying encoders, decoders, losses,
        and their learned tensors.
    name
        The structural computation name.
    arguments
        Its host arguments.
    fuel
        Optional reference-machine step budget.

    Returns
    -------
    ExecutionResult
        The typed result and trace. Torch tensor results retain their autograd
        graph back to the attached component parameters.

    Raises
    ------
    KeyError
        If ``name`` is not a structural computation.
    """

    computation = next(
        (
            item
            for item in module.computations
            if item.name == name and item.origin.structural_path[:1] == ("structural",)
        ),
        None,
    )
    if computation is None:
        raise KeyError(
            f"module {module.module!r} has no structural computation {name!r}"
        )
    return run_named(
        module,
        computation.name,
        host_arguments(module, program, name, arguments),
        runtime=structural_runtime_configuration(module, program),
        fuel=fuel,
    )