ml_switcheroo.core.ghost¶
Ghost Core: Introspection Abstraction Layer.
This module provides the data structures and inspection logic required to decouple framework analysis from the live environment. It enables the system to operate in “Ghost Mode” (WASM/CI) by working against cached snapshots instead of requiring heavy libraries (Torch/TensorFlow) to be installed.
Updates: - Robust C-Extension handling (try/except around inspect.signature). - Validates parameter kinds to support *args (VarPositional).
Classes¶
Serializable representation of a function parameter. |
|
Serializable snapshot of a Framework API component. |
|
Facade for API Inspection. |
Module Contents¶
- class ml_switcheroo.core.ghost.GhostParam(/, **data: Any)¶
Bases:
pydantic.BaseModelSerializable representation of a function parameter.
- name: str¶
- kind: str¶
- default: str | None = None¶
- annotation: str | None = None¶
- class ml_switcheroo.core.ghost.GhostRef(/, **data: Any)¶
Bases:
pydantic.BaseModelSerializable snapshot of a Framework API component.
Used by the Consensus Engine to align concepts (e.g. ‘HuberLoss’ vs ‘Huber’) without needing the framework installed at runtime.
- name: str¶
- api_path: str¶
- kind: str = None¶
- params: List[GhostParam] = None¶
- docstring: str | None = None¶
- has_varargs: bool = False¶
- has_arg(arg_name: str) bool¶
Checks if a specific argument exists in the signature.
- class ml_switcheroo.core.ghost.GhostInspector¶
Facade for API Inspection.
Responsibility: Convert Live Objects -> JSON-serializable GhostDefs. Crucial for populating snapshots used by WASM/JS environments.
- static inspect(obj: Any | Callable, api_path: str) GhostRef¶
Creates a GhostRef from a live Python object. Gracefully handles C-Extensions and builtins that resist introspection.
- Parameters:
obj – The live class or function to inspect.
api_path – The canonical string path (e.g. ‘torch.nn.ReLU’).
- Returns:
A populated GhostRef object.