{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"# Manipulate the Simulation"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This example shows how to play with the simulation,\n",
"such as contingency analysis and manipulate the constraints."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import ams\n",
"\n",
"import datetime"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Last run time: 2024-11-24 17:46:29\n",
"ams:0.9.12\n"
]
}
],
"source": [
"print(\"Last run time:\", datetime.datetime.now().strftime(\"%Y-%m-%d %H:%M:%S\"))\n",
"\n",
"print(f'ams:{ams.__version__}')"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"ams.config_logger(stream_level=20)"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## Manipulate the Simulation"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"### Load Case"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Working directory: \"/Users/jinningwang/work/ams/examples\"\n",
"Parsing input file \"/Users/jinningwang/work/miniconda3/envs/amsre/lib/python3.12/site-packages/ams/cases/5bus/pjm5bus_uced.xlsx\"...\n",
"Input file parsed in 0.0218 seconds.\n",
"Zero line rates detacted in rate_b, rate_c, adjusted to 999.\n",
"System set up in 0.0018 seconds.\n"
]
}
],
"source": [
"sp = ams.load(ams.get_case('5bus/pjm5bus_uced.xlsx'),\n",
" setup=True,\n",
" no_output=True,)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The system load are defined in model `PQ`."
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" idx | \n",
" u | \n",
" name | \n",
" bus | \n",
" Vn | \n",
" p0 | \n",
" q0 | \n",
" vmax | \n",
" vmin | \n",
" owner | \n",
" ctrl | \n",
"
\n",
" \n",
" | uid | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" PQ_1 | \n",
" 1.0 | \n",
" PQ 1 | \n",
" Bus_2 | \n",
" 230.0 | \n",
" 3.0 | \n",
" 0.9861 | \n",
" 1.1 | \n",
" 0.9 | \n",
" None | \n",
" 1.0 | \n",
"
\n",
" \n",
" | 1 | \n",
" PQ_2 | \n",
" 1.0 | \n",
" PQ 2 | \n",
" Bus_3 | \n",
" 230.0 | \n",
" 3.0 | \n",
" 0.9861 | \n",
" 1.1 | \n",
" 0.9 | \n",
" None | \n",
" 1.0 | \n",
"
\n",
" \n",
" | 2 | \n",
" PQ_3 | \n",
" 1.0 | \n",
" PQ 3 | \n",
" Bus_4 | \n",
" 230.0 | \n",
" 4.0 | \n",
" 1.3147 | \n",
" 1.1 | \n",
" 0.9 | \n",
" None | \n",
" 1.0 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" idx u name bus Vn p0 q0 vmax vmin owner ctrl\n",
"uid \n",
"0 PQ_1 1.0 PQ 1 Bus_2 230.0 3.0 0.9861 1.1 0.9 None 1.0\n",
"1 PQ_2 1.0 PQ 2 Bus_3 230.0 3.0 0.9861 1.1 0.9 None 1.0\n",
"2 PQ_3 1.0 PQ 3 Bus_4 230.0 4.0 1.3147 1.1 0.9 None 1.0"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sp.PQ.as_df()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In RTED, system load is referred as `pd`."
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([3., 3., 4.])"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sp.RTED.pd.v"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Run Simulation"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"RTED can be solved and one can inspect the results as discussed in\n",
"previous example."
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Building system matrices\n",
"Parsing OModel for \n",
"Evaluating OModel for \n",
"Finalizing OModel for \n",
" initialized in 0.0097 seconds.\n",
" solved as optimal in 0.0095 seconds, converged in 10 iterations with CLARABEL.\n"
]
},
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sp.RTED.run(solver='CLARABEL')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Power generation `pg` and line flow `plf` can be accessed as follows."
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([2. , 2.1, 5.2, 0.7])"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sp.RTED.pg.v"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 0.70595331, 0.68616798, 0.00192539, -1.58809337, 0.61190663,\n",
" -0.70192539, 0.70595331])"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sp.RTED.plf.v"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Change Load"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The load values can be manipulated in the model `PQ`.\n",
"\n",
"Note the difference between `Model.set` and `Model.alter`:\n",
"\n",
"`set`: This method ***WILL NOT*** modify the input values from the case file that have not been converted to the system base. As a result, changes applied by this method ***WILL NOT*** affect the dumped case file.\n",
"\n",
"`alter`: If the method operates on an input parameter, the new data ***should be in the same base as that in the input file***. This function will convert ``value`` to per unit in the system base whenever necessary. The values for storing the input data, i.e., the parameter's ``vin`` field, will be overwritten. As a result, altered values ***WILL BE*** reflected in the dumped case file."
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"sp.PQ.alter(src='p0', idx=['PQ_1', 'PQ_2'], value=[3.2, 3.2])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"According parameters need to be updated to make the changes effective in the optimization model.\n",
"If not sure which parameters need to be updated, one can use\n",
"``update()`` to update all parameters."
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sp.RTED.update('pd')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"After manipulation, the routined can be solved again."
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
" solved as optimal in 0.0014 seconds, converged in 10 iterations with CLARABEL.\n"
]
},
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sp.RTED.run(solver='CLARABEL')"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([2. , 2.09999999, 5.19999999, 1.10000002])"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sp.RTED.pg.v"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"An alternative way is to alter the load through ``RTED``.\n",
"\n",
"As ``pd`` has owner ``StaticLoad`` and soruce ``p0``, the parameter update through ``RTED`` actually happens to ``StaticLoad.p0``."
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"StaticLoad (3 devices) at 0x16b03adb0"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sp.RTED.pd.owner"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'p0'"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sp.RTED.pd.src"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Similarly, the load can be changed using ``set`` method."
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sp.RTED.set(src='pd', attr='v', idx=['PQ_1', 'PQ_2'], value=[0.2, 0.2])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Remember to update the optimization parameters after the change."
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sp.RTED.update('pd')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can see that the original load is also updated."
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" idx | \n",
" u | \n",
" name | \n",
" bus | \n",
" Vn | \n",
" p0 | \n",
" q0 | \n",
" vmax | \n",
" vmin | \n",
" owner | \n",
" ctrl | \n",
"
\n",
" \n",
" | uid | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" PQ_1 | \n",
" 1.0 | \n",
" PQ 1 | \n",
" Bus_2 | \n",
" 230.0 | \n",
" 0.2 | \n",
" 0.9861 | \n",
" 1.1 | \n",
" 0.9 | \n",
" None | \n",
" 1.0 | \n",
"
\n",
" \n",
" | 1 | \n",
" PQ_2 | \n",
" 1.0 | \n",
" PQ 2 | \n",
" Bus_3 | \n",
" 230.0 | \n",
" 0.2 | \n",
" 0.9861 | \n",
" 1.1 | \n",
" 0.9 | \n",
" None | \n",
" 1.0 | \n",
"
\n",
" \n",
" | 2 | \n",
" PQ_3 | \n",
" 1.0 | \n",
" PQ 3 | \n",
" Bus_4 | \n",
" 230.0 | \n",
" 4.0 | \n",
" 1.3147 | \n",
" 1.1 | \n",
" 0.9 | \n",
" None | \n",
" 1.0 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" idx u name bus Vn p0 q0 vmax vmin owner ctrl\n",
"uid \n",
"0 PQ_1 1.0 PQ 1 Bus_2 230.0 0.2 0.9861 1.1 0.9 None 1.0\n",
"1 PQ_2 1.0 PQ 2 Bus_3 230.0 0.2 0.9861 1.1 0.9 None 1.0\n",
"2 PQ_3 1.0 PQ 3 Bus_4 230.0 4.0 1.3147 1.1 0.9 None 1.0"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sp.PQ.as_df()"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
" solved as optimal in 0.0018 seconds, converged in 10 iterations with CLARABEL.\n"
]
},
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sp.RTED.run(solver='CLARABEL')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"As expected, the power generation also changed."
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([1.99999999, 1.30000001, 0.5 , 0.6 ])"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sp.RTED.pg.v"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Trip a Generator"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can see that there are three PV generators in the system.\n",
"\n",
"> **Warning:** in `MatProcessor`, `StaticGen` online status is NOT considered in its connectivity matrix `Cg`.\n",
"> The same applies for `PQ`, `Line`, and `Shunt`."
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" idx | \n",
" u | \n",
" name | \n",
" Sn | \n",
" Vn | \n",
" bus | \n",
" busr | \n",
" p0 | \n",
" q0 | \n",
" pmax | \n",
" pmin | \n",
" qmax | \n",
" qmin | \n",
" v0 | \n",
" vmax | \n",
" vmin | \n",
" ra | \n",
" xs | \n",
" ctrl | \n",
" uf | \n",
" Pc1 | \n",
" Pc2 | \n",
" Qc1min | \n",
" Qc1max | \n",
" Qc2min | \n",
" Qc2max | \n",
" Ragc | \n",
" R10 | \n",
" R30 | \n",
" Rq | \n",
" apf | \n",
" pg0 | \n",
" td1 | \n",
" td2 | \n",
"
\n",
" \n",
" | uid | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" PV_1 | \n",
" 1.0 | \n",
" Alta | \n",
" 100.0 | \n",
" 230.0 | \n",
" Bus_1 | \n",
" None | \n",
" 1.0000 | \n",
" 0.0 | \n",
" 2.1 | \n",
" 0.2 | \n",
" 0.300 | \n",
" -0.300 | \n",
" 1.0 | \n",
" 1.4 | \n",
" 0.6 | \n",
" 0.01 | \n",
" 0.3 | \n",
" 1.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 999.0 | \n",
" 999.0 | \n",
" 999.0 | \n",
" 999.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.5 | \n",
" 0.0 | \n",
"
\n",
" \n",
" | 1 | \n",
" PV_3 | \n",
" 1.0 | \n",
" Solitude | \n",
" 100.0 | \n",
" 230.0 | \n",
" Bus_3 | \n",
" None | \n",
" 3.2349 | \n",
" 0.0 | \n",
" 5.2 | \n",
" 0.5 | \n",
" 1.275 | \n",
" -1.275 | \n",
" 1.0 | \n",
" 1.4 | \n",
" 0.6 | \n",
" 0.01 | \n",
" 0.3 | \n",
" 1.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 999.0 | \n",
" 999.0 | \n",
" 999.0 | \n",
" 999.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.5 | \n",
" 0.0 | \n",
"
\n",
" \n",
" | 2 | \n",
" PV_5 | \n",
" 1.0 | \n",
" Brighton | \n",
" 100.0 | \n",
" 230.0 | \n",
" Bus_5 | \n",
" None | \n",
" 4.6651 | \n",
" 0.0 | \n",
" 6.0 | \n",
" 0.6 | \n",
" 4.500 | \n",
" -4.500 | \n",
" 1.0 | \n",
" 1.4 | \n",
" 0.6 | \n",
" 0.01 | \n",
" 0.3 | \n",
" 1.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 999.0 | \n",
" 999.0 | \n",
" 999.0 | \n",
" 999.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.5 | \n",
" 0.0 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" idx u name Sn Vn bus busr p0 q0 pmax pmin \\\n",
"uid \n",
"0 PV_1 1.0 Alta 100.0 230.0 Bus_1 None 1.0000 0.0 2.1 0.2 \n",
"1 PV_3 1.0 Solitude 100.0 230.0 Bus_3 None 3.2349 0.0 5.2 0.5 \n",
"2 PV_5 1.0 Brighton 100.0 230.0 Bus_5 None 4.6651 0.0 6.0 0.6 \n",
"\n",
" qmax qmin v0 vmax vmin ra xs ctrl uf Pc1 Pc2 Qc1min \\\n",
"uid \n",
"0 0.300 -0.300 1.0 1.4 0.6 0.01 0.3 1.0 0.0 0.0 0.0 0.0 \n",
"1 1.275 -1.275 1.0 1.4 0.6 0.01 0.3 1.0 0.0 0.0 0.0 0.0 \n",
"2 4.500 -4.500 1.0 1.4 0.6 0.01 0.3 1.0 0.0 0.0 0.0 0.0 \n",
"\n",
" Qc1max Qc2min Qc2max Ragc R10 R30 Rq apf pg0 td1 td2 \n",
"uid \n",
"0 0.0 0.0 0.0 999.0 999.0 999.0 999.0 0.0 0.0 0.5 0.0 \n",
"1 0.0 0.0 0.0 999.0 999.0 999.0 999.0 0.0 0.0 0.5 0.0 \n",
"2 0.0 0.0 0.0 999.0 999.0 999.0 999.0 0.0 0.0 0.5 0.0 "
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sp.PV.as_df()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"`PV_1` is tripped by setting its connection status `u` to 0."
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sp.StaticGen.set(src='u', idx='PV_1', attr='v', value=0)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In AMS, some parameters are defiend as constants in the numerical optimization model\n",
"to follow the CVXPY DCP and DPP rules.\n",
"Once non-parametric parameters are changed, the optimization model will be\n",
"re-initialized to make the changes effective.\n",
"\n",
"More details can be found at [CVXPY - Disciplined Convex Programming](https://www.cvxpy.org/tutorial/dcp/index.html#disciplined-convex-programming)."
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Building system matrices\n",
" reinit OModel due to non-parametric change.\n",
"Evaluating OModel for \n",
"Finalizing OModel for \n"
]
},
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sp.RTED.update()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Then we can re-solve the model."
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
" solved as optimal in 0.0099 seconds, converged in 9 iterations with CLARABEL.\n"
]
},
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sp.RTED.run(solver='CLARABEL')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can see that the tripped generator has no power generation."
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 2. , -0. , 1.8, 0.6])"
]
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sp.RTED.pg.v.round(2)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Trip a Line"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can inspect the `Line` model to check the system topology."
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" idx | \n",
" u | \n",
" name | \n",
" bus1 | \n",
" bus2 | \n",
" Sn | \n",
" fn | \n",
" Vn1 | \n",
" Vn2 | \n",
" r | \n",
" x | \n",
" b | \n",
" g | \n",
" b1 | \n",
" g1 | \n",
" b2 | \n",
" g2 | \n",
" trans | \n",
" tap | \n",
" phi | \n",
" rate_a | \n",
" rate_b | \n",
" rate_c | \n",
" owner | \n",
" xcoord | \n",
" ycoord | \n",
" amin | \n",
" amax | \n",
"
\n",
" \n",
" | uid | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" Line_0 | \n",
" 1.0 | \n",
" Line AB | \n",
" Bus_1 | \n",
" Bus_2 | \n",
" 100.0 | \n",
" 60.0 | \n",
" 230.0 | \n",
" 230.0 | \n",
" 0.00281 | \n",
" 0.0281 | \n",
" 0.00712 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 1.0 | \n",
" 0.0 | \n",
" 4.0 | \n",
" 999.0 | \n",
" 999.0 | \n",
" None | \n",
" None | \n",
" None | \n",
" -6.283185 | \n",
" 6.283185 | \n",
"
\n",
" \n",
" | 1 | \n",
" Line_1 | \n",
" 1.0 | \n",
" Line AD | \n",
" Bus_1 | \n",
" Bus_4 | \n",
" 100.0 | \n",
" 60.0 | \n",
" 230.0 | \n",
" 230.0 | \n",
" 0.00304 | \n",
" 0.0304 | \n",
" 0.00658 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 1.0 | \n",
" 0.0 | \n",
" 2.0 | \n",
" 999.0 | \n",
" 999.0 | \n",
" None | \n",
" None | \n",
" None | \n",
" -6.283185 | \n",
" 6.283185 | \n",
"
\n",
" \n",
" | 2 | \n",
" Line_2 | \n",
" 1.0 | \n",
" Line AE | \n",
" Bus_1 | \n",
" Bus_5 | \n",
" 100.0 | \n",
" 60.0 | \n",
" 230.0 | \n",
" 230.0 | \n",
" 0.00064 | \n",
" 0.0064 | \n",
" 0.03126 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 1.0 | \n",
" 0.0 | \n",
" 2.0 | \n",
" 999.0 | \n",
" 999.0 | \n",
" None | \n",
" None | \n",
" None | \n",
" -6.283185 | \n",
" 6.283185 | \n",
"
\n",
" \n",
" | 3 | \n",
" Line_3 | \n",
" 1.0 | \n",
" Line BC | \n",
" Bus_2 | \n",
" Bus_3 | \n",
" 100.0 | \n",
" 60.0 | \n",
" 230.0 | \n",
" 230.0 | \n",
" 0.00108 | \n",
" 0.0108 | \n",
" 0.01852 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 1.0 | \n",
" 0.0 | \n",
" 2.0 | \n",
" 999.0 | \n",
" 999.0 | \n",
" None | \n",
" None | \n",
" None | \n",
" -6.283185 | \n",
" 6.283185 | \n",
"
\n",
" \n",
" | 4 | \n",
" Line_4 | \n",
" 1.0 | \n",
" Line CD | \n",
" Bus_3 | \n",
" Bus_4 | \n",
" 100.0 | \n",
" 60.0 | \n",
" 230.0 | \n",
" 230.0 | \n",
" 0.00297 | \n",
" 0.0297 | \n",
" 0.00674 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 1.0 | \n",
" 0.0 | \n",
" 2.0 | \n",
" 999.0 | \n",
" 999.0 | \n",
" None | \n",
" None | \n",
" None | \n",
" -6.283185 | \n",
" 6.283185 | \n",
"
\n",
" \n",
" | 5 | \n",
" Line_5 | \n",
" 1.0 | \n",
" Line DE | \n",
" Bus_4 | \n",
" Bus_5 | \n",
" 100.0 | \n",
" 60.0 | \n",
" 230.0 | \n",
" 230.0 | \n",
" 0.00297 | \n",
" 0.0297 | \n",
" 0.00674 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 1.0 | \n",
" 0.0 | \n",
" 2.4 | \n",
" 999.0 | \n",
" 999.0 | \n",
" None | \n",
" None | \n",
" None | \n",
" -6.283185 | \n",
" 6.283185 | \n",
"
\n",
" \n",
" | 6 | \n",
" Line_6 | \n",
" 1.0 | \n",
" Line AB2 | \n",
" Bus_1 | \n",
" Bus_2 | \n",
" 100.0 | \n",
" 60.0 | \n",
" 230.0 | \n",
" 230.0 | \n",
" 0.00281 | \n",
" 0.0281 | \n",
" 0.00712 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 1.0 | \n",
" 0.0 | \n",
" 4.0 | \n",
" 999.0 | \n",
" 999.0 | \n",
" None | \n",
" None | \n",
" None | \n",
" -6.283185 | \n",
" 6.283185 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" idx u name bus1 bus2 Sn fn Vn1 Vn2 r \\\n",
"uid \n",
"0 Line_0 1.0 Line AB Bus_1 Bus_2 100.0 60.0 230.0 230.0 0.00281 \n",
"1 Line_1 1.0 Line AD Bus_1 Bus_4 100.0 60.0 230.0 230.0 0.00304 \n",
"2 Line_2 1.0 Line AE Bus_1 Bus_5 100.0 60.0 230.0 230.0 0.00064 \n",
"3 Line_3 1.0 Line BC Bus_2 Bus_3 100.0 60.0 230.0 230.0 0.00108 \n",
"4 Line_4 1.0 Line CD Bus_3 Bus_4 100.0 60.0 230.0 230.0 0.00297 \n",
"5 Line_5 1.0 Line DE Bus_4 Bus_5 100.0 60.0 230.0 230.0 0.00297 \n",
"6 Line_6 1.0 Line AB2 Bus_1 Bus_2 100.0 60.0 230.0 230.0 0.00281 \n",
"\n",
" x b g b1 g1 b2 g2 trans tap phi rate_a \\\n",
"uid \n",
"0 0.0281 0.00712 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 4.0 \n",
"1 0.0304 0.00658 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 2.0 \n",
"2 0.0064 0.03126 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 2.0 \n",
"3 0.0108 0.01852 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 2.0 \n",
"4 0.0297 0.00674 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 2.0 \n",
"5 0.0297 0.00674 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 2.4 \n",
"6 0.0281 0.00712 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 4.0 \n",
"\n",
" rate_b rate_c owner xcoord ycoord amin amax \n",
"uid \n",
"0 999.0 999.0 None None None -6.283185 6.283185 \n",
"1 999.0 999.0 None None None -6.283185 6.283185 \n",
"2 999.0 999.0 None None None -6.283185 6.283185 \n",
"3 999.0 999.0 None None None -6.283185 6.283185 \n",
"4 999.0 999.0 None None None -6.283185 6.283185 \n",
"5 999.0 999.0 None None None -6.283185 6.283185 \n",
"6 999.0 999.0 None None None -6.283185 6.283185 "
]
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sp.Line.as_df()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Here line `2` is tripped by setting its connection status `u` to 0.\n",
"\n",
"Note that in ANDES, dynamic simulation of *line tripping should use model ``Toggle``.*"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [],
"source": [
"sp.Line.alter(src='u', idx='Line_1', value=0)"
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Building system matrices\n",
" reinit OModel due to non-parametric change.\n",
"Evaluating OModel for \n",
"Finalizing OModel for \n"
]
},
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sp.RTED.update()"
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
" solved as optimal in 0.0102 seconds, converged in 9 iterations with CLARABEL.\n"
]
},
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 29,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sp.RTED.run(solver='CLARABEL')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Here we can see the tripped line has no flow."
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([-0.12, 0. , 0.24, -0.44, 1.16, -0.84, -0.12])"
]
},
"execution_count": 30,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sp.RTED.plf.v.round(2)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Disable Constraints"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In addition to the system parameters, the constraints can also be manipulated.\n",
"\n",
"Here, we load the case to a new system."
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Working directory: \"/Users/jinningwang/work/ams/examples\"\n",
"Parsing input file \"/Users/jinningwang/work/miniconda3/envs/amsre/lib/python3.12/site-packages/ams/cases/5bus/pjm5bus_uced.xlsx\"...\n",
"Input file parsed in 0.0215 seconds.\n",
"Zero line rates detacted in rate_b, rate_c, adjusted to 999.\n",
"System set up in 0.0019 seconds.\n"
]
}
],
"source": [
"spc = ams.load(ams.get_case('5bus/pjm5bus_uced.xlsx'),\n",
" setup=True,\n",
" no_output=True,)"
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Building system matrices\n",
"Parsing OModel for \n",
"Evaluating OModel for \n",
"Finalizing OModel for \n",
" initialized in 0.0085 seconds.\n"
]
},
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 32,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"spc.RTED.init()"
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 33,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"spc.RTED.set(src='rate_a', idx=['Line_3'], attr='v', value=0.6)"
]
},
{
"cell_type": "code",
"execution_count": 34,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 34,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"spc.RTED.update('rate_a')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can inspect the constraints status as follows.\n",
"All constraints are turned on by default."
]
},
{
"cell_type": "code",
"execution_count": 35,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"OrderedDict([('pb', Constraint: pb [ON]),\n",
" ('sba', Constraint: sbus [ON]),\n",
" ('pglb', Constraint: pglb [ON]),\n",
" ('pgub', Constraint: pgub [ON]),\n",
" ('plflb', Constraint: plflb [ON]),\n",
" ('plfub', Constraint: plfub [ON]),\n",
" ('alflb', Constraint: alflb [ON]),\n",
" ('alfub', Constraint: alfub [ON]),\n",
" ('rbu', Constraint: rbu [ON]),\n",
" ('rbd', Constraint: rbd [ON]),\n",
" ('rru', Constraint: rru [ON]),\n",
" ('rrd', Constraint: rrd [ON]),\n",
" ('rgu', Constraint: rgu [ON]),\n",
" ('rgd', Constraint: rgd [ON])])"
]
},
"execution_count": 35,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"spc.RTED.constrs"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Then, solve the dispatch and inspect the line flow."
]
},
{
"cell_type": "code",
"execution_count": 36,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
" solved as optimal in 0.0098 seconds, converged in 10 iterations with CLARABEL.\n"
]
},
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 36,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"spc.RTED.run(solver='CLARABEL')"
]
},
{
"cell_type": "code",
"execution_count": 37,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 1.2 , 0.87, -1.17, -0.6 , -0.02, -1.15, 1.2 ])"
]
},
"execution_count": 37,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"spc.RTED.plf.v.round(2)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In the next, we can disable specific constraints, and the parameter name takes both single constraint name or a list of constraint names."
]
},
{
"cell_type": "code",
"execution_count": 38,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Turn off constraints: plflb, plfub\n"
]
},
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 38,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"spc.RTED.disable(['plflb', 'plfub'])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now, it can be seen that the two constraints are disabled."
]
},
{
"cell_type": "code",
"execution_count": 39,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"OrderedDict([('pb', Constraint: pb [ON]),\n",
" ('sba', Constraint: sbus [ON]),\n",
" ('pglb', Constraint: pglb [ON]),\n",
" ('pgub', Constraint: pgub [ON]),\n",
" ('plflb', Constraint: plflb [OFF]),\n",
" ('plfub', Constraint: plfub [OFF]),\n",
" ('alflb', Constraint: alflb [ON]),\n",
" ('alfub', Constraint: alfub [ON]),\n",
" ('rbu', Constraint: rbu [ON]),\n",
" ('rbd', Constraint: rbd [ON]),\n",
" ('rru', Constraint: rru [ON]),\n",
" ('rrd', Constraint: rrd [ON]),\n",
" ('rgu', Constraint: rgu [ON]),\n",
" ('rgd', Constraint: rgd [ON])])"
]
},
"execution_count": 39,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"spc.RTED.constrs"
]
},
{
"cell_type": "code",
"execution_count": 40,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Disabled constraints: plflb, plfub\n",
"Finalizing OModel for \n",
" initialized in 0.0011 seconds.\n",
" solved as optimal in 0.0078 seconds, converged in 9 iterations with CLARABEL.\n"
]
},
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 40,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"spc.RTED.run(solver='CLARABEL')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can see that now the line flow limits are not in effect."
]
},
{
"cell_type": "code",
"execution_count": 41,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 0.71, 0.69, 0. , -1.59, 0.61, -0.7 , 0.71])"
]
},
"execution_count": 41,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"spc.RTED.plf.v.round(2)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Similarly, you can also enable the constraints again."
]
},
{
"cell_type": "code",
"execution_count": 42,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Turn on constraints: plflb, plfub\n"
]
},
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 42,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"spc.RTED.enable(['plflb', 'plfub'])"
]
},
{
"cell_type": "code",
"execution_count": 43,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"OrderedDict([('pb', Constraint: pb [ON]),\n",
" ('sba', Constraint: sbus [ON]),\n",
" ('pglb', Constraint: pglb [ON]),\n",
" ('pgub', Constraint: pgub [ON]),\n",
" ('plflb', Constraint: plflb [ON]),\n",
" ('plfub', Constraint: plfub [ON]),\n",
" ('alflb', Constraint: alflb [ON]),\n",
" ('alfub', Constraint: alfub [ON]),\n",
" ('rbu', Constraint: rbu [ON]),\n",
" ('rbd', Constraint: rbd [ON]),\n",
" ('rru', Constraint: rru [ON]),\n",
" ('rrd', Constraint: rrd [ON]),\n",
" ('rgu', Constraint: rgu [ON]),\n",
" ('rgd', Constraint: rgd [ON])])"
]
},
"execution_count": 43,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"spc.RTED.constrs"
]
},
{
"cell_type": "code",
"execution_count": 44,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Finalizing OModel for \n",
" initialized in 0.0009 seconds.\n",
" solved as optimal in 0.0083 seconds, converged in 10 iterations with CLARABEL.\n"
]
},
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 44,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"spc.RTED.run(solver='CLARABEL')"
]
},
{
"cell_type": "code",
"execution_count": 45,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 1.2 , 0.87, -1.17, -0.6 , -0.02, -1.15, 1.2 ])"
]
},
"execution_count": 45,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"spc.RTED.plf.v.round(2)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Alternatively, you can also **force init** the dispatch to rebuild the system matrices, enable all constraints, and re-init the optimization models."
]
},
{
"cell_type": "code",
"execution_count": 46,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Turn off constraints: plflb, plfub, rgu, rgd\n"
]
},
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 46,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"spc.RTED.disable(['plflb', 'plfub', 'rgu', 'rgd'])"
]
},
{
"cell_type": "code",
"execution_count": 47,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Disabled constraints: plflb, plfub, rgu, rgd\n",
"Finalizing OModel for \n",
" initialized in 0.0380 seconds.\n"
]
},
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 47,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"spc.RTED.init(force=True)"
]
},
{
"cell_type": "code",
"execution_count": 48,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"OrderedDict([('pb', Constraint: pb [ON]),\n",
" ('sba', Constraint: sbus [ON]),\n",
" ('pglb', Constraint: pglb [ON]),\n",
" ('pgub', Constraint: pgub [ON]),\n",
" ('plflb', Constraint: plflb [OFF]),\n",
" ('plfub', Constraint: plfub [OFF]),\n",
" ('alflb', Constraint: alflb [ON]),\n",
" ('alfub', Constraint: alfub [ON]),\n",
" ('rbu', Constraint: rbu [ON]),\n",
" ('rbd', Constraint: rbd [ON]),\n",
" ('rru', Constraint: rru [ON]),\n",
" ('rrd', Constraint: rrd [ON]),\n",
" ('rgu', Constraint: rgu [OFF]),\n",
" ('rgd', Constraint: rgd [OFF])])"
]
},
"execution_count": 48,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"spc.RTED.constrs"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Alter Config"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Routines have an ``config`` attribute as configuration settings."
]
},
{
"cell_type": "code",
"execution_count": 49,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Working directory: \"/Users/jinningwang/work/ams/examples\"\n",
"Parsing input file \"/Users/jinningwang/work/miniconda3/envs/amsre/lib/python3.12/site-packages/ams/cases/5bus/pjm5bus_uced.xlsx\"...\n",
"Input file parsed in 0.0226 seconds.\n",
"Zero line rates detacted in rate_b, rate_c, adjusted to 999.\n",
"System set up in 0.0018 seconds.\n"
]
}
],
"source": [
"spf = ams.load(ams.get_case('5bus/pjm5bus_uced.xlsx'),\n",
" setup=True,\n",
" no_output=True,)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In RTED, the default interval is 5/60 [hour], and the formulations has been adjusted to fit the interval."
]
},
{
"cell_type": "code",
"execution_count": 50,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"OrderedDict({'t': 0.08333333333333333})"
]
},
"execution_count": 50,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"spf.RTED.config"
]
},
{
"cell_type": "code",
"execution_count": 51,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Building system matrices\n",
"Parsing OModel for \n",
"Evaluating OModel for \n",
"Finalizing OModel for \n",
" initialized in 0.0096 seconds.\n",
" solved as optimal in 0.0103 seconds, converged in 10 iterations with CLARABEL.\n"
]
},
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 51,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"spf.RTED.run(solver='CLARABEL')"
]
},
{
"cell_type": "code",
"execution_count": 52,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.19537500002212937"
]
},
"execution_count": 52,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"spf.RTED.obj.v"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can update the interval to 1 [hour] and re-solve the dispatch.\n",
"\n",
"Note that in this senario, compared to DCOPF, RTED has extra costs for ``pru`` and ``prd``."
]
},
{
"cell_type": "code",
"execution_count": 53,
"metadata": {},
"outputs": [],
"source": [
"spf.RTED.config.t = 60/60"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Remember to update the parameters after the change."
]
},
{
"cell_type": "code",
"execution_count": 54,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Building system matrices\n",
" reinit OModel due to non-parametric change.\n",
"Evaluating OModel for \n",
"Finalizing OModel for \n"
]
},
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 54,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"spf.RTED.update()"
]
},
{
"cell_type": "code",
"execution_count": 55,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
" solved as optimal in 0.0103 seconds, converged in 325 iterations with SCS.\n"
]
},
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 55,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"spf.RTED.run(solver='SCS')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can then get the objective value."
]
},
{
"cell_type": "code",
"execution_count": 56,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2.3445000011377894"
]
},
"execution_count": 56,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"spf.RTED.obj.v"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Note that in this build-in case, the ``cru`` and ``crd`` are defined as zero."
]
},
{
"cell_type": "code",
"execution_count": 57,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([0., 0., 0., 0.])"
]
},
"execution_count": 57,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"spf.RTED.cru.v"
]
},
{
"cell_type": "code",
"execution_count": 58,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([0., 0., 0., 0.])"
]
},
"execution_count": 58,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"spf.RTED.crd.v"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"As benchmark, we can solve the DCOPF."
]
},
{
"cell_type": "code",
"execution_count": 59,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Parsing OModel for \n",
"Evaluating OModel for \n",
"Finalizing OModel for \n",
" initialized in 0.0050 seconds.\n",
" solved as optimal in 0.0061 seconds, converged in 225 iterations with SCS.\n"
]
},
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 59,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"spf.DCOPF.run(solver='SCS')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"As expected, the DCOPF has a similar objective value."
]
},
{
"cell_type": "code",
"execution_count": 60,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2.344500000003334"
]
},
"execution_count": 60,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"spf.DCOPF.obj.v"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "amsre",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.0"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}