"""Example of how to perform a parameter sweep for categorical variables"""

import bencher as bch


# All the examples will be using the data structures and benchmark function defined in this file
from bencher.example.benchmark_data import ExampleBenchCfg


def example_float_cat(run_cfg: bch.BenchRunCfg | None = None) -> bch.Bench:
    """Example of how to perform a parameter sweep for categorical variables

    Args:
        run_cfg (BenchRunCfg): configuration of how to perform the param sweep

    Returns:
        Bench: results of the parameter sweep
    """
    bench = bch.Bench(
        "Bencher_Example_Float_Cat",
        ExampleBenchCfg(),
        run_cfg=run_cfg,
    )

    bench.plot_sweep(
        input_vars=[
            "theta",
            "offset",
            "postprocess_fn",
        ],
        result_vars=["out_sin"],
        const_vars=dict(noisy=True),
        title="Float 2D Cat 1D Example",
        description="""Following from the previous example lets add another input parameter to see how that affects the output.  We pass the boolean  'noisy' and keep the other parameters the same""",
        post_description="Now the plot has two lines, one for each of the boolean values where noisy=true and noisy=false.",
    )

    bench.plot_sweep(
        input_vars=["theta"],
        result_vars=["out_sin"],
        const_vars=dict(noisy=True),
        title="Float 1D Cat 1D  Example",
        description="""Following from the previous example lets add another input parameter to see how that affects the output.  We pass the boolean  'noisy' and keep the other parameters the same""",
        post_description="Now the plot has two lines, one for each of the boolean values where noisy=true and noisy=false.",
        plot_callbacks=False,
    )

    # report.append(bench.get_result().to_curve())

    # # this does not work yet because it tries to find min and max of categorical values
    # bench.plot_sweep(
    #     input_vars=["theta", "postprocess_fn"],
    #     result_vars=["out_sin"],
    #     const_vars=dict(noisy=True),
    #     title="Float 1D Cat 1D  Example",
    #     description="""Following from the previous example lets add another input parameter to see how that affects the output.  We pass the boolean  'noisy' and keep the other parameters the same""",
    #     post_description="Now the plot has two lines, one for each of the boolean values where noisy=true and noisy=false.",
    #     run_cfg=run_cfg,
    # )

    return bench


def run_example_float_cat(run_cfg: bch.BenchRunCfg | None = None) -> bch.Bench:
    if run_cfg is None:
        run_cfg = bch.BenchRunCfg()
    run_cfg.repeats = 2
    run_cfg.over_time = True
    run_cfg.clear_cache = True
    run_cfg.clear_history = True
    run_cfg.level = 3

    example_float_cat(run_cfg)

    run_cfg.clear_cache = False
    run_cfg.clear_history = False

    return example_float_cat(run_cfg)


if __name__ == "__main__":
    bch.run(run_example_float_cat)
