Skip to content

Commit

Permalink
Remove the family parameter from Run.__init__() (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
kgodlewski authored Oct 28, 2024
1 parent 8ffe412 commit 2eb6f39
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 63 deletions.
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ from neptune_scale import Run
run = Run(
experiment_name="ExperimentName",
family="RunFamilyName", # must be the same for related runs
run_id="SomeUniqueRunIdentifier",
)
```
Expand Down Expand Up @@ -130,7 +129,6 @@ __Parameters__

| Name | Type | Default | Description |
|------------------|------------------|---------|---------------------------------------------------------------------------|
| `family` | `str` | - | Identifies related runs. All runs of the same lineage must have the same `family` value. That is, forking is only possible within the same family. Max length: 128 bytes. |
| `run_id` | `str` | - | Identifier of the run. Must be unique within the project. Max length: 128 bytes. |
| `project` | `str`, optional | `None` | Name of a project in the form `workspace-name/project-name`. If `None`, the value of the `NEPTUNE_PROJECT` environment variable is used. |
| `api_token` | `str`, optional | `None` | Your Neptune API token or a service account's API token. If `None`, the value of the `NEPTUNE_API_TOKEN` environment variable is used. To keep your token secure, don't place it in source code. Instead, save it as an environment variable. |
Expand All @@ -156,7 +154,6 @@ from neptune_scale import Run
with Run(
project="team-alpha/project-x",
api_token="h0dHBzOi8aHR0cHM6...Y2MifQ==",
family="aquarium",
run_id="likable-barracuda",
) as run:
...
Expand All @@ -173,7 +170,6 @@ To restart an experiment, create a forked run:

```python
with Run(
family="aquarium",
run_id="adventurous-barracuda",
experiment_name="swim-further",
fork_run_id="likable-barracuda",
Expand All @@ -186,7 +182,6 @@ Continue a run:

```python
with Run(
family="aquarium",
run_id="likable-barracuda", # a Neptune run with this ID already exists
resume=True,
) as run:
Expand Down
12 changes: 2 additions & 10 deletions src/neptune_scale/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
)
from neptune_scale.parameters import (
MAX_EXPERIMENT_NAME_LENGTH,
MAX_FAMILY_LENGTH,
MAX_QUEUE_SIZE,
MAX_RUN_ID_LENGTH,
MINIMAL_WAIT_FOR_ACK_SLEEP_TIME,
Expand All @@ -84,7 +83,6 @@ class Run(WithResources, AbstractContextManager):
def __init__(
self,
*,
family: str,
run_id: str,
project: Optional[str] = None,
api_token: Optional[str] = None,
Expand All @@ -106,8 +104,6 @@ def __init__(
Initializes a run that logs the model-building metadata to Neptune.
Args:
family: Identifies related runs. For example, the same value must apply to all runs within a run hierarchy.
Max length: 128 bytes.
run_id: Unique identifier of a run. Must be unique within the project. Max length: 128 bytes.
project: Name of the project where the metadata is logged, in the form `workspace-name/project-name`.
If not provided, the value of the `NEPTUNE_PROJECT` environment variable is used.
Expand All @@ -131,7 +127,6 @@ def __init__(
on_warning_callback: Callback function triggered when a warning occurs.
"""

verify_type("family", family, str)
verify_type("run_id", run_id, str)
verify_type("resume", resume, bool)
verify_type("project", project, (str, type(None)))
Expand Down Expand Up @@ -182,7 +177,6 @@ def __init__(
assert api_token is not None # mypy
input_api_token: str = api_token

verify_non_empty("family", family)
verify_non_empty("run_id", run_id)
if experiment_name is not None:
verify_non_empty("experiment_name", experiment_name)
Expand All @@ -193,15 +187,13 @@ def __init__(

verify_project_qualified_name("project", project)

verify_max_length("family", family, MAX_FAMILY_LENGTH)
verify_max_length("run_id", run_id, MAX_RUN_ID_LENGTH)

# This flag is used to signal that we're closed or being closed (and most likely waiting for sync), and no
# new data should be logged.
self._is_closing = False

self._project: str = input_project
self._family: str = family
self._run_id: str = run_id

self._lock = threading.RLock()
Expand Down Expand Up @@ -229,7 +221,7 @@ def __init__(

self._sync_process = SyncProcess(
project=self._project,
family=self._family,
family=self._run_id,
operations_queue=self._operations_queue.queue,
errors_queue=self._errors_queue,
api_token=input_api_token,
Expand Down Expand Up @@ -396,7 +388,7 @@ def _create_run(
project=self._project,
run_id=self._run_id,
create=CreateRun(
family=self._family,
family=self._run_id,
fork_point=fork_point,
experiment_id=experiment_name,
creation_time=None if creation_time is None else datetime_to_proto(creation_time),
Expand Down
2 changes: 1 addition & 1 deletion src/neptune_scale/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ class NeptuneRunConflicting(NeptuneScaleError):
{h1}
----NeptuneRunConflicting------------------------------------------------------
{end}
Run with specified `run_id` already exists, but has different creation parameters (`family` or `fork_run_id`).
Run with specified `run_id` already exists, but has a different `fork_run_id` parameter.
{correct}Need help?{end}-> Contact [email protected]
Expand Down
1 change: 0 additions & 1 deletion src/neptune_scale/parameters.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Input validation
MAX_RUN_ID_LENGTH = 128
MAX_FAMILY_LENGTH = 128
MAX_EXPERIMENT_NAME_LENGTH = 730

# Operations queue
Expand Down
57 changes: 11 additions & 46 deletions tests/unit/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ def api_token():
# Set short timeouts on blocking operations for quicker test execution
@pytest.fixture(autouse=True, scope="session")
def short_timeouts():
import neptune_scale
import neptune_scale.core.components

patch = pytest.MonkeyPatch()
Expand All @@ -41,10 +40,9 @@ def test_context_manager(api_token):
# given
project = "workspace/project"
run_id = str(uuid.uuid4())
family = run_id

# when
with Run(project=project, api_token=api_token, family=family, run_id=run_id, mode="disabled"):
with Run(project=project, api_token=api_token, run_id=run_id, mode="disabled"):
...

# then
Expand All @@ -55,10 +53,9 @@ def test_close(api_token):
# given
project = "workspace/project"
run_id = str(uuid.uuid4())
family = run_id

# and
run = Run(project=project, api_token=api_token, family=family, run_id=run_id, mode="disabled")
run = Run(project=project, api_token=api_token, run_id=run_id, mode="disabled")

# when
run.close()
Expand All @@ -67,34 +64,16 @@ def test_close(api_token):
assert True


def test_family_too_long(api_token):
# given
project = "workspace/project"
run_id = str(uuid.uuid4())

# and
family = "a" * 1000

# when
with pytest.raises(ValueError):
with Run(project=project, api_token=api_token, family=family, run_id=run_id, mode="disabled"):
...

# and
assert True


def test_run_id_too_long(api_token):
# given
project = "workspace/project"
family = str(uuid.uuid4())

# and
run_id = "a" * 1000

# then
with pytest.raises(ValueError):
with Run(project=project, api_token=api_token, family=family, run_id=run_id, mode="disabled"):
with Run(project=project, api_token=api_token, run_id=run_id, mode="disabled"):
...

# and
Expand All @@ -104,14 +83,13 @@ def test_run_id_too_long(api_token):
def test_invalid_project_name(api_token):
# given
run_id = str(uuid.uuid4())
family = run_id

# and
project = "just-project"

# then
with pytest.raises(ValueError):
with Run(project=project, api_token=api_token, family=family, run_id=run_id, mode="disabled"):
with Run(project=project, api_token=api_token, run_id=run_id, mode="disabled"):
...

# and
Expand All @@ -122,10 +100,9 @@ def test_metadata(api_token):
# given
project = "workspace/project"
run_id = str(uuid.uuid4())
family = run_id

# then
with Run(project=project, api_token=api_token, family=family, run_id=run_id, mode="disabled") as run:
with Run(project=project, api_token=api_token, run_id=run_id, mode="disabled") as run:
run.log(
step=1,
timestamp=datetime.now(),
Expand Down Expand Up @@ -156,10 +133,9 @@ def test_tags(api_token):
# given
project = "workspace/project"
run_id = str(uuid.uuid4())
family = run_id

# then
with Run(project=project, api_token=api_token, family=family, run_id=run_id, mode="disabled") as run:
with Run(project=project, api_token=api_token, run_id=run_id, mode="disabled") as run:
run.add_tags(["tag1"])
run.add_tags(["tag2"], group_tags=True)
run.remove_tags(["tag3"])
Expand All @@ -173,10 +149,9 @@ def test_log_without_step(api_token):
# given
project = "workspace/project"
run_id = str(uuid.uuid4())
family = run_id

# then
with Run(project=project, api_token=api_token, family=family, run_id=run_id, mode="disabled") as run:
with Run(project=project, api_token=api_token, run_id=run_id, mode="disabled") as run:
run.log(
timestamp=datetime.now(),
configs={
Expand All @@ -192,10 +167,9 @@ def test_log_configs(api_token):
# given
project = "workspace/project"
run_id = str(uuid.uuid4())
family = run_id

# then
with Run(project=project, api_token=api_token, family=family, run_id=run_id, mode="disabled") as run:
with Run(project=project, api_token=api_token, run_id=run_id, mode="disabled") as run:
run.log_configs({"int": 1})

# and
Expand All @@ -206,10 +180,9 @@ def test_log_step_float(api_token):
# given
project = "workspace/project"
run_id = str(uuid.uuid4())
family = run_id

# then
with Run(project=project, api_token=api_token, family=family, run_id=run_id, mode="disabled") as run:
with Run(project=project, api_token=api_token, run_id=run_id, mode="disabled") as run:
run.log(
step=3.14,
timestamp=datetime.now(),
Expand All @@ -226,10 +199,9 @@ def test_log_no_timestamp(api_token):
# given
project = "workspace/project"
run_id = str(uuid.uuid4())
family = run_id

# then
with Run(project=project, api_token=api_token, family=family, run_id=run_id, mode="disabled") as run:
with Run(project=project, api_token=api_token, run_id=run_id, mode="disabled") as run:
run.log(
step=3.14,
configs={
Expand All @@ -245,10 +217,9 @@ def test_resume(api_token):
# given
project = "workspace/project"
run_id = str(uuid.uuid4())
family = run_id

# when
with Run(project=project, api_token=api_token, family=family, run_id=run_id, resume=True, mode="disabled") as run:
with Run(project=project, api_token=api_token, run_id=run_id, resume=True, mode="disabled") as run:
run.log(
step=3.14,
configs={
Expand All @@ -265,13 +236,11 @@ def test_creation_time(api_token):
# given
project = "workspace/project"
run_id = str(uuid.uuid4())
family = run_id

# when
with Run(
project=project,
api_token=api_token,
family=family,
run_id=run_id,
creation_time=datetime.now(),
mode="disabled",
Expand All @@ -286,13 +255,11 @@ def test_assign_experiment(api_token):
# given
project = "workspace/project"
run_id = str(uuid.uuid4())
family = run_id

# when
with Run(
project=project,
api_token=api_token,
family=family,
run_id=run_id,
experiment_name="experiment_id",
mode="disabled",
Expand All @@ -307,13 +274,11 @@ def test_forking(api_token):
# given
project = "workspace/project"
run_id = str(uuid.uuid4())
family = run_id

# when
with Run(
project=project,
api_token=api_token,
family=family,
run_id=run_id,
fork_run_id="parent-run-id",
fork_step=3.14,
Expand Down

0 comments on commit 2eb6f39

Please sign in to comment.