55 lines
1.8 KiB
Python
55 lines
1.8 KiB
Python
from mltrail_verifiable_provenance_ledger_for.reprobundle import ReproBundle
|
|
from mltrail_verifiable_provenance_ledger_for.contracts import Environment
|
|
|
|
|
|
def make_sample_environment():
|
|
return Environment(
|
|
id="env1",
|
|
language="python",
|
|
version="3.9",
|
|
dependencies={"numpy": "1.24.0", "pandas": "1.5.3"},
|
|
container_hash=None,
|
|
)
|
|
|
|
|
|
def test_bundle_hash_deterministic():
|
|
env = make_sample_environment()
|
|
bundle1 = ReproBundle(
|
|
code_commit="deadbeef",
|
|
environment=env,
|
|
dataset_refs=[{"id": "ds1", "fingerprint": "fp1"}],
|
|
model_ref={"id": "m1", "fingerprint": "mf1"},
|
|
run_manifest={"seed": 42, "cmd": "python train.py"},
|
|
)
|
|
bundle2 = ReproBundle(
|
|
code_commit="deadbeef",
|
|
environment=make_sample_environment(),
|
|
dataset_refs=[{"id": "ds1", "fingerprint": "fp1"}],
|
|
model_ref={"id": "m1", "fingerprint": "mf1"},
|
|
run_manifest={"seed": 42, "cmd": "python train.py"},
|
|
)
|
|
|
|
h1 = bundle1.compute_bundle_hash()
|
|
h2 = bundle2.compute_bundle_hash()
|
|
assert h1 == h2
|
|
|
|
|
|
def test_bundle_hash_changes_on_difference():
|
|
env = make_sample_environment()
|
|
base = ReproBundle(
|
|
code_commit="deadbeef",
|
|
environment=env,
|
|
dataset_refs=[{"id": "ds1", "fingerprint": "fp1"}],
|
|
model_ref={"id": "m1", "fingerprint": "mf1"},
|
|
run_manifest={"seed": 42, "cmd": "python train.py"},
|
|
)
|
|
modified = ReproBundle(
|
|
code_commit="cafebabe", # different commit
|
|
environment=env,
|
|
dataset_refs=[{"id": "ds1", "fingerprint": "fp1"}],
|
|
model_ref={"id": "m1", "fingerprint": "mf1"},
|
|
run_manifest={"seed": 42, "cmd": "python train.py"},
|
|
)
|
|
|
|
assert base.compute_bundle_hash() != modified.compute_bundle_hash()
|