@op(
config_schema=dict(
exp_out_location=Field(
dict,
default_value=dict(uri="experiments"),
description="Folder to store the experiments",
),
exp_folder_pattern=Field(
str,
default_value="EXP-$RUN_ID-id_$SHORT_ID",
description="Folder pattern of the experiment. "
"Can use $RUN_ID and $SHORT_ID to make the name unique",
),
description=Field(
str,
default_value="",
description="Description of the experiment. Replaces the training description",
),
)
)
def eval_copy_exp( # pylint: disable=too-many-locals
context: OpExecutionContext, exp_context: ExperimentContext
):
"""Copy experiment from one to another."""
op_config = json.loads(json.dumps(context.op_config))
description: str = op_config["description"]
exp_folder_pattern: str = op_config["exp_folder_pattern"]
exp_out_location: dict = op_config["exp_out_location"]
exp_folder, local_run_id, local_short_id = create_exp_settings(exp_folder_pattern)
new_exp_location = join_location_w_path(exp_out_location, exp_folder)
with open_location(exp_context.fs_config) as (
src_exp_fs,
src_exp_path,
), open_location(new_exp_location) as (target_exp_fs, target_exp_path):
in_mapper = src_exp_fs.get_mapper(src_exp_path)
out_mapper = target_exp_fs.get_mapper(target_exp_path)
logging.getLogger(__name__).info("Starting to copy experiment data")
eval_copy_exp_names = ExpEvalCopyNames()
for key in tqdm(in_mapper):
if key in eval_copy_exp_names:
out_mapper[key] = in_mapper[key]
change_ids_from_expinfo(
target_exp_fs,
join(target_exp_path, ExperimentFilenames.EXP_INFO),
local_run_id,
local_short_id,
description,
)
return ExperimentContext(
new_exp_location, run_id=local_run_id, short_id=local_short_id
)