Export 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/ams/ams/cases/5bus/pjm5bus_demo.xlsx"...
Input file parsed in 0.0761 seconds.
Zero Line parameters detected, adjusted to default values: rate_b, rate_c.
All bus type are PQ, adjusted given load and generator connection status.
System set up in 0.0021 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.0100 seconds.
<DCOPF> solved as optimal in 0.0066 seconds, converged in 9 iterations with CLARABEL.
Report saved to "pjm5bus_demo_out.txt" in 0.0010 seconds.
<DCOPF> RParam <c2> should have all non-negative values.
[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.0015 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.1.0.post75.dev0+gcc96e89c
Copyright (C) 2023-2025 Jinning Wang

AMS comes with ABSOLUTELY NO WARRANTY
Case file: /Users/jinningwang/work/ams/ams/cases/5bus/pjm5bus_demo.xlsx
Report time: 12/21/2025 12:00:06 AM


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

============================== DCOPF ==============================
                  Objective Function

Value in $                     9.536

                            P (p.u.)

Generation                        10
Load                              10

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

0                                  A                 1          0.023989           0.77623
1                                  B                 1          0.034668               0.1
2                                  C                 1          0.013068                 3
3                                  D                 1                -0            1.5705
4                                  E                 1          0.022896           0.91705

Line DATA:
                                Name        plf (p.u.)      mu1 ($/p.u.)      mu2 ($/p.u.)

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

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.0133 seconds.
<ED> solved as optimal in 0.0194 seconds, converged in 14 iterations with CLARABEL.
Report saved to "pjm5bus_demo_out.txt" in 0.0102 seconds.
<ED> RParam <c2> should have all non-negative values.
[7]:
True
[8]:
out_csv = sp.ED.export_csv()

out_csv
[8]:
'pjm5bus_demo_ED.csv'
[9]:
df = pd.read_csv(out_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.828936 1.801064 1.0 1.0 1.0 1.0
1 EDT2 0.2 0.500000 0.6 4.825838 1.434162 1.0 1.0 1.0 1.0
2 EDT3 0.2 0.500000 0.6 4.823074 1.106926 1.0 1.0 1.0 1.0
3 EDT4 0.2 0.500000 0.6 4.821818 0.958182 1.0 1.0 1.0 1.0
4 EDT5 0.2 0.500000 0.6 4.821148 0.878852 1.0 1.0 1.0 1.0
5 EDT6 0.2 0.500000 0.6 4.821651 0.938349 1.0 1.0 1.0 1.0
6 EDT7 0.2 0.500000 0.6 4.825335 1.374665 1.0 1.0 1.0 1.0
7 EDT8 0.2 0.500000 0.6 4.829690 1.890310 1.0 1.0 1.0 1.0
8 EDT9 0.2 0.575115 0.6 4.904885 2.000000 1.0 1.0 1.0 1.0
9 EDT10 0.2 0.690766 0.6 5.019234 2.000000 1.0 1.0 1.0 1.0
10 EDT11 0.2 0.806417 0.6 5.133583 2.000000 1.0 1.0 1.0 1.0
11 EDT12 0.2 0.927096 0.6 5.252904 2.000000 1.0 1.0 1.0 1.0
12 EDT13 0.2 1.032691 0.6 5.357309 2.000000 1.0 1.0 1.0 1.0
13 EDT14 0.2 1.173483 0.6 5.496517 2.000000 1.0 1.0 1.0 1.0
14 EDT15 0.2 1.289135 0.6 5.610865 2.000000 1.0 1.0 1.0 1.0
15 EDT16 0.2 1.374616 0.6 5.695384 2.000000 1.0 1.0 1.0 1.0
16 EDT17 0.2 1.439984 0.6 5.760016 2.000000 1.0 1.0 1.0 1.0
17 EDT18 0.2 1.439984 0.6 5.760016 2.000000 1.0 1.0 1.0 1.0
18 EDT19 0.2 1.394729 0.6 5.715271 2.000000 1.0 1.0 1.0 1.0
19 EDT20 0.2 1.218738 0.6 5.541262 2.000000 1.0 1.0 1.0 1.0
20 EDT21 0.2 1.088002 0.6 5.411998 2.000000 1.0 1.0 1.0 1.0
21 EDT22 0.2 0.962294 0.6 5.287706 2.000000 1.0 1.0 1.0 1.0
22 EDT23 0.2 0.680709 0.6 5.009291 2.000000 1.0 1.0 1.0 1.0
23 EDT24 0.2 0.500000 0.6 4.828183 1.711817 1.0 1.0 1.0 1.0

Cleanup#

Remove the output files.

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