Output Simulation Results#

In AMS, the results can be output in different formats.

One is the plain-text format, where it lists all solved dispatch requests. Another is the CSV format, where the dispatch results are exported to a CSV file.

[1]:
import os

import ams

import pandas as pd
[2]:
ams.config_logger(stream_level=20)

Import case and run simulation#

[3]:
sp = ams.load(ams.get_case('5bus/pjm5bus_demo.xlsx'),
              setup=True,
              no_output=False,)
Parsing input file "/Users/jinningwang/work/miniconda3/envs/amsre/lib/python3.12/site-packages/ams/cases/5bus/pjm5bus_demo.xlsx"...
Input file parsed in 0.1084 seconds.
Zero line rates detacted in rate_b, rate_c, adjusted to 999.
System set up in 0.0024 seconds.
[4]:
sp.DCOPF.run(solver='CLARABEL')
Building system matrices
Parsing OModel for <DCOPF>
Evaluating OModel for <DCOPF>
Finalizing OModel for <DCOPF>
<DCOPF> initialized in 0.0181 seconds.
<DCOPF> solved as optimal in 0.0137 seconds, converged in 8 iterations with CLARABEL.
Report saved to "pjm5bus_demo_out.txt" in 0.0016 seconds.
[4]:
True

Report to plain text#

Then, the system method report() can generated a plain-text report of the simulation results.

If multiple simulation runs are performed, the report will contain all of them.

[5]:
sp.report()
Report saved to "pjm5bus_demo_out.txt" in 0.0019 seconds.
[5]:
True

The report is like:

[6]:
report_file = "pjm5bus_demo_out.txt"

with open(report_file, 'r') as file:
    report_content = file.read()

print(report_content)
AMS 1.0.6
Copyright (C) 2023-2025 Jinning Wang

AMS comes with ABSOLUTELY NO WARRANTY
Case file: /Users/jinningwang/work/miniconda3/envs/amsre/lib/python3.12/site-packages/ams/cases/5bus/pjm5bus_demo.xlsx
Report time: 04/12/2025 04:54:26 PM


========== System Statistics ==========
Buses                              5
Generators                         5
Loads                              3
Shunts                             0
Lines                              7
Transformers                       0
Areas                              3
Zones                              2

============================== DCOPF ==============================
                            P (p.u.)

Generation                        10
Load                              10

Bus DATA:
                                Name       vBus (p.u.)        aBus (rad)       pi ($/p.u.)

0                                  A                 0          0.023989          0.077623
1                                  B                 0          0.034668              0.01
2                                  C                 0          0.013068               0.3
3                                  D                 0                -0           0.15705
4                                  E                 0          0.022896          0.091705

Line DATA:
                                Name        plf (p.u.)

Line_1                       Line AB          -0.38001
Line_2                       Line AD           0.78912
Line_3                       Line AE           0.17089
Line_4                       Line BC                 2
Line_5                       Line CD           0.43998
Line_6                       Line DE          -0.77089
Line_7                      Line AB2          -0.38001

StaticGen DATA:
                                Name         pg (p.u.)      pmaxe (p.u.)      pmine (p.u.)

PV_1                            Alta               0.2               2.1               0.2
PV_3                        Solitude              1.44               5.2               0.5
PV_5                        Brighton               0.6                 6               0.6
PV_2                            PV 2              5.76                99               -99
Slack_4                     Sundance                 2                 2               0.2


Export to CSV#

The dispatch simulation can also be exported to a CSV file.

[7]:
sp.ED.run(solver='CLARABEL')
Parsing OModel for <ED>
Evaluating OModel for <ED>
Finalizing OModel for <ED>
<ED> initialized in 0.0237 seconds.
<ED> solved as optimal in 0.0214 seconds, converged in 11 iterations with CLARABEL.
Report saved to "pjm5bus_demo_out.txt" in 0.0040 seconds.
[7]:
True
[8]:
sp.ED.export_csv()
[8]:
'pjm5bus_demo_ED.csv'
[9]:
df = pd.read_csv('pjm5bus_demo_ED.csv')

In the exported CSV file, each row represents a timeslot, and each column represents a variable.

[10]:
df.iloc[:, :10]
[10]:
Time pg PV_1 pg PV_3 pg PV_5 pg PV_2 pg Slack_4 vBus 0 vBus 1 vBus 2 vBus 3
0 EDT1 0.2 0.500000 0.6 4.829523 1.870477 0.0 0.0 0.0 0.0
1 EDT2 0.2 0.937153 0.6 5.262847 2.000000 0.0 0.0 0.0 0.0
2 EDT3 0.2 1.439984 0.6 5.760016 2.000000 0.0 0.0 0.0 0.0
3 EDT4 0.2 0.937153 0.6 5.262847 2.000000 0.0 0.0 0.0 0.0
4 EDT5 0.2 0.500000 0.6 4.829523 1.870477 0.0 0.0 0.0 0.0

Cleanup#

Remove the output files.

[11]:
os.remove('pjm5bus_demo_out.txt')
os.remove('pjm5bus_demo_ED.csv')