def main() -> None: """ . """ # Read in the settings file. with open(SETTINGS_PATH, "r") as settings_file: settings = json.load(settings_file) ox = Oxentiel(settings) # Set typecheck variables. dims.RESOLUTION = ox.resolution # Map cutoff values to the resulting total emissions. cutoffs = {} # Search for the optimal cutoff MOER value. for cutoff in range(500, 700, 10): env = SimpleEmissionsEnv(ox) agent = DeterministicAgent(cutoff=cutoff) emissions = [] ob = env.reset() for _ in range(200000): act = agent.act(ob) ob, _, done, info = env.step(act) co2 = info["co2"] emissions.append(co2) if done: break lbs = sum(emissions) print("|||||||||||||||||||||||| Cutoff:", cutoff, "emissions:", lbs) cutoffs[cutoff] = lbs
def main() -> None: """ Just loads the settings file and calls ``train()``. """ with open(SETTINGS_PATH, "r") as settings_file: settings = json.load(settings_file) ox = Oxentiel(settings) env = TDEmissionsEnv(ox) train(ox, env)
def test_ox_attributes_get_set(settings: Dict[str, Any]) -> None: """ Test that all keys are set as attributes. """ ox = Oxentiel(settings) def check_attributes(mapping: Dict[str, Any], ox: Oxentiel) -> None: """ Recursively add all keys from a nested dictionary. """ for key, value in mapping.items(): if isinstance(value, dict): check_attributes(value, getattr(ox, key)) assert hasattr(ox, key) check_attributes(settings, ox)
def test_ox_adds_all_keys_from_nested_dicts(settings: Dict[str, Any]) -> None: """ Test that all keys are added when the dictionary is nested. """ ox = Oxentiel(settings) def check_keys(mapping: Dict[str, Any], ox: Oxentiel) -> None: """ Recursively add all keys from a nested dictionary. """ for key, value in mapping.items(): if isinstance(value, dict): check_keys(value, getattr(ox, key)) assert key in ox.keys() check_keys(settings, ox)
def main() -> None: """ Just loads the settings file and calls ``train()``. """ with open(SETTINGS_PATH, "r") as settings_file: settings = json.load(settings_file) ox = Oxentiel(settings) # Get the specified agent/env. agent: Agent if ox.agent == "vpg": env = TDEmissionsEnv(ox) agent = VPGAgent(ox) elif ox.agent == "deterministic": env = SimpleEmissionsEnv(ox) agent = DeterministicAgent(ox.cutoff) else: raise ValueError( "Invalid agent choice. Should be 'vpg' or 'deterministic'.") # Run the simulation. simulate(ox, env, agent)
def configs(draw: Callable[[st.SearchStrategy], Any], tempdir: str) -> Oxentiel: """ Generates config objects. """ dataset = draw(datasets()) source_path = os.path.join(tempdir, "dataset.csv") dataset.to_csv(source_path, index=False) lr = draw(st.floats(min_value=0, max_value=1)) lr_cycle_steps = draw(st.integers(min_value=1)) pct_start = draw(st.floats(min_value=0, max_value=1)) hidden_dim = draw(st.integers(min_value=1, max_value=8)) iterations = draw(st.integers(min_value=1, max_value=10000)) batch_size = draw(st.integers(min_value=1, max_value=100)) base_resolution = draw(st.integers(min_value=1, max_value=20)) res_multiplier = draw(st.integers(min_value=1, max_value=10)) resolution = base_resolution * res_multiplier gamma = draw(st.floats(min_value=0, max_value=1)) lam = draw(st.floats(min_value=0, max_value=1)) assume(len(dataset) > base_resolution) assume(len(dataset) > resolution) ox_settings = { "source_path": source_path, "lr": lr, "lr_cycle_steps": lr_cycle_steps, "pct_start": pct_start, "hidden_dim": hidden_dim, "iterations": iterations, "batch_size": batch_size, "resolution": resolution, "base_resolution": base_resolution, "gamma": gamma, "lam": lam, "start": "", "end": "", } ox = Oxentiel(ox_settings) return ox
def test_ox_repr_prints_everything(settings: Dict[str, Any]) -> None: """ Test that every key appears in the string representation. """ ox_repr = repr(Oxentiel(settings)) print(ox_repr) for key in settings: assert repr(key) in ox_repr
def test_ox_settings_passed_by_value() -> None: """ Test that modifying ``Oxentiel.settings`` doesn't change the argument dict. """ settings = {"key": {"subkey": [1, 2]}} ox = Oxentiel(settings) settings["key"]["subkey"].append(3) assert 3 not in ox.key.subkey
def check_keys(mapping: Dict[str, Any], ox: Oxentiel) -> None: """ Recursively add all keys from a nested dictionary. """ for key, value in mapping.items(): if isinstance(value, dict): check_keys(value, getattr(ox, key)) assert key in ox.keys()