| """Deterministic question-program executors (``docs/02`` §8, ``docs/07`` §5 P3). |
| |
| Each DSL has one :class:`~explicit_learning.executors.base.Executor` that turns a |
| typed :class:`~explicit_learning.dsl.ast.Program` plus a structured |
| :class:`~explicit_learning.sources.base.World` into a deterministic |
| :class:`~explicit_learning.executors.base.ExecutionResult`. |
| :func:`get_executor` dispatches by ``Program.dsl``. |
| """ |
|
|
| from __future__ import annotations |
|
|
| from ..dsl.ast import Dsl |
| from .base import ( |
| AnswerValue, |
| ExecutionResult, |
| ExecutionStatus, |
| Executor, |
| ExecutorError, |
| dependency_closure, |
| literal_value, |
| match_choice, |
| serialize_answer, |
| trace_sha256, |
| ) |
| from .clevr import ClevrExecutor |
| from .geometry import GeometryExecutor |
| from .gqa import ( |
| GQASemanticError, |
| GQASemanticExecutor, |
| GQASemanticProgram, |
| GQASemanticStep, |
| compile_gqa_program, |
| ) |
| from .plot import PlotExecutor |
| from .table import TableExecutor |
|
|
| _REGISTRY: dict[Dsl, Executor] = { |
| "plotqa_dsl_v1": PlotExecutor(), |
| "geometry_dsl_v1": GeometryExecutor(), |
| "table_dsl_v1": TableExecutor(), |
| "clevr_dsl_v1": ClevrExecutor(), |
| } |
|
|
|
|
| def get_executor(dsl: Dsl) -> Executor: |
| """Return the deterministic executor registered for ``dsl``.""" |
| try: |
| return _REGISTRY[dsl] |
| except KeyError as exc: |
| raise ExecutorError(f"no executor registered for dsl {dsl!r}") from exc |
|
|
|
|
| __all__ = [ |
| "AnswerValue", |
| "ExecutionResult", |
| "ExecutionStatus", |
| "Executor", |
| "ExecutorError", |
| "ClevrExecutor", |
| "GQASemanticError", |
| "GQASemanticExecutor", |
| "GQASemanticProgram", |
| "GQASemanticStep", |
| "GeometryExecutor", |
| "PlotExecutor", |
| "TableExecutor", |
| "dependency_closure", |
| "compile_gqa_program", |
| "get_executor", |
| "literal_value", |
| "match_choice", |
| "serialize_answer", |
| "trace_sha256", |
| ] |
|
|