예제 #1
0
def detail(run_id: str) -> None:
    click.echo(click.style("Run [{}] detailed information.\n".format(run_id), fg='magenta'))

    glob_query = "{}/**/{}/run.json".format(EXPERIMENTS_DIRECTORY, run_id)
    results = glob.glob(glob_query)

    if len(results) == 0:
        click.echo(click.style("No data for experiment found =(\n"
                               "Check `qiskitflow runs`", fg="yellow"))

    for path in results:
        run = Experiment.load(path)

        ps = "\n".join(str(p) for p in run.parameters)
        ms = "\n".join(str(m) for m in run.metrics)
        cts = "\n".join(str(c) for c in run.counts)

        header = ["", "Values"]
        rows = [
            ["Run ID", run.run_id],
            ["Experiment", run.name],
            ["Date", datetime.fromtimestamp(run.timestamp)],
            ["Parameters", ps],
            ["Metrics", ms],
            ["Counts", cts]
        ]

        click.echo(click.style(tabulate(rows, header, tablefmt='grid'), fg='white'))
예제 #2
0
def _get_runs(search: str,
              experiment_name: str,
              order_by: str,
              order_type: str = "asc"):

    glob_query = "{}/**/**/run.json".format(EXPERIMENTS_DIRECTORY)
    if experiment_name:
        glob_query = "{}/{}/**/run.json".format(EXPERIMENTS_DIRECTORY,
                                                experiment_name)

    runs_paths = glob.glob(glob_query)

    # gather all runs and sort them accordingly
    runs = []
    for path in runs_paths:
        experiment = Experiment.load(path)
        if experiment_name and experiment_name != experiment.name:
            continue
        if search in experiment.run_id:
            ordering = experiment.get_metric(
                order_by) if order_by else os.path.getctime(path)
            runs.append({"order": int(ordering), "run": Experiment.load(path)})
    runs.sort(key=lambda x: x["order"], reverse=order_type == "desc")

    # collect rows to display
    rows = []
    for entry in runs:
        run = entry["run"]
        ps = [str(p) for p in run.parameters]
        ms = [str(m) for m in run.metrics]

        rows.append([
            datetime.fromtimestamp(run.timestamp),
            "{}\n({})".format(run.name,
                              run.run_id), "\n".join(ms), "\n".join(ps)
        ])

    return rows
예제 #3
0
파일: info.py 프로젝트: aviv-or/QiskitFlow
def _get_runs(name: str, metrics: str, parameters: str):
    """ Get run list.

    Args:
        name (str): name of experiment
        metrics (str): csv list of metrics to display
        parameters (str): csv list of parameters to display
        sort (str): sort by metric

    Returns:
        rows (list): list of rows for rendered table
    """

    runs = []
    for idx, path in enumerate(
            glob.glob("{}/{}/**/run.json".format(EXPERIMENTS_DIRECTORY,
                                                 name))):
        _, _, run_id, _ = path.split("/")
        experiment = Experiment.load(path)

        if not metrics and not parameters:
            ms = [str(m) for m in experiment.metrics]
            ps = [str(p) for p in experiment.parameters]

            runs.append([run_id, "\n".join(ps), "\n".join(ms)])
        else:
            run = [run_id]

            for parameter in parameters.split(","):
                params_dict = {p.name: p.value for p in experiment.parameters}
                run.append(params_dict.get(parameter, ""))

            for metric in metrics.split(","):
                metrics_dict = {m.name: m.value for m in experiment.metrics}
                run.append(metrics_dict.get(metric, ""))

            runs.append(run)

    return runs