# Created: 2026-06-05
# (c) Copyright 2025 ETH Zurich
#
# Licensed under the GNU General Public License v3.0;
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
#
# https://www.gnu.org/licenses/gpl-3.0.en.html
#
# This software is distributed "AS IS", WITHOUT WARRANTY OF ANY KIND,
# express or implied. See the License for specific language governing
# permissions and limitations under the License.
"""Byte-identical SIM baseline gates for the inverter models (Phase 0).
Exercise GridForming + GridFollowing (+ SGs) through the t=4.0 bus fault and
compare the full state trajectory against the pickled references at atol=1e-6,
for both network realizations:
- ``test_sim_line_dyn``: ``line_dyn=True`` (ODE, cvodes) -- the primary gate.
- ``test_sim_alg``: ``line_dyn=False`` (algebraic network / DAE, idas) -- the
distinct path the future LCL_static realization will exercise.
Any change to inverter state count, ordering, or numerics fails these instantly --
the gates every behavior-preserving step of the inverter refactor
(docs/inverter_modernization_design.md) must keep green.
"""
import pickle
import numpy as np
from pydynamicestimator.tests.baselines.inverter_baseline import (
BASELINES,
run_inverter_case,
)
[docs]
def _assert_matches(case: str, atol: float) -> None:
with open(BASELINES[case], "rb") as file:
base = pickle.load(file)
arr = run_inverter_case(case)
assert np.allclose(
arr, base, atol=atol
), f"The inverter '{case}' trajectory did not match the byte-identical baseline"
[docs]
def test_sim_line_dyn():
_assert_matches("sim_ld", atol=1e-6)
[docs]
def test_sim_alg():
_assert_matches("sim_alg", atol=1e-6)