22# Licensed under the MIT License.
33
44from contextlib import contextmanager
5- from typing import Text , Optional
5+ from typing import Any , Dict , Text , Optional
66from .expm import ExpManager
77from .exp import Experiment
88from .recorder import Recorder
@@ -380,11 +380,11 @@ def get_recorder(
380380 .. code-block:: Python
381381
382382 # Case 1
383- with R.start('test'):
383+ with R.start(experiment_name= 'test'):
384384 recorder = R.get_recorder()
385385
386386 # Case 2
387- with R.start('test'):
387+ with R.start(experiment_name= 'test'):
388388 recorder = R.get_recorder(recorder_id='2e7a4efd66574fa49039e00ffaefa99d')
389389
390390 # Case 3
@@ -433,12 +433,18 @@ def delete_recorder(self, recorder_id=None, recorder_name=None):
433433 """
434434 self .get_exp ().delete_recorder (recorder_id , recorder_name )
435435
436- def save_objects (self , local_path = None , artifact_path = None , ** kwargs ):
436+ def save_objects (self , local_path = None , artifact_path = None , ** kwargs : Dict [ Text , Any ] ):
437437 """
438438 Method for saving objects as artifacts in the experiment to the uri. It supports either saving
439439 from a local file/directory, or directly saving objects. User can use valid python's keywords arguments
440440 to specify the object to be saved as well as its name (name: value).
441441
442+ In summary, this API is designs for saving **objects** to **the experiments management backend path**,
443+ 1. Qlib provide two methods to specify **objects**
444+ - Passing in the object directly by passing with `**kwargs` (e.g. R.save_objects(trained_model=model))
445+ - Passing in the local path to the object, i.e. `local_path` parameter.
446+ 2. `artifact_path` represents the **the experiments management backend path**
447+
442448 - If `active recorder` exists: it will save the objects through the active recorder.
443449 - If `active recorder` not exists: the system will create a default experiment, and a new recorder and save objects under it.
444450
@@ -451,21 +457,35 @@ def save_objects(self, local_path=None, artifact_path=None, **kwargs):
451457 .. code-block:: Python
452458
453459 # Case 1
454- with R.start('test'):
460+ with R.start(experiment_name= 'test'):
455461 pred = model.predict(dataset)
456462 R.save_objects(**{"pred.pkl": pred}, artifact_path='prediction')
463+ rid = R.get_recorder().id
464+ ...
465+ R.get_recorder(recorder_id=rid).load_object("prediction/pred.pkl") # after saving objects, you can load the previous object with this api
457466
458467 # Case 2
459- with R.start('test'):
460- R.save_objects(local_path='results/pred.pkl')
468+ with R.start(experiment_name='test'):
469+ R.save_objects(local_path='results/pred.pkl', artifact_path="prediction")
470+ rid = R.get_recorder().id
471+ ...
472+ R.get_recorder(recorder_id=rid).load_object("prediction/pred.pkl") # after saving objects, you can load the previous object with this api
473+
461474
462475 Parameters
463476 ----------
464477 local_path : str
465478 if provided, them save the file or directory to the artifact URI.
466479 artifact_path : str
467480 the relative path for the artifact to be stored in the URI.
468- """
481+ **kwargs: Dict[Text, Any]
482+ the object to be saved.
483+ For example, `{"pred.pkl": pred}`
484+ """
485+ if local_path is not None and len (kwargs ) > 0 :
486+ raise ValueError (
487+ "You can choose only one of `local_path`(save the files in a path) or `kwargs`(pass in the objects directly)"
488+ )
469489 self .get_exp ().get_recorder ().save_objects (local_path , artifact_path , ** kwargs )
470490
471491 def load_object (self , name : Text ):
0 commit comments