Execution¶
Running a module looks up a named,
checked entry point and gives it its arguments and runtime services, separately from evaluating
its body. A provider (RuntimeProvider) binds the handlers and type validators that a run needs
and that live only in the running Python process. When a well-typed module cannot run in some
environment, the entry signature
and the available providers show what is missing.
execution
¶
Named, checked execution for whole QIEC modules.
The evaluator deliberately operates on core terms and process-local attachments. This module supplies the user-facing boundary above it: it selects a named computation, specializes its static telescope, validates host arguments and results, creates a new attachment table for every invocation, and reports failures with stable diagnostic codes.
Runtime providers are explicit. A configuration names registered provider
factories (or carries provider objects when used from Python); no module import
or ambient attachment registry is consulted by run_named.
TraceObserver
¶
A callback receiving each event an execution emits, in order.
RuntimeProviderFactory
¶
RuntimeProviderFactory = Callable[[Mapping[str, object]], RuntimeProvider]
Build a runtime provider from the options its configuration entry records.
ExecutionTraceEvent
didactic-model
¶
ExecutionTraceEvent(*, sequence: int, event: str, computation: str, detail: Mapping[str, HeldValue] = field(default_factory=dict, opaque=True, extras=OPAQUE_BY_IDENTITY))
Bases: QiecModel
One stable event emitted by a named QIEC invocation.
The detail mapping is an owned snapshot retained by identity.
| PARAMETER | DESCRIPTION |
|---|---|
sequence
|
The event's position in the invocation's trace, from zero.
TYPE:
|
event
|
The stable event name, such as
TYPE:
|
computation
|
The name of the computation being run.
TYPE:
|
detail
|
JSON-compatible event data; frozen on construction.
TYPE:
|
to_data
¶
Render the event as JSON-compatible data.
| RETURNS | DESCRIPTION |
|---|---|
dict[str, object]
|
The sequence number, event name, computation name, and detail mapping, with every detail value made JSON-compatible. |
Source code in src/quivers/qiec/execution.py
ExecutionTraceRecorder
didactic-model
¶
ExecutionTraceRecorder(*, events: list[ExecutionTraceEvent] = field(default_factory=list, opaque=True, extras=OPAQUE_BY_IDENTITY))
Bases: QiecModel
Collect events while also satisfying the :class:TraceObserver API.
The mutable event list retains its identity through record updates.
| PARAMETER | DESCRIPTION |
|---|---|
events
|
The recorded events, in order; empty to start.
TYPE:
|
__call__
¶
__call__(event: ExecutionTraceEvent) -> None
Record one event.
| PARAMETER | DESCRIPTION |
|---|---|
event
|
The event the invocation just emitted.
TYPE:
|
ExecutionDiagnostic
didactic-model
¶
ExecutionDiagnostic(*, code: str, message: str, computation: str | None = None, origin: SourceOrigin | None = field(default=None, opaque=True, extras=OPAQUE_BY_VALUE), severity: Literal['error', 'warning', 'note'] = 'error')
Bases: QiecModel
A stable failure at the source-to-host execution boundary.
| PARAMETER | DESCRIPTION |
|---|---|
code
|
The stable diagnostic code, such as
TYPE:
|
message
|
The human-readable explanation.
TYPE:
|
computation
|
The named computation involved, if any.
TYPE:
|
origin
|
The source location involved, if any.
TYPE:
|
severity
|
TYPE:
|
to_data
¶
Render the diagnostic as JSON-compatible data.
| RETURNS | DESCRIPTION |
|---|---|
dict[str, object]
|
The code, severity, message, computation name, and origin (or
|
Source code in src/quivers/qiec/execution.py
ExecutionFailure
¶
ExecutionFailure(diagnostic: ExecutionDiagnostic)
Bases: EvaluationError
Raised with a serializable diagnostic when named execution cannot run.
| PARAMETER | DESCRIPTION |
|---|---|
diagnostic
|
The failure, kept on the error as
TYPE:
|
Source code in src/quivers/qiec/execution.py
RuntimeProvider
¶
Bases: Protocol
An explicit source of process-local handlers and type validators.
attach
¶
attach(module: QiecModule, attachments: RuntimeAttachments) -> None
Bind this provider's handlers into a fresh attachment table.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The validated module whose handlers and effects are being served.
TYPE:
|
attachments
|
The per-invocation table receiving runtime handlers.
TYPE:
|
Source code in src/quivers/qiec/execution.py
validator_for
¶
validator_for(type_: TypeExpr) -> RuntimeValidator | None
Supply a host validator for a runtime type, if this provider has one.
| PARAMETER | DESCRIPTION |
|---|---|
type_
|
The closed QIEC type an argument or result must inhabit.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
RuntimeValidator | None
|
A predicate over host values, or |
Source code in src/quivers/qiec/execution.py
CoreRuntimeProvider
didactic-model
¶
CoreRuntimeProvider(*, options: Mapping[str, HeldValue] = field(default_factory=dict, opaque=True, extras=OPAQUE_BY_IDENTITY), name: str = 'core')
Bases: QiecModel
Primitive validators plus explicitly configured structural handlers.
options.handlers maps authored handler names to either
{"kind": "passthrough"}, {"kind": "state", "initial": ...},
or {"kind": "scripted", "responses": {"op": [...]}}. The source
handler still controls types, coverage, and resumption grades; options
supply only process-local clause behavior and state.
The options mapping is an owned snapshot retained by identity so configured live values keep their runtime behavior.
| PARAMETER | DESCRIPTION |
|---|---|
options
|
JSON-compatible configuration; frozen on construction.
TYPE:
|
name
|
The provider's name, reported in traces and result labels.
TYPE:
|
attach
¶
attach(module: QiecModule, attachments: RuntimeAttachments) -> None
Bind one structural handler per configured authored handler.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The validated module whose handlers the configuration names.
TYPE:
|
attachments
|
The per-invocation table receiving the constructed handlers.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If |
Source code in src/quivers/qiec/execution.py
515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 | |
validator_for
¶
validator_for(type_: TypeExpr) -> RuntimeValidator | None
Supply the primitive validator for a closed runtime type.
| PARAMETER | DESCRIPTION |
|---|---|
type_
|
The closed QIEC type an argument or result must inhabit.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
RuntimeValidator | None
|
The core validator, or |
Source code in src/quivers/qiec/execution.py
RuntimeSelection
didactic-model
¶
RuntimeSelection(*, provider: str, options: Mapping[str, HeldValue] = field(default_factory=dict, opaque=True, extras=OPAQUE_BY_IDENTITY))
Bases: QiecModel
One named provider and its JSON-compatible construction options.
The options mapping is an owned snapshot retained by identity.
| PARAMETER | DESCRIPTION |
|---|---|
provider
|
The registered or entry-point name of the provider; must be non-empty.
TYPE:
|
options
|
The options passed to the provider's factory; frozen on construction.
TYPE:
|
RuntimeConfiguration
didactic-model
¶
RuntimeConfiguration(*, selections: tuple[RuntimeSelection, ...] = field(default=(RuntimeSelection(provider='core'),), opaque=True, extras=OPAQUE_BY_VALUE), providers: tuple[RuntimeProvider, ...] = field(default=(), opaque=True, extras=OPAQUE_BY_IDENTITY))
Bases: QiecModel
Complete, explicit runtime selection for one or more invocations.
Selections compare by value; already-built providers retain identity.
| PARAMETER | DESCRIPTION |
|---|---|
selections
|
Providers to build by name for every invocation; the core provider alone by default.
TYPE:
|
providers
|
Already-built provider objects, appended after the selections when used from Python.
TYPE:
|
label
property
¶
A +-joined label naming every selected and supplied provider.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The provider names in order, or |
instantiate
¶
instantiate() -> tuple[RuntimeProvider, ...]
Build every named provider and append the programmatic ones.
| RETURNS | DESCRIPTION |
|---|---|
tuple[RuntimeProvider, ...]
|
The providers in selection order, followed by |
| RAISES | DESCRIPTION |
|---|---|
ExecutionFailure
|
With code |
Source code in src/quivers/qiec/execution.py
to_data
¶
Render the configuration as JSON-compatible data.
| RETURNS | DESCRIPTION |
|---|---|
dict[str, object]
|
The named selections with their options, and the names of any programmatic providers. |
Source code in src/quivers/qiec/execution.py
HoleRun
didactic-model
¶
HoleRun(*, evaluator: Evaluator = field(opaque=True, extras=OPAQUE_BY_IDENTITY), module: QiecModule = field(opaque=True, extras=OPAQUE_BY_IDENTITY), registry: KernelRegistry = field(opaque=True, extras=OPAQUE_BY_IDENTITY), computation: NamedComputation = field(opaque=True, extras=OPAQUE_BY_VALUE), substitution: StaticSubstitution = field(opaque=True, extras=OPAQUE_BY_VALUE), result_type: TypeExpr = field(opaque=True, extras=OPAQUE_BY_VALUE), providers: tuple[RuntimeProvider, ...] = field(opaque=True, extras=OPAQUE_BY_IDENTITY), recorder: ExecutionTraceRecorder = field(opaque=True, extras=OPAQUE_BY_IDENTITY), introduced: tuple[HoleGoal, ...] = field(default=(), opaque=True, extras=OPAQUE_BY_VALUE))
Bases: QiecModel
What continuing an indeterminate run needs.
| PARAMETER | DESCRIPTION |
|---|---|
evaluator
|
The evaluator that ran it, which holds the suspension and the fillings so far.
TYPE:
|
module
|
The module run.
TYPE:
|
registry
|
Its resolved declarations, against which fillings are checked.
TYPE:
|
computation
|
The computation run.
TYPE:
|
substitution
|
The static specialization of the run, applied to each filling.
TYPE:
|
result_type
|
The specialized result type the run's value is validated against.
TYPE:
|
providers
|
The runtime providers whose validators cover the result.
TYPE:
|
recorder
|
The trace of the run so far, which a resumption extends.
TYPE:
|
introduced
|
The goals of holes that earlier fillings contained, each in the context of the hole its filling filled.
TYPE:
|
ExecutionResult
didactic-model
¶
ExecutionResult(*, computation: str, value: HeldValue = field(opaque=True, extras=OPAQUE_BY_IDENTITY), result_type: TypeExpr = field(opaque=True, extras=OPAQUE_BY_VALUE), runtime: str, trace: tuple[ExecutionTraceEvent, ...] = field(opaque=True, extras=OPAQUE_BY_VALUE), continuation: HoleRun | None = field(default=None, opaque=True, extras=OPAQUE_BY_IDENTITY))
Bases: QiecModel
The checked value and trace produced by one named invocation.
The host result retains identity. Its checked type and trace records compare by value.
| PARAMETER | DESCRIPTION |
|---|---|
computation
|
The name of the computation run.
TYPE:
|
value
|
The validated host result.
TYPE:
|
result_type
|
The computation's result type under its specialization.
TYPE:
|
runtime
|
The label of the runtime configuration used.
TYPE:
|
trace
|
Every event the invocation emitted, in order; empty for a run that does not record them.
TYPE:
|
continuation
|
For a run whose value is
TYPE:
|
indeterminate
property
¶
Whether the run's value depends on a typed hole with no filling.
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True when the value is an |
to_data
¶
Render the result as JSON-compatible data.
| RETURNS | DESCRIPTION |
|---|---|
dict[str, object]
|
|
Source code in src/quivers/qiec/execution.py
available_runtime_providers
¶
Return built-in and installed quivers.qiec_runtime entry points.
| RETURNS | DESCRIPTION |
|---|---|
tuple[str, ...]
|
Every selectable provider name, sorted. |
Source code in src/quivers/qiec/execution.py
register_runtime_provider
¶
register_runtime_provider(name: str, factory: RuntimeProviderFactory) -> None
Register a provider factory for explicit configuration by name.
Registration makes a provider selectable; it never activates that provider for an invocation. Replacing an existing name is rejected so plugin load order cannot silently change execution semantics.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The name a configuration uses to select the provider.
TYPE:
|
factory
|
The callable building a provider from JSON-compatible options.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If |
Source code in src/quivers/qiec/execution.py
runtime_configuration_from_data
¶
runtime_configuration_from_data(data: object) -> RuntimeConfiguration
Decode the non-executable JSON runtime configuration format.
| PARAMETER | DESCRIPTION |
|---|---|
data
|
The decoded JSON document;
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
RuntimeConfiguration
|
The selections in document order, with no programmatic providers. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If |
Source code in src/quivers/qiec/execution.py
load_runtime_configuration
¶
load_runtime_configuration(path: str | Path) -> RuntimeConfiguration
Load an explicit runtime selection without importing executable code.
| PARAMETER | DESCRIPTION |
|---|---|
path
|
A JSON file in the format :func:
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
RuntimeConfiguration
|
The decoded selection. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the file cannot be read, is not valid JSON, or does not decode as a runtime configuration. |
Source code in src/quivers/qiec/execution.py
parse_static_arguments
¶
parse_static_arguments(module: QiecModule, computation: str, assignments: tuple[str, ...]) -> tuple[StaticArgument, ...]
Resolve CLI NAME=TERM specializations in telescope order.
This intentionally accepts only closed, nominal terms available in the module: primitive or declared types, closed index constructors/literals, and declared effect applications. Static variables and inferred holes are not runtime configuration values.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The module declaring
TYPE:
|
computation
|
The named computation whose telescope is being instantiated.
TYPE:
|
assignments
|
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[StaticArgument, ...]
|
The parsed arguments in the telescope's order. |
| RAISES | DESCRIPTION |
|---|---|
ExecutionFailure
|
With code |
Source code in src/quivers/qiec/execution.py
1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 | |
run_named
¶
run_named(module: QiecModule, computation: str, arguments: tuple[object, ...] = (), *, static_arguments: tuple[StaticArgument, ...] = (), runtime: RuntimeConfiguration | None = None, observer: TraceObserver | None = None, record_trace: bool = True, fuel: int | None = None, numbers: NumberDomain | None = None, distributions: DistributionBackend | None = None) -> ExecutionResult
Validate and execute one named computation from module.
The attachment table and every configured provider instance are allocated inside this call. Mutable handler state can thus never leak from one named invocation to the next.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The module declaring the computation; it is validated before the body is evaluated.
TYPE:
|
computation
|
The name of the computation to run.
TYPE:
|
arguments
|
Host values for the computation's value parameters, in order.
TYPE:
|
static_arguments
|
Closed terms instantiating the computation's telescope, in order; required whenever the telescope is non-empty.
TYPE:
|
runtime
|
The providers to attach; defaults to the core provider alone.
TYPE:
|
observer
|
A callback receiving every trace event as it is emitted.
TYPE:
|
record_trace
|
Whether the result keeps every event. A run emits events in proportion to its machine steps, so a run of unknown length that records them has no bound on the memory it holds; one that does not holds only its live state. An observer receives the events either way, and with neither the machine builds none.
TYPE:
|
fuel
|
The number of machine steps the run may take, or
TYPE:
|
numbers
|
The dtype and device of the run's numbers. Python numbers are
double precision, so a run of host values defaults to
TYPE:
|
distributions
|
The backend that samples and scores the run's distributions; the
installed backend when
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ExecutionResult
|
The validated result value, its specialized type, the runtime label, and the full trace, empty when the run does not record it. |
| RAISES | DESCRIPTION |
|---|---|
ExecutionFailure
|
With code |
Source code in src/quivers/qiec/execution.py
1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 | |
resume_run
¶
resume_run(result: ExecutionResult, fills: Mapping[str, Value]) -> ExecutionResult
Fill typed holes of an indeterminate run and continue it.
Each filling is checked against the goal of every hole of its name (its type, in the context of bindings the hole sees), then the run continues where it stopped: a run suspended at a step that needed a hole replays that step and goes on; a run that finished with holes in its value has them replaced. Nothing that ran before the suspension runs again, so effects already performed are not repeated.
| PARAMETER | DESCRIPTION |
|---|---|
result
|
An indeterminate result of
TYPE:
|
fills
|
A filling per hole name. A filling may mention the bindings the hole sees, and may itself contain holes.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ExecutionResult
|
The continued run's result, indeterminate again if it needs a hole that is still open. |
| RAISES | DESCRIPTION |
|---|---|
ExecutionFailure
|
With code |
Source code in src/quivers/qiec/execution.py
2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 | |