Beispiel #1
0
def test_n_max_pipeline():
    pipe = pipelines.n_max_pipeline()
    props = goodvehicle.goodVehicle()
    wot = engine.preproc_wot(props, props["wot"])
    sol = pipe.compute(
        {
            **dtz.keyfilter(
                lambda k: k in ("n_rated", "p_rated", "n2v_ratios"), props),
            "wot":
            wot,
            "cycle": {
                "V": pd.Series([120])
            },
            "v_max":
            190.3,
            "g_vmax":
            6,
        })
    assert (list(sol) == """
        p_rated n_rated n2v_ratios wot cycle v_max g_vmax n2v_g_vmax
        n_95_low n_95_high n_max_cycle n_max_vehicle n_max
        """.split())

    steps = [getattr(n, "name", n) for n in sol.plan.steps]
    steps_executed = [getattr(n, "name", n) for n in sol.executed]
    print(steps, steps_executed)
    exp_steps = "calc_n2v_g_vmax calc_n_95 calc_n_max_cycle calc_n_max_vehicle calc_n_max".split(
    )
    assert steps == steps_executed == exp_steps
Beispiel #2
0
    def test_badCycle(self):
        mdl = goodVehicle()
        mdl["cycle"] = 1

        with self.assertRaisesRegex(
                PandasError, "DataFrame constructor not properly called"):
            experiment = Experiment(mdl)
            mdl = experiment.run()
Beispiel #3
0
    def test_two_ramps_smoke_test(self):
        mdl = goodVehicle()
        mdl = datamodel.upd_resistance_coeffs_regression_curves(mdl)

        V = np.hstack((np.r_[0:100:2], np.r_[98:0:-2]))
        mdl["cycle"] = {"v_target": V}

        experiment = Experiment(mdl)
        mdl = experiment.run()
Beispiel #4
0
def test_cycler_pipeline():  # wltc_class):
    wltc_class = 0
    aug = wio.make_autograph()
    ops = aug.wrap_funcs([
        *pipelines.cycler_pipeline().ops,
        # fake Vs
        operation(
            lambda v: v.rename("V_dsc"),
            "FAKE.V_dsc",
            "wltc_class_data/V_cycle",
            "V_dsc",
        ),
    ])
    pipe = compose(..., *ops)
    props = goodvehicle.goodVehicle()
    inp = {
        **props,
        "wltc_data": datamodel.get_wltc_data(),
        "wltc_class": wltc_class,
        "v_max": 190.3,
        "g_vmax": 6,
        # "n_min_drives":  nmindrive.mdl_2_n_min_drives.compute(props)
    }
    datamodel.validate_model(inp, additional_properties=True)

    with config.evictions_skipped(True):
        sol = pipe.compute(inp, callbacks=(pipelines.check_dupe_cols))
    cycle = sol["cycle"]

    assert len(cycle) == 1612
    # assert len(cycle.columns) == 105

    renames = {
        "OK_max_n": "ok_max_n",
        "OK_g0": "ok_gear0",
        "OK_p": "ok_p",
        "OK_n": "ok_n",
        "OK_gear": "ok_gear",
        "G_min": "g_min",
        "G_max0": "g_max0",
    }
    exp = [
        ("t", ""),
        ("V_cycle", ""),
        ("V_dsc", ""),
        ("V", ""),
        ("A", ""),
        ("va_phase", ""),
        ("phase_1", ""),
        ("phase_2", ""),
        ("phase_3", ""),
        ("accel_raw", ""),
        ("run", ""),
        ("stop", ""),
        ("decel", ""),
        ("initaccel", ""),
        ("stopdecel", ""),
        ("up", ""),
        ("P_resist", ""),
        ("P_inert", ""),
        ("P_req", ""),
        ("n", "g1"),
        ("n", "g2"),
        ("n", "g3"),
        ("n", "g4"),
        ("n", "g5"),
        ("n", "g6"),
        ("n_norm", "g1"),
        ("n_norm", "g2"),
        ("n_norm", "g3"),
        ("n_norm", "g4"),
        ("n_norm", "g5"),
        ("n_norm", "g6"),
        ("p", "g1"),
        ("p", "g2"),
        ("p", "g3"),
        ("p", "g4"),
        ("p", "g5"),
        ("p", "g6"),
        ("p_avail", "g1"),
        ("p_avail", "g2"),
        ("p_avail", "g3"),
        ("p_avail", "g4"),
        ("p_avail", "g5"),
        ("p_avail", "g6"),
        ("p_avail_stable", "g1"),
        ("p_avail_stable", "g2"),
        ("p_avail_stable", "g3"),
        ("p_avail_stable", "g4"),
        ("p_avail_stable", "g5"),
        ("p_avail_stable", "g6"),
        ("p_norm", "g1"),
        ("p_norm", "g2"),
        ("p_norm", "g3"),
        ("p_norm", "g4"),
        ("p_norm", "g5"),
        ("p_norm", "g6"),
        ("P_remain", "g1"),
        ("P_remain", "g2"),
        ("P_remain", "g3"),
        ("P_remain", "g4"),
        ("P_remain", "g5"),
        ("P_remain", "g6"),
        ("ok_p", "g3"),
        ("ok_p", "g4"),
        ("ok_p", "g5"),
        ("ok_p", "g6"),
        ("ok_max_n", "g1"),
        ("ok_max_n", "g2"),
        ("ok_max_n", "g3"),
        ("ok_max_n", "g4"),
        ("ok_max_n", "g5"),
        ("ok_max_n", "g6"),
        ("ok_gear0", "g0"),
        ("ok_min_n_g1", "g1"),
        ("ok_min_n_g1_initaccel", "g1"),
        ("ok_min_n_g2", "g2"),
        ("ok_min_n_g2_stopdecel", "g2"),
        ("ok_min_n_g3plus_dns", "g3"),
        ("ok_min_n_g3plus_dns", "g4"),
        ("ok_min_n_g3plus_dns", "g5"),
        ("ok_min_n_g3plus_dns", "g6"),
        ("ok_min_n_g3plus_ups", "g3"),
        ("ok_min_n_g3plus_ups", "g4"),
        ("ok_min_n_g3plus_ups", "g5"),
        ("ok_min_n_g3plus_ups", "g6"),
        ("ok_n", "g1"),
        ("ok_n", "g2"),
        ("ok_n", "g3"),
        ("ok_n", "g4"),
        ("ok_n", "g5"),
        ("ok_n", "g6"),
        ("incrementing_gflags", "g0"),
        ("incrementing_gflags", "g1"),
        ("incrementing_gflags", "g2"),
        ("incrementing_gflags", "g3"),
        ("incrementing_gflags", "g4"),
        ("incrementing_gflags", "g5"),
        ("incrementing_gflags", "g6"),
        ("ok_gear", "g0"),
        ("ok_gear", "g1"),
        ("ok_gear", "g2"),
        ("ok_gear", "g3"),
        ("ok_gear", "g4"),
        ("ok_gear", "g5"),
        ("ok_gear", "g6"),
        ("g_min", ""),
        ("g_max0", ""),
    ]

    print(cycle.columns)
    # assert set(cycle.columns) == set(exp)
    assert set(cycle.rename(columns=renames, level=0)) == set(exp)
    assert not ({
        "class_phase_boundaries",
        "n2v_g_vmax",
        "n95_low",
        "n95_high",
        "n_max_cycle",
        "n_max_vehicle",
        "n_max",
    } - sol.keys())

    steps = [getattr(n, "name", n) for n in sol.plan.steps]
    steps_executed = [getattr(n, "name", n) for n in sol.executed]
    print("\n".join(textwrap.wrap(" ".join(steps), 90)))
    # print("\n".join(textwrap.wrap(" ".join(steps_executed), 90)))
    exp_steps = """
    get_wltc_class_data get_class_phase_boundaries PhaseMarker interpolate_wot_on_v_grid
    attach_p_avail_in_gwots calc_n2v_g_vmax calc_n95 calc_n_max_vehicle
    make_gwots_multi_indexer FAKE.V_dsc init_cycle_velocity calc_acceleration
    attach_class_phase_markers calc_phase_accel_raw calc_phase_run_stop calc_phase_decel
    calc_phase_initaccel calc_phase_stopdecel calc_phase_up calc_p_resist calc_inertial_power
    calc_required_power calc_n_max_cycle calc_n_max validate_n_max join_gwots_with_cycle
    calc_P_remain calc_OK_p calc_OK_max_n calc_OK_g0 calc_OK_min_n derrive_ok_n_flags
    calc_ok_gears make_cycle_multi_indexer make_incrementing_gflags make_G_min make_G_max0
    """.split()
    assert steps == steps_executed == exp_steps
Beispiel #5
0
def test_cycler_pipeline():  # wltc_class):
    wltc_class = 0
    aug = wio.make_autograph()
    ops = aug.wrap_funcs([
        *pipelines.cycler_pipeline().ops,
        # fake Vs
        operation(None, "FAKE.V_dsc", "wltc_class_data/V_cycle", "V_dsc"),
    ])
    pipe = compose(..., *ops)
    inp = {
        **goodvehicle.goodVehicle(),
        "wltc_data": datamodel.get_wltc_data(),
        "wltc_class": wltc_class,
        "v_max": 190.3,
        "g_vmax": 6,
    }
    datamodel.validate_model(inp)

    with config.evictions_skipped(True):
        sol = pipe.compute(inp)

    exp = {
        "V_cycle",
        "V_cycle",
        "V",
        "A",
        "v_phase1",
        "v_phase2",
        "v_phase3",
        "va_phases",
        "P_resist",
        "P_inert",
        "P_req",
        "t",
        ("n", "g1"),
        ("n", "g2"),
        ("n", "g3"),
        ("n", "g4"),
        ("n", "g5"),
        ("n", "g6"),
        ("n_norm", "g1"),
        ("n_norm", "g2"),
        ("n_norm", "g3"),
        ("n_norm", "g4"),
        ("n_norm", "g5"),
        ("n_norm", "g6"),
        ("p", "g1"),
        ("p", "g2"),
        ("p", "g3"),
        ("p", "g4"),
        ("p", "g5"),
        ("p", "g6"),
        ("p_avail", "g1"),
        ("p_avail", "g2"),
        ("p_avail", "g3"),
        ("p_avail", "g4"),
        ("p_avail", "g5"),
        ("p_avail", "g6"),
        ("p_avail_stable", "g1"),
        ("p_avail_stable", "g2"),
        ("p_avail_stable", "g3"),
        ("p_avail_stable", "g4"),
        ("p_avail_stable", "g5"),
        ("p_avail_stable", "g6"),
        ("p_norm", "g1"),
        ("p_norm", "g2"),
        ("p_norm", "g3"),
        ("p_norm", "g4"),
        ("p_norm", "g5"),
        ("p_norm", "g6"),
        ("p_resist", ""),
    }
    assert set(sol["cycle"].columns) == exp
    assert not ({
        "class_phase_boundaries",
        "n2v_g_vmax",
        "n_95_low",
        "n_95_high",
        "n_max_cycle",
        "n_max_vehicle",
        "n_max",
    } - sol.keys())

    steps = [getattr(n, "name", n) for n in sol.plan.steps]
    steps_executed = [getattr(n, "name", n) for n in sol.executed]
    print(steps, steps_executed)
    exp_steps = """
        get_wltc_class_data get_forced_cycle get_class_phase_boundaries
        interpolate_wot_on_v_grid attach_p_avail_in_gwots attach_p_resist_in_gwots
        calc_n2v_g_vmax calc_n_95 calc_n_max_vehicle make_gwots_multi_indexer FAKE.V_dsc
        init_cycle_velocity calc_acceleration attach_class_v_phase_markers
        calc_class_va_phase_markers calc_p_resist calc_inertial_power calc_required_power
        calc_n_max_cycle calc_n_max attach_wots
        """.split()
    assert steps == steps_executed == exp_steps