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 db merge #676

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
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
93 changes: 93 additions & 0 deletions src/orion/core/cli/db/merge.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Module running the set command
==============================

Update data of experiments and trials in the storage

"""
import argparse
import logging

import orion.core.io.experiment_builder as experiment_builder

logger = logging.getLogger(__name__)


DESCRIPTION = """
"""


CONFIRM_MESSAGE = """
"""


def add_subparser(parser):
"""Return the parser that needs to be used for this command"""
set_parser = parser.add_parser(
"merge",
description=DESCRIPTION,
help="",
formatter_class=argparse.RawTextHelpFormatter,
)

set_parser.set_defaults(func=main)

set_parser.add_argument("base", help="Name of the base experiment.")

set_parser.add_argument("experiment", help="Name of the experiment to merge.")

set_parser.add_argument("merged", help="Name of the merged experiment.")

set_parser.add_argument(
"-c",
"--config",
type=argparse.FileType("r"),
metavar="path-to-config",
help="user provided orion configuration file",
)
set_parser.add_argument(
"-f",
"--force",
action="store_true",
help="Force merge without asking to enter experiment name twice.",
)

return set_parser


def main(args):
"""Remove the experiment(s) or trial(s)."""
config = experiment_builder.get_cmd_config(args)
experiment_builder.setup_storage(config.get("storage"))

# Load base experiment
base = experiment_builder.load(
name=args["base"]
)

# Load experiment to merge
exp = experiment_builder.load(
name=args["experiment"]
)

# Make merged experiment
merged_config = base.configuration
del merged_config["_id"]
del merged_config["refers"]
merged_config["name"] = args["merged"]
merged = experiment_builder.create_experiment(mode="w", **merged_config)

base_trials = base.fetch_trials(with_evc_tree=True)
exp_trials = exp.fetch_trials(with_evc_tree=True)

for trial in base.fetch_trials(with_evc_tree=True):
trial.id_override = None
merged.register_trial(trial, status=trial.status)

for trial in exp.fetch_trials(with_evc_tree=True):
trial.id_override = None
merged.register_trial(trial, status=trial.status)

return 0