Skip to content

Logging message enhancement#606

Closed
jinningwang wants to merge 25 commits intoCURENT:developfrom
jinningwang:enhance
Closed

Logging message enhancement#606
jinningwang wants to merge 25 commits intoCURENT:developfrom
jinningwang:enhance

Conversation

@jinningwang
Copy link
Copy Markdown
Contributor

@jinningwang jinningwang commented Apr 28, 2025

  • Skip InitChecker logging and limiter adjust for offline devices.
  • When reading files, issue a warning only once per model for the following cases: 1) a NumParam value
    does not meet the expected criteria, or 2) unused data is detected.

@jinningwang jinningwang requested a review from Copilot April 28, 2025 15:39
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@jinningwang jinningwang requested a review from Copilot April 28, 2025 16:01
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request enhances logging behavior by skipping warnings for offline devices during initialization checks and ensuring that warning messages for NumParam corrections are issued only once.

  • New test cases for online/offline behavior in the initialization checker are added.
  • Logging in parameter adjustments now issues warnings at most once.
  • Device online status is integrated into condition checks for flag updates and adjustments.

Reviewed Changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/test_services.py Added tests to verify warning behavior for online and offline devices.
tests/test_numparam.py Introduced tests asserting a single warning issuance for parameter checks.
andes/core/service.py Modified condition checking to work only on online devices.
andes/core/param.py Updated logging messages to include a note that the warning is one-time.
andes/core/discrete.py Adjusted the lower/upper adjustment logic to account for device status.
Files not reviewed (1)
  • docs/source/release-notes.rst: Language not supported
Comments suppressed due to low confidence (1)

tests/test_numparam.py:16

  • [nitpick] The test assertion depends on the exact log message text; since the warning now includes additional wording, consider using a regex or substring match that accommodates possible variations in the log output.
        assert caplog.text.count("Non-zero parameter Line.x corrected to 1e-08.") == 1

Comment thread andes/core/service.py Outdated
Comment thread andes/core/discrete.py
@jinningwang jinningwang linked an issue Apr 29, 2025 that may be closed by this pull request
2 tasks
@cuihantao
Copy link
Copy Markdown
Collaborator

cuihantao commented May 2, 2025

I'm not sure why it's better to show the warning message only once for nonconforming inputs.

In the input stage, when we add one device, GEN 1 with inertia H = 0, for example, this should trigger one message so that the user will be able to identify and fix it.

When the second device GEN 2 with H = 0 is added, shouldn't this message be displayed again?

@cuihantao
Copy link
Copy Markdown
Collaborator

A useful enhancement would be to show which device violated the property constraint. I didn't do it, because in order to do it, one parameter needs to access its owner and then access the idx field, which looked messy to me. Maybe we can revisit it.

@jinningwang
Copy link
Copy Markdown
Contributor Author

I add a notebook to explain this, https://github.com/CURENT/demo/blob/master/demo/logging/logging.ipynb:

  • Property violation and auto correction is triggered ONLY in file loading stage, for PSS/E and JSON files.
  • Property violation and auto correction is not triggered for XLSX file.

It seems that when add a model manually after file loading, the property violation is not triggered.

Indeed this is a very marginal feature, but I can handle this if helpful "which device violated the property constraint"

@cuihantao
Copy link
Copy Markdown
Collaborator

cuihantao commented May 2, 2025 via email

@jinningwang
Copy link
Copy Markdown
Contributor Author

Thank you for your comment. I agree with your opinion and plan to implement the following enhancements:

  1. Individual Check by Default: This will perform a check on a single device input by default. When reading from a file, this will be turned off, and a model-level check will be conducted instead. Additionally, when users add new devices one by one, this check should be triggered automatically when calling NumParam.add
  2. Model-Level Check: This will perform a check on all devices within a model, identifying which devices have violations and providing the idxes. This one should be triggered automatically after adding all devices from case file.

Change 1 involves System.add, ModelData.add, and NumParam.add

Change 2 involves the three file parsing modules.

Let me know if I miss anything.

@cuihantao
Copy link
Copy Markdown
Collaborator

cuihantao commented May 11, 2025

When reading from a file, this will be turned off, and a model-level check will be conducted instead

Turning off the warning is not a great idea because some warnings are due to user omissions that need attention. The proposed change falls under the category of "fail silently" and is generally advised against. If the goal is to make the program less verbose, we can store all the warning messages somewhere and output a message at the end like this:

```There are warnings during the data parsing. To see all the warnings, do system.show_warnings()

(you can decide where to place the function.)

In that output, then provide more information regarding which parameter of which device trigger the warning, and the exact reason. 

Let me know if this makes sense and if you'd like to proceed.

@jinningwang
Copy link
Copy Markdown
Contributor Author

Agree with you, but we might skip this feature for now.

@jinningwang
Copy link
Copy Markdown
Contributor Author

Now in this PR I only skip the InitChecker logging and limiter adjust for offline devices.

@cuihantao
Copy link
Copy Markdown
Collaborator

Tracking the status of this PR against the current master branch.

Already addressed

  • NumParam warning deduplication: Solved differently in 925297c. Instead of adding periods to per-device warnings, master accumulates violations into _param_corrections during add() and emits grouped warnings via report_corrections() at setup time. This is a better approach.
  • .readthedocs.yml duplicate setuptools removal: Already done in 034bf01.
  • Exciter common_params with syn: Already present on master.
  • RenGovernor common_params with ree: Already present on master.

Not yet addressed

  • InitChecker: skip logging for offline devices (andes/core/service.py InitChecker.check()): No ue/u filtering. All devices are still checked and reported regardless of online status.
  • Limiter adjust: skip offline devices (andes/core/discrete.py do_adjust_lower / do_adjust_upper): Still uses plain val < lower / val > upper masks without filtering by ue/u.
  • Group common_params additions still missing:
    • TurbineGov: missing syn
    • VoltComp: missing avr
    • PSS: missing avr
    • FreqMeasurement: missing bus
    • PhasorMeasurement: missing bus
    • PLL: missing bus
    • Motor: missing bus
    • RenPlant: missing ree
  • Tests: No test_init_checker_online or test_init_checker_offline tests exist.

I'm going to hold on for the common parameters for groups due to some planned overhaul. Also, the models should follow an interface for querying the status instead of assuming the names of the status field.

@cuihantao
Copy link
Copy Markdown
Collaborator

Update on "Not yet addressed" items

The following items from the tracking list have been addressed in 81a1da9:

Now addressed

  • InitChecker: skip logging for offline devicesInitChecker.check() now calls model.get_status() to filter offline devices from warnings. model.get_status(idx=None) returns the full ue.v array.
  • Limiter adjust: skip offline devicesdo_adjust_lower / do_adjust_upper now filter by get_status() before building violation masks.
  • Group common_params additions:
    • TurbineGov: added syn
    • VoltComp: added avr
    • PSS: added avr
    • FreqMeasurement: added bus
    • PhasorMeasurement: added bus
    • PLL: added bus
    • Motor: added bus
    • RenPlant: added ree
  • Tests — Added TestInitCheckerOffline (3 tests) and TestLimiterAdjustOffline (2 tests) in tests/test_discrete.py.

Additional fixes in the same commit

  • GainLimiter now exposes allow_adjust parameter (threaded to internal HardLimiter). Set allow_adjust=False on REGCA1.HVG since clamping at lower=0 is by design (v < Volim in steady state).
  • Fixed duplicate ss.setup() calls in tests/models/renewable/test_reecb1.py (andes.load() already calls setup by default).

@cuihantao cuihantao closed this Feb 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enhancement on logging message

3 participants