Exemple #1
0
def test_recompute_till():
    def by2(n):
        return 2 * n

    pipe = compose(
        ...,
        operation(by2, "f0", "a0", "a1"),
        operation(by2, "f1", "a1", "a2"),
        operation(by2, "f2", "a2", "a3"),
        operation(by2, "f3", "a3", "a4"),
    )
    sol = pipe(a0=1)
    assert exe_ops(sol) == ["f0", "f1", "f2", "f3"]
    assert sol == {"a0": 1, "a1": 2, "a2": 4, "a3": 8, "a4": 16}

    inp = dict(sol)
    inp["a1"] = 3

    sol = pipe.compute(inp, outputs="a3", recompute_from="a1")
    assert exe_ops(sol) == ["f1", "f2"]
    assert sol == {"a3": 12}

    with evictions_skipped(True):
        sol = pipe.compute(inp, outputs="a3", recompute_from="a1")
        assert exe_ops(sol) == ["f1", "f2"]
        assert sol == {"a0": 1, "a1": 3, "a2": 6, "a3": 12, "a4": 16}
Exemple #2
0
def test_skip_eviction_flag():
    graph = compose(
        "graph",
        operation(name="add1", needs=["a", "b"], provides=["ab"])(add),
        operation(name="add2", needs=["a", "ab"], provides=["aab"])(add),
    )
    with evictions_skipped(True):
        exp = {"a": 1, "b": 3, "ab": 4, "aab": 5}
        assert graph.compute({"a": 1, "b": 3}, "aab") == exp
Exemple #3
0
def test_cycle_tip():
    pipe = compose(..., operation(str, "cyclic1", "a", "a"))
    with pytest.raises(nx.NetworkXUnfeasible, match="TIP:"):
        pipe.compute()
    pipe = compose(..., operation(str, "cyclic1", "a", "b"),
                   operation(str, "cyclic2", "b", "a"))
    with evictions_skipped(True), pytest.raises(nx.NetworkXUnfeasible,
                                                match="TIP:"):
        pipe.compute()
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
Exemple #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