File size: 1,926 Bytes
e1ced61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
"""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:  # pragma: no cover - dispatch is exhaustive
        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",
]