PTWM
ptwm

ptwm.ablation

PTWM ablation harness: resolved policy, bench-compress orchestration, attribution.

ptwm.ablation

PTWM ablation harness: resolved policy, bench-compress orchestration, attribution.

pymodule

ptwm.ablation

python/ptwm/ablation/__init__.py:1
module ptwm.ablation

PTWM ablation harness: resolved policy, bench-compress orchestration, attribution.

* _resolve.py: active-trust-aware policy resolution * _bench.py: ptwm bench compress * _compare.py: ptwm bench compare * _attribute.py: leave-one-out + Shapley * _replay.py: resolved-policy round-trip
pyfunction

ptwm.ablation.attribute_leave_one_out

python/ptwm/ablation/_attribute.py:47
def attribute_leave_one_out(input_path: str | Path, baseline_policy: str | Path | None, out_dir: str | Path, max_attributions: int = 32) -> AttributionResult

O(n) re-encodes -- one per used contribution with that id ignored.

NameTypeDescription
input_pathstr | PathPath to the raw binary input file to compress.
baseline_policystr | Path | NonePath to a TOML policy file for the baseline run, or ``None`` to use the default empty policy.
out_dirstr | PathDirectory for intermediate compressed files and CSV output.
max_attributions = 32intMaximum number of contributions to attribute. If the baseline uses more than this many contributions, only the first ``max_attributions`` are attributed.
Returns
AttributionResultOne row per attributed contribution. ``delta_bytes`` and ``delta_pct`` are zero until the ignore-policy path is wired in.
pyfunction

ptwm.ablation.attribute_shapley

python/ptwm/ablation/_attribute.py:115
def attribute_shapley(input_path: str | Path, baseline_policy: str | Path | None, out_dir: str | Path, max_attributions: int = 8) -> AttributionResult

Shapley attribution. Gated by max_attributions <= 8.

NameTypeDescription
input_pathstr | PathPath to the raw binary input file to compress.
baseline_policystr | Path | NonePath to a TOML policy file for the baseline run, or ``None`` to use the default empty policy.
out_dirstr | PathDirectory for intermediate compressed files and CSV output.
max_attributions = 8intMaximum number of contributions allowed. Raises ``ValueError`` when the baseline uses more contributions than this limit, to avoid a 2^n * n encode blowup.
Returns
AttributionResultOne row per contribution. ``delta_bytes`` and ``delta_pct`` are zero until the ignore-policy path is wired in.
Raises
  • ValueError — When the baseline references more contributions than ``max_attributions``.
pyclass

ptwm.ablation.AttributionResult

python/ptwm/ablation/_attribute.py:39
class AttributionResult:

Result of a leave-one-out or Shapley attribution run.

pymethod

ptwm.ablation.AttributionResult.__init__

python/ptwm/ablation/_attribute.py:1
def __init__(self, method: str, rows: list[AttributionRow]) -> None
pyattribute

ptwm.ablation.AttributionResult.method

python/ptwm/ablation/_attribute.py:43
method: str
pyattribute

ptwm.ablation.AttributionResult.rows

python/ptwm/ablation/_attribute.py:44
rows: list[AttributionRow]
pyclass

ptwm.ablation.AttributionRow

python/ptwm/ablation/_attribute.py:27
class AttributionRow:

Per-contribution attribution row.

pymethod

ptwm.ablation.AttributionRow.__init__

python/ptwm/ablation/_attribute.py:1
def __init__(self, contribution_id: str, label: str, baseline_size: int, without_size: int, delta_bytes: int, delta_pct: float) -> None
pyattribute

ptwm.ablation.AttributionRow.baseline_size

python/ptwm/ablation/_attribute.py:33
baseline_size: int
pyattribute

ptwm.ablation.AttributionRow.contribution_id

python/ptwm/ablation/_attribute.py:31
contribution_id: str
pyattribute

ptwm.ablation.AttributionRow.delta_bytes

python/ptwm/ablation/_attribute.py:35
delta_bytes: int
pyattribute

ptwm.ablation.AttributionRow.delta_pct

python/ptwm/ablation/_attribute.py:36
delta_pct: float
pyattribute

ptwm.ablation.AttributionRow.label

python/ptwm/ablation/_attribute.py:32
label: str
pyattribute

ptwm.ablation.AttributionRow.without_size

python/ptwm/ablation/_attribute.py:34
without_size: int
pyfunction

ptwm.ablation.bench_compare

python/ptwm/ablation/_compare.py:22
def bench_compare(a: str | Path, b: str | Path) -> CompareResult

Compare the extension tables and file sizes of two `.ptwm` files.

NameTypeDescription
astr | PathPath to the first `.ptwm` file.
bstr | PathPath to the second `.ptwm` file.
Returns
CompareResultA dataclass describing which contribution IDs are present only in *a*, only in *b*, in both, and the on-disk sizes of each file.
pyfunction

ptwm.ablation.bench_compress

python/ptwm/ablation/_bench.py:42
def bench_compress(input_path: str | Path, baseline_policy: str | Path | None, variant_policies: Iterable[str | Path], metrics: list[str], trials: int, out_dir: str | Path) -> BenchResult

Run the compressor under each policy and emit per-trial metrics.

Returns a :class:`BenchResult` holding every row; also writes ``<out_dir>/results.csv``, ``<out_dir>/per_tensor.csv``, and ``<out_dir>/summary.md``.
NameTypeDescription
input_pathstr | PathPath to the raw binary input file.
baseline_policystr | Path | NonePath to a TOML policy file for the baseline run, or ``None`` to use the default empty policy.
variant_policiesIterable[str | Path]Iterable of paths to variant policy TOML files.
metricslist[str]List of metric names to surface in the summary. v1 always captures ``ratio`` and ``encode-time``; other names are recorded in the summary for forward compatibility.
trialsintNumber of compress trials to execute per variant.
out_dirstr | PathDirectory to write ``results.csv`` and ``summary.md`` into.
pyfunction

ptwm.ablation.bench_replay

python/ptwm/ablation/_replay.py:31
def bench_replay(results_csv: str | Path, row: int, out_dir: str | Path | None = None) -> ReplayResult

Re-run a single row from a previous ``bench compress`` results CSV.

NameTypeDescription
results_csvstr | PathPath to the ``results.csv`` produced by :func:`bench_compress`.
rowintZero-based row index to replay.
out_dir = Nonestr | Path | NoneDirectory for the replayed ``.ptwm`` file. Defaults to a ``replay/`` sub-directory next to the CSV.
Returns
ReplayResultComparison of the expected (CSV) vs actual output sizes.
pyclass

ptwm.ablation.BenchResult

python/ptwm/ablation/_bench.py:35
class BenchResult:

Aggregated result from a bench compress run.

pymethod

ptwm.ablation.BenchResult.__init__

python/ptwm/ablation/_bench.py:1
def __init__(self, rows: list[BenchRow] = list()) -> None
pyattribute

ptwm.ablation.BenchResult.rows

python/ptwm/ablation/_bench.py:39
rows: list[BenchRow] = field(default_factory=list)
pyclass

ptwm.ablation.BenchRow

python/ptwm/ablation/_bench.py:19
class BenchRow:

Single per-trial metric row.

pymethod

ptwm.ablation.BenchRow.__init__

python/ptwm/ablation/_bench.py:1
def __init__(self, variant: str, trial: int, input_bytes: int, output_bytes: int, ratio: float, encode_ns: int, decode_ns: int, peak_mem_bytes: int, resolved_policy_toml: str, out_file: str) -> None
pyattribute

ptwm.ablation.BenchRow.decode_ns

python/ptwm/ablation/_bench.py:29
decode_ns: int
pyattribute

ptwm.ablation.BenchRow.encode_ns

python/ptwm/ablation/_bench.py:28
encode_ns: int
pyattribute

ptwm.ablation.BenchRow.input_bytes

python/ptwm/ablation/_bench.py:25
input_bytes: int
pyattribute

ptwm.ablation.BenchRow.out_file

python/ptwm/ablation/_bench.py:32
out_file: str
pyattribute

ptwm.ablation.BenchRow.output_bytes

python/ptwm/ablation/_bench.py:26
output_bytes: int
pyattribute

ptwm.ablation.BenchRow.peak_mem_bytes

python/ptwm/ablation/_bench.py:30
peak_mem_bytes: int
pyattribute

ptwm.ablation.BenchRow.ratio

python/ptwm/ablation/_bench.py:27
ratio: float
pyattribute

ptwm.ablation.BenchRow.resolved_policy_toml

python/ptwm/ablation/_bench.py:31
resolved_policy_toml: str
pyattribute

ptwm.ablation.BenchRow.trial

python/ptwm/ablation/_bench.py:24
trial: int
pyattribute

ptwm.ablation.BenchRow.variant

python/ptwm/ablation/_bench.py:23
variant: str
pyclass

ptwm.ablation.CompareResult

python/ptwm/ablation/_compare.py:11
class CompareResult:

Result of comparing extension tables in two `.ptwm` files.

pymethod

ptwm.ablation.CompareResult.__init__

python/ptwm/ablation/_compare.py:1
def __init__(self, only_in_a: list[tuple[str, str]], only_in_b: list[tuple[str, str]], common: list[tuple[str, str]], size_a: int, size_b: int) -> None
pyattribute

ptwm.ablation.CompareResult.common

python/ptwm/ablation/_compare.py:17
common: list[tuple[str, str]]
pyattribute

ptwm.ablation.CompareResult.only_in_a

python/ptwm/ablation/_compare.py:15
only_in_a: list[tuple[str, str]]
pyattribute

ptwm.ablation.CompareResult.only_in_b

python/ptwm/ablation/_compare.py:16
only_in_b: list[tuple[str, str]]
pyattribute

ptwm.ablation.CompareResult.size_a

python/ptwm/ablation/_compare.py:18
size_a: int
pyattribute

ptwm.ablation.CompareResult.size_b

python/ptwm/ablation/_compare.py:19
size_b: int
pyclass

ptwm.ablation.ReplayResult

python/ptwm/ablation/_replay.py:21
class ReplayResult:
pymethod

ptwm.ablation.ReplayResult.__init__

python/ptwm/ablation/_replay.py:1
def __init__(self, row_variant: str, row_trial: int, expected_output_bytes: int, actual_output_bytes: int, matches: bool, out_file: str) -> None
pyattribute

ptwm.ablation.ReplayResult.actual_output_bytes

python/ptwm/ablation/_replay.py:26
actual_output_bytes: int
pyattribute

ptwm.ablation.ReplayResult.expected_output_bytes

python/ptwm/ablation/_replay.py:25
expected_output_bytes: int
pyattribute

ptwm.ablation.ReplayResult.matches

python/ptwm/ablation/_replay.py:27
matches: bool
pyattribute

ptwm.ablation.ReplayResult.out_file

python/ptwm/ablation/_replay.py:28
out_file: str
pyattribute

ptwm.ablation.ReplayResult.row_trial

python/ptwm/ablation/_replay.py:24
row_trial: int
pyattribute

ptwm.ablation.ReplayResult.row_variant

python/ptwm/ablation/_replay.py:23
row_variant: str
pyfunction

ptwm.ablation.resolve_active

python/ptwm/ablation/_resolve.py:56
def resolve_active(policy_path: str | os.PathLike | None = None) -> ResolvedPolicy

Resolve `policy_path` against the *active* trust state.

`policy_path` may be a path to a TOML policy file or ``None`` to use the default empty policy. Callers (`ptwm bench compress`) call this once at run start and serialize the resulting TOML into every CSV row for reproducibility.