This example notebook is a supplement to the ANDES tutorial. Make sure you have read the tutorial on using the CLI first.
A brief version can be found at https://github.com/cuihantao/andes/blob/master/README.md#run-simulations
!
magic in iPython¶This example shows how to use the ANDES CLI from Jupyter Notebook.
It is based on the iPython magic !
. To run a shell command from within iPython or notebook, place a !
before the command.
All the commands demonstrated in this notebook can be used in a terminal/shell by removing the preceeding !
sign.
For example, to list the directory , use !ls
. This is equivalent to running ls
from the terminal.
!ls
10. load-frequency-control.ipynb 6. using-cli-from-notebook.ipynb 1. simulate_and_plot.ipynb 7. parallel-simulation.ipynb 2. inspect_data.ipynb 8. change-setpoints.ipynb 3. eigenvalue.ipynb 9. batch-processing.ipynb 4. inspect_models.ipynb new_system.xlsx 5. profiling.ipynb verification
Likewise, to run andes
, use !andes
. Addition arguments can be passed as usual.
!andes
_ _ | Version 1.3.4.post6.dev0+g1cc8c20 /_\ _ _ __| |___ ___ | Python 3.8.6 on Linux, 03/17/2021 08:45:25 PM / _ \| ' \/ _` / -_|_-< | /_/ \_\_||_\__,_\___/__/ | This program comes with ABSOLUTELY NO WARRANTY. usage: andes [-h] [-v {1,10,20,30,40}] {run,plot,doc,misc,prepare,selftest} ... positional arguments: {run,plot,doc,misc,prepare,selftest} [run] run simulation routine; [plot] plot results; [doc] quick documentation; [misc] misc. functions; [prepare] prepare the numerical code; [selftest] run self test. optional arguments: -h, --help show this help message and exit -v {1,10,20,30,40}, --verbose {1,10,20,30,40} Verbosity level in 10-DEBUG, 20-INFO, 30-WARNING, or 40-ERROR.
Pass the path to the case file and other arguments to andes from the command line as follows.
!andes run ../andes/cases/kundur/kundur_full.xlsx -r tds
_ _ | Version 1.3.4.post6.dev0+g1cc8c20 /_\ _ _ __| |___ ___ | Python 3.8.6 on Linux, 03/17/2021 08:45:26 PM / _ \| ' \/ _` / -_|_-< | /_/ \_\_||_\__,_\___/__/ | This program comes with ABSOLUTELY NO WARRANTY. Working directory: "/home/hcui7/repos/andes/examples" Loaded config from file "/home/hcui7/.andes/andes.rc" Using generated Python code. Parsing input file "../andes/cases/kundur/kundur_full.xlsx"... Input file parsed in 0.4508 seconds. System internal structure set up in 0.0289 seconds. -> System connectivity check results: No islanded bus detected. No islanded areas detected. Each island has a slack bus correctly defined and enabled. -> Power flow calculation Sparse solver: KLU Solution method: NR method Sparse addition: Fast in-place (kvxopt) Power flow initialized. 0: |F(x)| = 14.9282832 1: |F(x)| = 3.608627841 2: |F(x)| = 0.1701107882 3: |F(x)| = 0.002038626956 4: |F(x)| = 3.745103977e-07 Converged in 5 iterations in 0.0072 seconds. Report saved to "kundur_full_out.txt" in 0.0031 seconds. -> Time Domain Simulation Summary: Sparse Solver: KLU Simulation time: 0-20.0 s. Fixed step size: h=33.33 ms. Shrink if not converged. Initialization for dynamics was successful in 0.0264 seconds. <Toggler 1>: Line.Line_8 status changed to 0 at t=2.0 sec. 100%|████████████████████████████████| 100/100 [00:02<00:00, 45.65%/s] Simulation completed in 2.1908 seconds. Outputs to "kundur_full_out.lst" and "kundur_full_out.npz". Outputs written in 0.0486 seconds. -> Single process finished in 2.9050 seconds.
Case file names can be separated from the path, which can be passed to -p
. The above command is equivanent to
!andes run kundur_full.xlsx -p "../andes/cases/kundur/" -r tds
_ _ | Version 1.3.4.post6.dev0+g1cc8c20 /_\ _ _ __| |___ ___ | Python 3.8.6 on Linux, 03/18/2021 04:19:38 PM / _ \| ' \/ _` / -_|_-< | /_/ \_\_||_\__,_\___/__/ | This program comes with ABSOLUTELY NO WARRANTY. Working directory: "/home/hcui7/repos/andes/examples" Loaded config from file "/home/hcui7/.andes/andes.rc" Using generated Python code. ../andes/cases/kundur/kundur_full.xlsx Unable to determine case format. Input format unknown for file "../andes/cases/kundur/kundur_full.xlsx". -> Single process exit with an error in 0.2402 seconds.
!pwd
/home/hcui7/repos/andes/examples
import os
os.path.isfile('../andes/cases/kundur/kundur_full.xlsx')
True
To run a simulation using PSS/E raw and dyr files, pass the dyr file to argument --addfile
.
For example:
!andes run ../andes/cases/kundur/kundur.raw --addfile ../andes/cases/kundur/kundur_full.dyr -r tds
_ _ | Version 1.3.4.post6.dev0+g1cc8c20 /_\ _ _ __| |___ ___ | Python 3.8.6 on Linux, 03/17/2021 08:45:32 PM / _ \| ' \/ _` / -_|_-< | /_/ \_\_||_\__,_\___/__/ | This program comes with ABSOLUTELY NO WARRANTY. Working directory: "/home/hcui7/repos/andes/examples" Loaded config from file "/home/hcui7/.andes/andes.rc" Using generated Python code. Parsing input file "../andes/cases/kundur/kundur.raw"... MODIFIED KUNDUR'S TWO-AREA TEST SYSTEM, DISTRIBUTED WITH ANDES SEE THE BOOK "POWER SYSTEM STABILITY AND CONTROL" FOR ORIGINAL DATA Input file parsed in 0.0059 seconds. Parsing additional file "../andes/cases/kundur/kundur_full.dyr"... Addfile parsed in 0.3804 seconds. System internal structure set up in 0.0279 seconds. -> System connectivity check results: No islanded bus detected. No islanded areas detected. Each island has a slack bus correctly defined and enabled. -> Power flow calculation Sparse solver: KLU Solution method: NR method Sparse addition: Fast in-place (kvxopt) Power flow initialized. 0: |F(x)| = 3.175850023 1: |F(x)| = 3.176155228e-08 Converged in 2 iterations in 0.0031 seconds. Report saved to "kundur_out.txt" in 0.0038 seconds. -> Time Domain Simulation Summary: Sparse Solver: KLU Simulation time: 0-20.0 s. Fixed step size: h=33.33 ms. Shrink if not converged. Initialization for dynamics was successful in 0.0262 seconds. <Toggler Toggler_1>: Line.Line_8 status changed to 0 at t=2.0 sec. 100%|████████████████████████████████| 100/100 [00:02<00:00, 42.64%/s] Simulation completed in 2.3451 seconds. Outputs to "kundur_out.lst" and "kundur_out.npz". Outputs written in 0.0288 seconds. -> Single process finished in 2.9936 seconds.
lst
file¶!cat kundur_full_out.lst
0, Time [s], Time [s] 1, delta GENROU 1, $\delta$ GENROU 1 2, delta GENROU 2, $\delta$ GENROU 2 3, delta GENROU 3, $\delta$ GENROU 3 4, delta GENROU 4, $\delta$ GENROU 4 5, omega GENROU 1, $\omega$ GENROU 1 6, omega GENROU 2, $\omega$ GENROU 2 7, omega GENROU 3, $\omega$ GENROU 3 8, omega GENROU 4, $\omega$ GENROU 4 9, e1q GENROU 1, $e'_q$ GENROU 1 10, e1q GENROU 2, $e'_q$ GENROU 2 11, e1q GENROU 3, $e'_q$ GENROU 3 12, e1q GENROU 4, $e'_q$ GENROU 4 13, e1d GENROU 1, $e'_d$ GENROU 1 14, e1d GENROU 2, $e'_d$ GENROU 2 15, e1d GENROU 3, $e'_d$ GENROU 3 16, e1d GENROU 4, $e'_d$ GENROU 4 17, e2d GENROU 1, $e''_d$ GENROU 1 18, e2d GENROU 2, $e''_d$ GENROU 2 19, e2d GENROU 3, $e''_d$ GENROU 3 20, e2d GENROU 4, $e''_d$ GENROU 4 21, e2q GENROU 1, $e''_q$ GENROU 1 22, e2q GENROU 2, $e''_q$ GENROU 2 23, e2q GENROU 3, $e''_q$ GENROU 3 24, e2q GENROU 4, $e''_q$ GENROU 4 25, LAG_y TGOV1 1, $y_{LAG}$ TGOV1 1 26, LAG_y TGOV1 2, $y_{LAG}$ TGOV1 2 27, LAG_y TGOV1 3, $y_{LAG}$ TGOV1 3 28, LAG_y TGOV1 4, $y_{LAG}$ TGOV1 4 29, LL_x TGOV1 1, $x'_{LL}$ TGOV1 1 30, LL_x TGOV1 2, $x'_{LL}$ TGOV1 2 31, LL_x TGOV1 3, $x'_{LL}$ TGOV1 3 32, LL_x TGOV1 4, $x'_{LL}$ TGOV1 4 33, vp EXDC2 1, $V_p$ EXDC2 1 34, vp EXDC2 2, $V_p$ EXDC2 2 35, vp EXDC2 3, $V_p$ EXDC2 3 36, vp EXDC2 4, $V_p$ EXDC2 4 37, LS_y EXDC2 1, $y_{LS}$ EXDC2 1 38, LS_y EXDC2 2, $y_{LS}$ EXDC2 2 39, LS_y EXDC2 3, $y_{LS}$ EXDC2 3 40, LS_y EXDC2 4, $y_{LS}$ EXDC2 4 41, LL_x EXDC2 1, $x'_{LL}$ EXDC2 1 42, LL_x EXDC2 2, $x'_{LL}$ EXDC2 2 43, LL_x EXDC2 3, $x'_{LL}$ EXDC2 3 44, LL_x EXDC2 4, $x'_{LL}$ EXDC2 4 45, LA_y EXDC2 1, $y_{LA}$ EXDC2 1 46, LA_y EXDC2 2, $y_{LA}$ EXDC2 2 47, LA_y EXDC2 3, $y_{LA}$ EXDC2 3 48, LA_y EXDC2 4, $y_{LA}$ EXDC2 4 49, W_x EXDC2 1, $x'_{W}$ EXDC2 1 50, W_x EXDC2 2, $x'_{W}$ EXDC2 2 51, W_x EXDC2 3, $x'_{W}$ EXDC2 3 52, W_x EXDC2 4, $x'_{W}$ EXDC2 4 53, a Bus 1, $\theta$ Bus 1 54, a Bus 2, $\theta$ Bus 2 55, a Bus 3, $\theta$ Bus 3 56, a Bus 4, $\theta$ Bus 4 57, a Bus 5, $\theta$ Bus 5 58, a Bus 6, $\theta$ Bus 6 59, a Bus 7, $\theta$ Bus 7 60, a Bus 8, $\theta$ Bus 8 61, a Bus 9, $\theta$ Bus 9 62, a Bus 10, $\theta$ Bus 10 63, v Bus 1, $V$ Bus 1 64, v Bus 2, $V$ Bus 2 65, v Bus 3, $V$ Bus 3 66, v Bus 4, $V$ Bus 4 67, v Bus 5, $V$ Bus 5 68, v Bus 6, $V$ Bus 6 69, v Bus 7, $V$ Bus 7 70, v Bus 8, $V$ Bus 8 71, v Bus 9, $V$ Bus 9 72, v Bus 10, $V$ Bus 10 73, p PV 2, $p$ PV 2 74, p PV 3, $p$ PV 3 75, p PV 4, $p$ PV 4 76, q PV 2, $q$ PV 2 77, q PV 3, $q$ PV 3 78, q PV 4, $q$ PV 4 79, p Slack 1, $p$ Slack 1 80, q Slack 1, $q$ Slack 1 81, Id GENROU 1, $I_d$ GENROU 1 82, Id GENROU 2, $I_d$ GENROU 2 83, Id GENROU 3, $I_d$ GENROU 3 84, Id GENROU 4, $I_d$ GENROU 4 85, Iq GENROU 1, $I_q$ GENROU 1 86, Iq GENROU 2, $I_q$ GENROU 2 87, Iq GENROU 3, $I_q$ GENROU 3 88, Iq GENROU 4, $I_q$ GENROU 4 89, vd GENROU 1, $V_d$ GENROU 1 90, vd GENROU 2, $V_d$ GENROU 2 91, vd GENROU 3, $V_d$ GENROU 3 92, vd GENROU 4, $V_d$ GENROU 4 93, vq GENROU 1, $V_q$ GENROU 1 94, vq GENROU 2, $V_q$ GENROU 2 95, vq GENROU 3, $V_q$ GENROU 3 96, vq GENROU 4, $V_q$ GENROU 4 97, tm GENROU 1, $\tau_m$ GENROU 1 98, tm GENROU 2, $\tau_m$ GENROU 2 99, tm GENROU 3, $\tau_m$ GENROU 3 100, tm GENROU 4, $\tau_m$ GENROU 4 101, te GENROU 1, $\tau_e$ GENROU 1 102, te GENROU 2, $\tau_e$ GENROU 2 103, te GENROU 3, $\tau_e$ GENROU 3 104, te GENROU 4, $\tau_e$ GENROU 4 105, vf GENROU 1, $v_f$ GENROU 1 106, vf GENROU 2, $v_f$ GENROU 2 107, vf GENROU 3, $v_f$ GENROU 3 108, vf GENROU 4, $v_f$ GENROU 4 109, XadIfd GENROU 1, $X_{ad}I_{fd}$ GENROU 1 110, XadIfd GENROU 2, $X_{ad}I_{fd}$ GENROU 2 111, XadIfd GENROU 3, $X_{ad}I_{fd}$ GENROU 3 112, XadIfd GENROU 4, $X_{ad}I_{fd}$ GENROU 4 113, psid GENROU 1, $\psi_d$ GENROU 1 114, psid GENROU 2, $\psi_d$ GENROU 2 115, psid GENROU 3, $\psi_d$ GENROU 3 116, psid GENROU 4, $\psi_d$ GENROU 4 117, psiq GENROU 1, $\psi_q$ GENROU 1 118, psiq GENROU 2, $\psi_q$ GENROU 2 119, psiq GENROU 3, $\psi_q$ GENROU 3 120, psiq GENROU 4, $\psi_q$ GENROU 4 121, psi2q GENROU 1, $\psi_{aq}$ GENROU 1 122, psi2q GENROU 2, $\psi_{aq}$ GENROU 2 123, psi2q GENROU 3, $\psi_{aq}$ GENROU 3 124, psi2q GENROU 4, $\psi_{aq}$ GENROU 4 125, psi2d GENROU 1, $\psi_{ad}$ GENROU 1 126, psi2d GENROU 2, $\psi_{ad}$ GENROU 2 127, psi2d GENROU 3, $\psi_{ad}$ GENROU 3 128, psi2d GENROU 4, $\psi_{ad}$ GENROU 4 129, psi2 GENROU 1, $\psi_a$ GENROU 1 130, psi2 GENROU 2, $\psi_a$ GENROU 2 131, psi2 GENROU 3, $\psi_a$ GENROU 3 132, psi2 GENROU 4, $\psi_a$ GENROU 4 133, Se GENROU 1, $S_e(|\psi_{a}|)$ GENROU 1 134, Se GENROU 2, $S_e(|\psi_{a}|)$ GENROU 2 135, Se GENROU 3, $S_e(|\psi_{a}|)$ GENROU 3 136, Se GENROU 4, $S_e(|\psi_{a}|)$ GENROU 4 137, XaqI1q GENROU 1, $X_{aq}I_{1q}$ GENROU 1 138, XaqI1q GENROU 2, $X_{aq}I_{1q}$ GENROU 2 139, XaqI1q GENROU 3, $X_{aq}I_{1q}$ GENROU 3 140, XaqI1q GENROU 4, $X_{aq}I_{1q}$ GENROU 4 141, paux TGOV1 1, $P_{aux}$ TGOV1 1 142, paux TGOV1 2, $P_{aux}$ TGOV1 2 143, paux TGOV1 3, $P_{aux}$ TGOV1 3 144, paux TGOV1 4, $P_{aux}$ TGOV1 4 145, pout TGOV1 1, $P_{out}$ TGOV1 1 146, pout TGOV1 2, $P_{out}$ TGOV1 2 147, pout TGOV1 3, $P_{out}$ TGOV1 3 148, pout TGOV1 4, $P_{out}$ TGOV1 4 149, wref TGOV1 1, $\omega_{ref}$ TGOV1 1 150, wref TGOV1 2, $\omega_{ref}$ TGOV1 2 151, wref TGOV1 3, $\omega_{ref}$ TGOV1 3 152, wref TGOV1 4, $\omega_{ref}$ TGOV1 4 153, pref TGOV1 1, $P_{ref}$ TGOV1 1 154, pref TGOV1 2, $P_{ref}$ TGOV1 2 155, pref TGOV1 3, $P_{ref}$ TGOV1 3 156, pref TGOV1 4, $P_{ref}$ TGOV1 4 157, wd TGOV1 1, $\omega_{dev}$ TGOV1 1 158, wd TGOV1 2, $\omega_{dev}$ TGOV1 2 159, wd TGOV1 3, $\omega_{dev}$ TGOV1 3 160, wd TGOV1 4, $\omega_{dev}$ TGOV1 4 161, pd TGOV1 1, $P_d$ TGOV1 1 162, pd TGOV1 2, $P_d$ TGOV1 2 163, pd TGOV1 3, $P_d$ TGOV1 3 164, pd TGOV1 4, $P_d$ TGOV1 4 165, LL_y TGOV1 1, $y_{LL}$ TGOV1 1 166, LL_y TGOV1 2, $y_{LL}$ TGOV1 2 167, LL_y TGOV1 3, $y_{LL}$ TGOV1 3 168, LL_y TGOV1 4, $y_{LL}$ TGOV1 4 169, vout EXDC2 1, $v_{out}$ EXDC2 1 170, vout EXDC2 2, $v_{out}$ EXDC2 2 171, vout EXDC2 3, $v_{out}$ EXDC2 3 172, vout EXDC2 4, $v_{out}$ EXDC2 4 173, vref EXDC2 1, $V_{ref}$ EXDC2 1 174, vref EXDC2 2, $V_{ref}$ EXDC2 2 175, vref EXDC2 3, $V_{ref}$ EXDC2 3 176, vref EXDC2 4, $V_{ref}$ EXDC2 4 177, Se EXDC2 1, $S_e(|V_{out}|)$ EXDC2 1 178, Se EXDC2 2, $S_e(|V_{out}|)$ EXDC2 2 179, Se EXDC2 3, $S_e(|V_{out}|)$ EXDC2 3 180, Se EXDC2 4, $S_e(|V_{out}|)$ EXDC2 4 181, vi EXDC2 1, $V_i$ EXDC2 1 182, vi EXDC2 2, $V_i$ EXDC2 2 183, vi EXDC2 3, $V_i$ EXDC2 3 184, vi EXDC2 4, $V_i$ EXDC2 4 185, LL_y EXDC2 1, $y_{LL}$ EXDC2 1 186, LL_y EXDC2 2, $y_{LL}$ EXDC2 2 187, LL_y EXDC2 3, $y_{LL}$ EXDC2 3 188, LL_y EXDC2 4, $y_{LL}$ EXDC2 4 189, W_y EXDC2 1, $y_{W}$ EXDC2 1 190, W_y EXDC2 2, $y_{W}$ EXDC2 2 191, W_y EXDC2 3, $y_{W}$ EXDC2 3 192, W_y EXDC2 4, $y_{W}$ EXDC2 4
Windows users may not have cat
by default in the search path. Do instead
with open('kundur_full_out.lst', 'r') as f:
print(f.read())
We found a limitation of using andes plot
from within Notebook/iPython. The figure won't be displayed correctly. The workaround is to save the image as a file and display it from the notebook.
Please let us know if you have better solutions.
!andes plot kundur_full_out.lst 0 5 6 --save
Figure saved to "kundur_full_out_1.png". Figure(640x480)
from IPython.display import Image
Image("kundur_full_out_1.png")
xargs
for index loop up¶A convenient tool in Linux/macOS is xargs
, which turns the standard output of one program into arguments for another.
andes plot --xargs
accepts an input of search pattern for variable names and returns a list of arguments, including the matched indices, that can be understood by andes plot
.
A convenient tool in Linux/macOS is xargs
, which turns the standard output of one program into arguments for another.
andes plot --xargs
accepts an input of search pattern for variable names and returns a list of arguments, including the matched indices, that can be understood by andes plot
.
xargs
for index lookup¶A convenient tool in Linux/macOS is xargs
, which turns the standard output of one program into arguments for another.
andes plot --xargs
accepts an input of search pattern for variable names and returns a list of arguments, including the matched indices, that can be understood by andes plot
.
To illustrate, let's look at an example output of andes plot --xargs
.
!andes plot kundur_full_out.lst --xargs "omega GENROU"
kundur_full_out.lst 0 5 6 7 8
The output consists of the lst file name, the default x-axis index 0
, and the indices for the found variables. The full output can be passed to andes plot
without modification.
We use the following command to pass the arguments:
!andes plot kundur_full_out.lst --xargs "omega GENROU" | xargs andes plot
Figure(640x480)
where |
is the pipe operator in shell for piping the standard output of the left-hand side to the right-hand side, xargs
captures the pipe-in and appends it to andes plot
.
The command is equivalent to manually running
!andes plot kundur_full_out.lst 5 6 7 8
Figure(640x480)
Remove the saved png
image files.
!rm -v *.png
removed 'kundur_full_out_1.png'
!andes misc -C
_ _ | Version 1.3.4.post6.dev0+g1cc8c20 /_\ _ _ __| |___ ___ | Python 3.8.6 on Linux, 03/17/2021 08:45:48 PM / _ \| ' \/ _` / -_|_-< | /_/ \_\_||_\__,_\___/__/ | This program comes with ABSOLUTELY NO WARRANTY. "/home/hcui7/repos/andes/examples/kundur_full_out.npz" removed. "/home/hcui7/repos/andes/examples/kundur_full_out.lst" removed. "/home/hcui7/repos/andes/examples/kundur_full_out.txt" removed. "/home/hcui7/repos/andes/examples/kundur_out.lst" removed. "/home/hcui7/repos/andes/examples/kundur_out.npz" removed. "/home/hcui7/repos/andes/examples/kundur_out.txt" removed.