Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✅ Add a test for tracking with params #80

Merged
merged 3 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lamin_cli/_save.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def get_stem_uid_and_version_from_file(
"\nCall `ln.track()` and copy/paste the output"
" into the notebook"
)
logger.important(f"mapped '{file_path}' on uid '{uid}'")
return uid, stem_uid, version


Expand Down
35 changes: 35 additions & 0 deletions tests/scripts/run-track-with-params.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import argparse
import lamindb as ln


# this section should typically be outside of the script
ln.Param(name="dataset_key", dtype="str").save()
ln.Param(name="learning_rate", dtype="float").save()
ln.Param(name="downsample", dtype="bool").save()
ln.Param(name="split", dtype="str").save()


def main():
parser = argparse.ArgumentParser(description="A demo script.")
parser.add_argument("--dataset-key", type=str)
parser.add_argument("--downsample", action="store_true", help="Downsample")
parser.add_argument("--split", choices=["train", "test", "validation"])
parser.add_argument("--learning-rate", type=float)
args = parser.parse_args()

params = {
"dataset_key": args.dataset_key,
"learning_rate": args.learning_rate,
"downsample": args.downsample,
"split": args.split,
}

ln.track("JjRF4mACd9m00000", params=params)

# actually do stuff

ln.finish()


if __name__ == "__main__":
main()
34 changes: 34 additions & 0 deletions tests/test_save_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,37 @@ def test_run_save_cache():
)
print(result.stderr.decode())
assert result.returncode == 0


def test_run_save_with_params():
env = os.environ
env["LAMIN_TESTING"] = "true"
filepath = scripts_dir / "run-track-with-params.py"

# run the script
result = subprocess.run(
f"python {filepath} --dataset-key mydata --learning-rate 0.01 --split train",
shell=True,
capture_output=True,
)
print(result.stdout.decode())
print(result.stderr.decode())
assert result.returncode == 0
assert "created Transform" in result.stdout.decode()
assert "JjRF4mACd9m00000" in result.stdout.decode()
assert "created Run" in result.stdout.decode()

# you can re-save the script
result = subprocess.run(
f"lamin save {filepath}",
shell=True,
capture_output=True,
env=env,
)
print(result.stdout.decode())
print(result.stderr.decode())
assert result.returncode == 0
assert "source code is already saved" in result.stdout.decode()
assert (
"run-track-with-params.py' on uid 'JjRF4mACd9m00000'" in result.stdout.decode()
)