|
23 | 23 | "from pathlib import Path\n", |
24 | 24 | "\n", |
25 | 25 | "# Setup Environment\n", |
26 | | - "data_path = Path.cwd() / \"grid2op\" / \"data\"\n", |
27 | | - "p = Parameters()\n", |
28 | | - "p.MAX_SUB_CHANGED = 5\n", |
29 | | - "env = grid2op.make(data_path / \"rte_case5_example\", param=p, allow_detachment=True)\n", |
| 26 | + "env_standard = grid2op.make(\"rte_case5_example\", test=True, allow_detachment=False)\n", |
| 27 | + "env_with_detach = grid2op.make(\"rte_case5_example\", test=True, allow_detachment=True)\n", |
30 | 28 | "\n", |
31 | 29 | "# Setup Plotter Utility\n", |
32 | | - "plotter = PlotMatplot(env.observation_space, load_name=True, gen_name=True, dpi=150)\n", |
33 | | - "print(f\"Loads: {env.n_load}, Generators: {env.n_gen}, Storage: {env.n_storage}, Allow Detachment: {env._allow_detachment}\")" |
| 30 | + "plotter = PlotMatplot(env_standard.observation_space, load_name=True, gen_name=True, dpi=150)\n", |
| 31 | + "for env, env_name in zip([env_standard, env_with_detach], [\"env_standard\", \"env_with_detach\"]):\n", |
| 32 | + " print(f\"For {env_name}: Loads: {env.n_load}, Generators: {env.n_gen}, Storage: {env.n_storage}, Detachment is allowed: {env.detachment_is_allowed}\")" |
34 | 33 | ] |
35 | 34 | }, |
36 | 35 | { |
|
46 | 45 | "metadata": {}, |
47 | 46 | "outputs": [], |
48 | 47 | "source": [ |
49 | | - "load_lookup = {name:i for i,name in enumerate(env.name_load)}\n", |
50 | | - "gen_lookup = {name:i for i,name in enumerate(env.name_gen)}\n", |
51 | | - "act = env.action_space({\"set_bus\":[(env.load_pos_topo_vect[load_lookup[\"load_3_1\"]], -1),\n", |
52 | | - " (env.load_pos_topo_vect[load_lookup[\"load_4_2\"]], -1)]})\n", |
| 48 | + "act = env_standard.action_space({\"set_bus\":{\"loads_id\": [(\"load_3_1\", -1)]}})\n", |
53 | 49 | "print(act)\n", |
54 | | - "env.set_id(\"00\")\n", |
55 | | - "init_obs = env.reset()\n", |
56 | | - "obs, reward, done, info = env.step(act)\n", |
| 50 | + "init_obs = env_standard.reset(seed=0, options={\"time serie id\": \"00\"})\n", |
| 51 | + "obs, reward, done, info = env_standard.step(act)\n", |
57 | 52 | "plotter.plot_obs(obs, figure=plt.figure(figsize=(8,5)))\n", |
| 53 | + "plt.title(\"Without providing 'allow_detachment=True' grid2op fails if a load is disconnected\")\n", |
| 54 | + "plt.show()" |
| 55 | + ] |
| 56 | + }, |
| 57 | + { |
| 58 | + "cell_type": "code", |
| 59 | + "execution_count": null, |
| 60 | + "metadata": {}, |
| 61 | + "outputs": [], |
| 62 | + "source": [ |
| 63 | + "init_obs = env_with_detach.reset(seed=0, options={\"time serie id\": \"00\"})\n", |
| 64 | + "obs, reward, done, info = env_with_detach.step(act)\n", |
| 65 | + "plotter.plot_obs(obs, figure=plt.figure(figsize=(8,5)))\n", |
| 66 | + "plt.title(\"Providing 'allow_detachment=True' grid2op continues if a load is disconnected\")\n", |
| 67 | + "plt.tight_layout()\n", |
58 | 68 | "plt.show()" |
59 | 69 | ] |
60 | 70 | } |
61 | 71 | ], |
62 | 72 | "metadata": { |
63 | 73 | "kernelspec": { |
64 | | - "display_name": "venv_test", |
| 74 | + "display_name": "Python 3 (ipykernel)", |
65 | 75 | "language": "python", |
66 | 76 | "name": "python3" |
67 | 77 | }, |
|
75 | 85 | "name": "python", |
76 | 86 | "nbconvert_exporter": "python", |
77 | 87 | "pygments_lexer": "ipython3", |
78 | | - "version": "3.12.7" |
| 88 | + "version": "3.10.12" |
79 | 89 | } |
80 | 90 | }, |
81 | 91 | "nbformat": 4, |
82 | | - "nbformat_minor": 2 |
| 92 | + "nbformat_minor": 4 |
83 | 93 | } |
0 commit comments