33
44from pydantic import BaseModel , Field , field_validator
55
6- from alphatrion .artifact .artifact import Artifact
76from alphatrion .metadata .sql_models import COMPLETED_STATUS , ExperimentStatus
8- from alphatrion .runtime .runtime import Runtime
7+ from alphatrion .runtime .runtime import global_runtime
98
109
1110class CheckpointConfig (BaseModel ):
@@ -75,9 +74,7 @@ class Experiment:
7574
7675 def __init__ (
7776 self ,
78- runtime : Runtime ,
7977 config : ExperimentConfig | None = None ,
80- artifact_insecure : bool = False ,
8178 ):
8279 """
8380 :param runtime: the Runtime instance
@@ -87,9 +84,8 @@ def __init__(
8784 artifact registry. Default is False.
8885 """
8986
90- self ._runtime = runtime
91- self ._artifact = Artifact (runtime , insecure = artifact_insecure )
9287 self ._config = config or ExperimentConfig ()
88+ self ._runtime = global_runtime ()
9389
9490 self ._steps = 0
9591 self ._best_metric_value = None
@@ -100,13 +96,11 @@ def __init__(
10096 @classmethod
10197 def run (
10298 cls ,
103- project_id : str ,
10499 config : ExperimentConfig | None = None ,
105100 name : str | None = None ,
106101 description : str | None = None ,
107102 meta : dict | None = None ,
108103 labels : dict | None = None ,
109- artifact_insecure : bool = False ,
110104 ):
111105 """
112106 :param project_id: the project ID to run the experiment under
@@ -121,12 +115,7 @@ def run(
121115 :return: a context manager that yields an Experiment instance
122116 """
123117
124- runtime = Runtime (project_id = project_id )
125- exp = Experiment (
126- runtime = runtime ,
127- config = config ,
128- artifact_insecure = artifact_insecure ,
129- )
118+ exp = Experiment (config = config )
130119 return RunContext (
131120 exp , name = name , description = description , meta = meta , labels = labels
132121 )
@@ -234,32 +223,6 @@ def running_time(self) -> int:
234223 return 0
235224 return int ((datetime .now (UTC ) - self ._start_at ).total_seconds ())
236225
237- def log_artifact (
238- self ,
239- exp_id : int ,
240- paths : str | list [str ],
241- version : str = "latest" ,
242- ):
243- """
244- Log artifacts (files) to the artifact registry.
245- :param exp_id: the experiment ID
246- :param paths: list of file paths to log.
247- Support one or multiple files or a folder.
248- If a folder is provided, all files in the folder will be logged.
249- Don't support nested folders currently.
250- Only files in the first level of the folder will be logged.
251- :param version: the version (tag) to log the files under
252- """
253-
254- if not paths :
255- raise ValueError ("no files specified to log" )
256-
257- exp = self ._runtime ._metadb .get_exp (exp_id = exp_id )
258- if exp is None :
259- raise ValueError (f"Experiment with id { exp_id } does not exist." )
260-
261- self ._artifact .push (experiment_name = exp .name , paths = paths , version = version )
262-
263226
264227class RunContext :
265228 """A context manager for running experiments."""
0 commit comments