Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions tests/UnitTests/PhasorDynamics/BranchTests.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,17 +303,15 @@ namespace GridKit
// Verifies invalid branch parameters are rejected.
TestStatus success = true;

Log::setVerbosity(Log::Verbosity::EVERYTHING);
Log::misc() << "Testing that invalid branch parameters are rejected. "
<< "Logged errors are expected.\n";
Log::setVerbosity(Log::Verbosity::WARNINGS);

PhasorDynamics::Bus<ScalarT, IdxT> bus1(1.0, 0.0);
PhasorDynamics::Bus<ScalarT, IdxT> bus2(1.0, 0.0);

PhasorDynamics::Branch<ScalarT, IdxT> valid_branch(&bus1, &bus2, 0.0, 0.1, 0.0, 0.0);
success *= (valid_branch.verify() == 0);

const auto previous_verbosity = Log::verbosity();
Log::setVerbosity(Log::Verbosity::NONE);

PhasorDynamics::Branch<ScalarT, IdxT> zero_impedance_branch(&bus1, &bus2, 0.0, 0.0, 0.0, 0.0);
success *= (zero_impedance_branch.verify() != 0);

Expand All @@ -327,6 +325,7 @@ namespace GridKit
PhasorDynamics::Branch<ScalarT, IdxT> nonfinite_branch(&bus1, &bus2, nan, 0.1, 0.0, 0.0);
success *= (nonfinite_branch.verify() != 0);

Log::setVerbosity(previous_verbosity);
return success.report(__func__);
}

Expand Down
25 changes: 25 additions & 0 deletions tests/UnitTests/PhasorDynamics/ControllerReecbTests.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@
#include <GridKit/Model/VariableMonitorController.hpp>
#include <GridKit/Testing/TestHelpers.hpp>
#include <GridKit/Testing/Testing.hpp>
#include <GridKit/Utilities/Logger/Logger.hpp>
#include <GridKit/Utilities/MapFromCsr.hpp>

namespace GridKit
{
namespace Testing
{
using Log = ::GridKit::Utilities::Logger;

template <typename scalar_type, typename index_type>
class ControllerReecbTests
{
Expand All @@ -45,6 +48,9 @@ namespace GridKit
{
TestStatus success = true;

const auto previous_verbosity = Log::verbosity();
Log::setVerbosity(Log::Verbosity::NONE);

PhasorDynamics::Bus<ScalarT, IdxT> bus(1.0, 0.0);

PhasorDynamics::Controller::Reecb<ScalarT, IdxT> empty(&bus);
Expand Down Expand Up @@ -263,6 +269,7 @@ namespace GridKit
{{Vars::PORD, 1.0}, {Vars::RPORD, 0.0}},
"floored active-power order rate");

Log::setVerbosity(previous_verbosity);
return success.report(__func__);
}

Expand Down Expand Up @@ -374,6 +381,9 @@ namespace GridKit
{
TestStatus success = true;

const auto previous_verbosity = Log::verbosity();
Log::setVerbosity(Log::Verbosity::NONE);

const auto data = makeData();

success *= initializationRejectedAtomically(data, 0.75, -0.1, "negative active-current command");
Expand Down Expand Up @@ -552,6 +562,7 @@ namespace GridKit
success *= vectorUnchanged(invalid_fixture.reecb.y(), invalid_y, "state");
success *= vectorUnchanged(invalid_fixture.reecb.yp(), invalid_yp, "derivative");

Log::setVerbosity(previous_verbosity);
return success.report(__func__);
}

Expand All @@ -561,6 +572,9 @@ namespace GridKit
{
TestStatus success = true;

const auto previous_verbosity = Log::verbosity();
Log::setVerbosity(Log::Verbosity::NONE);

struct ExactnessCase
{
RealT ipcmd;
Expand Down Expand Up @@ -750,6 +764,7 @@ namespace GridKit
success *= stateMatches(exhausted.reecb, {{Vars::ILMAX, 0.0}}, "injection does not expand current circle");
success *= allResidualsWithinInitTolerance(exhausted.reecb);

Log::setVerbosity(previous_verbosity);
return success.report(__func__);
}

Expand Down Expand Up @@ -816,6 +831,9 @@ namespace GridKit
{
TestStatus success = true;

const auto previous_verbosity = Log::verbosity();
Log::setVerbosity(Log::Verbosity::NONE);

const std::array<bool, 2> selector_values{{false, true}};
for (const bool pf : selector_values)
{
Expand Down Expand Up @@ -904,6 +922,7 @@ namespace GridKit
}
}

Log::setVerbosity(previous_verbosity);
return success.report(__func__);
}

Expand Down Expand Up @@ -1616,10 +1635,16 @@ namespace GridKit
data.parameters[Params::QFlag] = mode.q_flag;
data.parameters[Params::Pqflag] = mode.p_priority;

const auto previous_verbosity = Log::verbosity();
if (mode.pf_flag && mode.q_flag)
{
Log::setVerbosity(Log::Verbosity::NONE);
}
success *= jacobiansMatch(
dependencyTrackingJacobian(data, kNonunitAlpha, success),
enzymeJacobian(data, kNonunitAlpha, success),
mode.label);
Log::setVerbosity(previous_verbosity);
}

struct CurrentCircleProbe
Expand Down
25 changes: 10 additions & 15 deletions tests/UnitTests/PhasorDynamics/ControllerRepcaTests.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ namespace GridKit
{
TestStatus success = true;

noteExpectedLogs("Testing REPCA defaults, parameter floors, and invalid "
"configurations. Logged errors and warnings are expected.");
const auto previous_verbosity = Log::verbosity();
// Use EVERYTHING to inspect diagnostics from the invalid cases below.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Use EVERYTHING to inspect diagnostics from the invalid cases below.
// Changing the verbosity to NONE to suppress expected errors and warning for the following tests.
// Use EVERYTHING to inspect diagnostics from the invalid cases below.

I like having a comment here. I recommend adding something to this effect to other instances.

Log::setVerbosity(Log::Verbosity::NONE);

PhasorDynamics::Bus<ScalarT, IdxT> bus(1.0, 0.0);

Expand Down Expand Up @@ -237,6 +238,7 @@ namespace GridKit
floored_residuals,
"floored time constants");

Log::setVerbosity(previous_verbosity);
return success.report(__func__);
}

Expand All @@ -245,9 +247,6 @@ namespace GridKit
{
TestStatus success = true;

noteExpectedLogs("Testing REPCA initialization without an attached frequency "
"signal. A warning is expected.");

Fixture<ScalarT> fixture(makeInitializationData(), 0.8, 0.6);
fixture.attachAllInputs(99.0);
setInitializationInputs(fixture);
Expand Down Expand Up @@ -346,7 +345,10 @@ namespace GridKit
Fixture<ScalarT> fallback(makeInitializationData(), 0.8, 0.6);
fallback.attachAllInputs(0.0, false);
setInitializationInputs(fallback);
const auto previous_verbosity = Log::verbosity();
Log::setVerbosity(Log::Verbosity::NONE);
success *= fallback.initialize(0.25, 0.45);
Log::setVerbosity(previous_verbosity);
success *= scalarMatches(fallback.input(Ext::FREQREF), 1.0, "default frequency");
success *= (fallback.repca.evaluateResidual() == 0);
success *= allResidualsWithinInitTolerance(fallback.repca);
Expand Down Expand Up @@ -429,8 +431,8 @@ namespace GridKit
{
TestStatus success = true;

noteExpectedLogs("Testing REPCA adjusted limits and inadmissible "
"initialization points. Logged warnings and errors are expected.");
const auto previous_verbosity = Log::verbosity();
Log::setVerbosity(Log::Verbosity::NONE);

const auto data = makeInitializationData();

Expand Down Expand Up @@ -769,6 +771,7 @@ namespace GridKit
"adjusted command limits");
}

Log::setVerbosity(previous_verbosity);
return success.report(__func__);
}

Expand Down Expand Up @@ -2149,14 +2152,6 @@ namespace GridKit
return success;
}

void noteExpectedLogs(const char* message) const
{
const auto previous_verbosity = Log::verbosity();
Log::setVerbosity(Log::Verbosity::EVERYTHING);
Log::misc() << message << '\n';
Log::setVerbosity(previous_verbosity);
}

std::vector<DependencyTracking::Variable::DependencyMap> expectedJacobian() const
{
return {
Expand Down
21 changes: 6 additions & 15 deletions tests/UnitTests/PhasorDynamics/ConverterRegcaTests.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ namespace GridKit
success *= (configured.getMonitor() != nullptr);
success *= (configured.verify() == 0);

noteExpectedLogs("Testing invalid REGCA configurations. "
"Logged errors and time-constant warnings are expected.");
const auto previous_verbosity = Log::verbosity();
Log::setVerbosity(Log::Verbosity::NONE);
success *= (minimal.verify() > 0);

for (const Params parameter : {Params::Tg, Params::p0, Params::q0})
Expand Down Expand Up @@ -102,6 +102,7 @@ namespace GridKit
success *= (fixture.evaluate() == 0);
success *= allResidualsZero(fixture.regca);

Log::setVerbosity(previous_verbosity);
return success.report(__func__);
}

Expand Down Expand Up @@ -191,8 +192,8 @@ namespace GridKit
{
TestStatus success = true;

noteExpectedLogs("Testing inadmissible REGCA initialization points. "
"Logged errors are expected.");
const auto previous_verbosity = Log::verbosity();
Log::setVerbosity(Log::Verbosity::NONE);

struct RejectionCase
{
Expand Down Expand Up @@ -334,6 +335,7 @@ namespace GridKit
"IP with LVPL bypassed");
}

Log::setVerbosity(previous_verbosity);
return success.report(__func__);
}

Expand Down Expand Up @@ -1010,17 +1012,6 @@ namespace GridKit
return false;
}

/// Raises verbosity just long enough to flag intentionally provoked
/// logs, so expected errors in the output are not mistaken for
/// failures.
void noteExpectedLogs(const char* message) const
{
const auto previous_verbosity = Log::verbosity();
Log::setVerbosity(Log::Verbosity::EVERYTHING);
Log::misc() << message << "\n";
Log::setVerbosity(previous_verbosity);
}

#ifdef GRIDKIT_ENABLE_ENZYME
/// Move the answer-key state to the HVRCM and active-current limiter
/// transition points, where the Jacobian has the richest structure.
Expand Down
18 changes: 6 additions & 12 deletions tests/UnitTests/PhasorDynamics/ExciterEsdc1aTests.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ namespace GridKit
{
TestStatus success = true;

noteExpectedLogs("Testing ESDC1A defaults and invalid configurations. "
"Logged errors and time-constant warnings are expected.");
const auto previous_verbosity = Log::verbosity();
Log::setVerbosity(Log::Verbosity::NONE);

PhasorDynamics::Bus<ScalarT, IdxT> bus(1.0, 0.0);

Expand Down Expand Up @@ -189,6 +189,7 @@ namespace GridKit
success *= (floored.evaluate() == 0);
success *= allResidualsZero(floored.esdc1a);

Log::setVerbosity(previous_verbosity);
return success.report(__func__);
}

Expand Down Expand Up @@ -320,8 +321,8 @@ namespace GridKit
{
TestStatus success = true;

noteExpectedLogs("Testing inadmissible ESDC1A initialization points. "
"Logged errors are expected.");
const auto previous_verbosity = Log::verbosity();
Log::setVerbosity(Log::Verbosity::NONE);

// An enabled speed multiplier must remain finite and strictly
// positive. Other initialization limits are relaxed so these cases
Expand Down Expand Up @@ -491,6 +492,7 @@ namespace GridKit
success *= (junction.evaluate() == 0);
success *= allResidualsZero(junction.esdc1a);

Log::setVerbosity(previous_verbosity);
return success.report(__func__);
}

Expand Down Expand Up @@ -1432,14 +1434,6 @@ namespace GridKit
return false;
}

void noteExpectedLogs(const char* message) const
{
const auto previous_verbosity = Log::verbosity();
Log::setVerbosity(Log::Verbosity::EVERYTHING);
Log::misc() << message << "\n";
Log::setVerbosity(previous_verbosity);
}

void numberVariables(Fixture<DependencyTracking::Variable>& fixture) const
{
auto* y = fixture.esdc1a.y().getData();
Expand Down
7 changes: 3 additions & 4 deletions tests/UnitTests/PhasorDynamics/ExciterIeeet1Tests.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,8 @@ namespace GridKit
{
TestStatus success = true;

Log::setVerbosity(Log::Verbosity::EVERYTHING);
Log::misc() << "Testing that invalid saturation parameters are rejected. "
<< "Logged errors are expected.\n";
Log::setVerbosity(Log::Verbosity::WARNINGS);
const auto previous_verbosity = Log::verbosity();
Log::setVerbosity(Log::Verbosity::NONE);

using Params = PhasorDynamics::Exciter::Ieeet1Parameters;

Expand All @@ -200,6 +198,7 @@ namespace GridKit

success *= (exciter.verify() != 0);

Log::setVerbosity(previous_verbosity);
return success.report(__func__);
}

Expand Down
14 changes: 6 additions & 8 deletions tests/UnitTests/PhasorDynamics/ExciterSexsPtiTests.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,8 @@ namespace GridKit

TestStatus success = true;

Log::setVerbosity(Log::Verbosity::EVERYTHING);
Log::misc() << "Testing that invalid parameters are rejected. "
<< "Logged errors are expected.\n";
Log::setVerbosity(Log::Verbosity::WARNINGS);
const auto previous_verbosity = Log::verbosity();
Log::setVerbosity(Log::Verbosity::NONE);

PhasorDynamics::Bus<ScalarT, IdxT> bus(1.0, 0.0);

Expand All @@ -225,6 +223,7 @@ namespace GridKit
PhasorDynamics::Exciter::SexsPti<ScalarT, IdxT> invalid_model(&bus, invalid);
success *= (invalid_model.verify() > 0);

Log::setVerbosity(previous_verbosity);
return success.report(__func__);
}

Expand Down Expand Up @@ -260,14 +259,13 @@ namespace GridKit
success *= (system.evaluateResidual() == 0);
success *= (system.size() == 5);

Log::setVerbosity(Log::Verbosity::EVERYTHING);
Log::misc() << "Testing that model with missing EFD data is rejected. "
<< "Logged errors are expected.\n";
Log::setVerbosity(Log::Verbosity::WARNINGS);
auto missing_efd = data;
missing_efd.sexspti[0].signal_outputs.erase(SignalOutput::efd);
SystemModel<ScalarT, IdxT> missing_efd_system(missing_efd);
const auto previous_verbosity = Log::verbosity();
Log::setVerbosity(Log::Verbosity::NONE);
success *= (missing_efd_system.verify() > 0);
Log::setVerbosity(previous_verbosity);

return success.report(__func__);
}
Expand Down
Loading
Loading