Metadata-Version: 2.4
Name: metewand
Version: 0.2.0
Summary: Define Metewand benchmarks with Python functions
Author-email: Johan Larsson <johan@jolars.co>
License-Expression: MIT OR Apache-2.0
Project-URL: Homepage, https://metewand.org
Project-URL: Documentation, https://metewand.org/guide/getting-started
Project-URL: Repository, https://github.com/jolars/metewand
Project-URL: Issues, https://github.com/jolars/metewand/issues
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE-APACHE
License-File: LICENSE-MIT
Dynamic: license-file

# Metewand Python package

Define Metewand benchmarks with ordinary Python functions for data generation,
methods, and independent evaluation. The package handles worker communication
and standard result files. It requires Python 3.11 or later and has no runtime
dependencies. Running benchmarks also requires a POSIX system and the separate
Metewand CLI, built with Rust 1.98.0 or later. Installing this Python package does
not install the CLI.

## Install and run

Once the first PyPI release is published, install the package into the Python
environment that will run your workers:

```sh
python3 -m venv .venv
. .venv/bin/activate
python3 -m pip install metewand
```

Install the CLI from the matching release tag, then create and run a benchmark:

```sh
metewand_version=$(python3 -c 'import metewand; print(metewand.__version__)')
cargo install --locked --git https://github.com/jolars/metewand \
  --tag "metewand-v${metewand_version}" metewand-cli
metewand init my-benchmark
cd my-benchmark
metewand check --workers
metewand run --output-dir run
metewand status --output-dir run
```

Keep the Python environment active so workers use its interpreter and installed
dependencies. The CLI creates `metewand.yaml` and `benchmark.py`, with data
generation, two methods, and independent evaluation. Choose a new output
directory for each run, or explicitly resume with `--resume`.

Before the first release, or when developing from a checkout, install both
components from the same revision instead:

```sh
git clone https://github.com/jolars/metewand.git
cd metewand
cargo install --locked --path crates/metewand-cli
python3 -m venv .venv
. .venv/bin/activate
python3 -m pip install ./packages/python
```

This is an experimental package. Use matching CLI and Python package versions,
and pin the version or source revision for retained benchmarks. Authoring syntax
and profile APIs may change before the MVP. Package versions are separate from
the versioned worker protocol and persisted record formats.

## Author benchmarks

The package implements Metewand's version-1 worker protocol, including one-shot
execution, fresh sequences, and buffered profiles. It serializes
messages, dispatches callbacks, reports structured errors, and measures the
implementation callback. The CLI owns source acquisition, seeds, scheduling,
worker lifecycle, artifact validation, and
durable publication. The package does not set random generators or infer scientific
semantics. Install scientific dependencies into the worker environment yourself.

For a simple benchmark, use `metewand init` and ordinary functions selected in
YAML with `function: benchmark.py:solve`. The package supplies the context, JSON data,
and artifact envelopes. Evaluators can return plain metrics when no scientific
rules are declared; completion is then `not_required`. See the
[least-squares example](https://github.com/jolars/metewand/tree/main/examples/least-squares)
for incremental validation.

For lifecycle adapters, subclass `OneShotImplementation` and return scientific data
from `execute`. Evaluators return `Evaluation(metrics, verdict)`. The package writes
standard envelopes; custom result and metrics writers remain supported.

See the [authoring guide](https://metewand.org/guide/authoring/),
[callback interfaces](https://github.com/jolars/metewand/blob/main/packages/python/src/metewand/_worker.py),
and the runnable
[Python package example](https://github.com/jolars/metewand/tree/main/examples/python-package).
Run the package tests from a repository checkout with:

```sh
PYTHONPATH=packages/python/src python3 -m unittest discover -s packages/python/tests -v
```

The normal Rust workspace tests also run this suite and exercise all three
Python roles through the Rust transport and output validator.

## Configuration-dependent support

Declare `capabilities: [one_shot, applicability]` and override
`check_applicability` to exclude configurations your implementation cannot
support intrinsically:

```python
def check_applicability(self, dataset_instance, dataset_manifest,
                        problem_contract, problem_parameters,
                        implementation_parameters):
    supported = not problem_parameters["intercept"]
    return {
        "outcome": "applicable" if supported else "not_applicable",
        "code": "supported" if supported else "unsupported_intercept",
        "reason": "Supported configuration." if supported else "Requires a zero intercept.",
    }
```

Both dataset arguments are `Path` objects. The callback runs in a separate
worker before measured preparation, may inspect the immutable dataset and its
manifest, and must return nonempty `code` and `reason` strings. Optional
`details` must be a dictionary. Exclusions produce no attempts; callback
exceptions fail resolution. `plan` records `unchecked` until the dataset and
worker are resolved. `explain` and `export` retain checked inputs and reasons.
