ml_switcheroo.generated_tests.generator¶

Dynamic Test Code Generator (Physical Synthesizer).

This module is responsible for creating physical Python test files based on the Semantic Knowledge Base.

It operations in two stages: 1. Template Resolution: It aggregates execution templates (import, convert_input, to_numpy)

from the SemanticsManager, prioritizing overlays (snapshots) over registry defaults.

  1. Code Emission: It iterates over Operations in the Spec, generating def test_gen_<opname>() functions that: - Generate random inputs using type hints. - Execute the operation across all available backends (Torch, JAX, etc.). - Compare outputs using np.allclose. - Verify Output Shape if output_shape_calc is defined in the ODL.

JIT Logic:

If a template specifies jit_wrap: True (e.g., JAX), the generator inspects the framework traits to identify static_argnums (arguments like axis or keepdims) and generates valid jax.jit(fn, static_argnums=(…)) wrappers.

Classes¶

TestGenerator

Generates Pytest-compatible test files from Semantic Operations.

Module Contents¶

class ml_switcheroo.generated_tests.generator.TestGenerator(semantics_mgr: ml_switcheroo.semantics.manager.SemanticsManager | None = None)¶

Generates Pytest-compatible test files from Semantic Operations.

semantics_mgr¶

Source for op definitions and backend templates.

Type:

SemanticsManager

_processed_fws¶

Tracks which frameworks were seen to optimize imports.

Type:

Set[str]

semantics_mgr¶
generate(semantics: Dict[str, Any], output_path: pathlib.Path) → None¶

Generates a test file containing functions for each operation in semantics.

Parameters:
  • semantics – Dictionary of operations (result of mgr.get_known_apis()).

  • output_path – Destination path for the .py file.