Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Turn off warn_infinite for phase_crossover_frequencies() calculation #1106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 30, 2025

Conversation

murrayrm
Copy link
Member

This PR addresses #1105 where warning messages were being generated if a system had poles at the origin (which generates a phase crossover at infinity). The fix was simple: warning messages should be turned off when computing the crossover gains (as they are in stability_margins).

@coveralls
Copy link

coveralls commented Jan 29, 2025

Coverage Status

coverage: 94.649% (+0.001%) from 94.648%
when pulling d9e44d2 on murrayrm:fix_phase_crossover-28Jan2025
into 71bd731 on python-control:main.

@slivingston slivingston self-requested a review January 29, 2025 05:06
Copy link
Member

@slivingston slivingston left a comment

Choose a reason for hiding this comment

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

Good work! Besides my comment about the regression test, this is ready to merge.

Comment on lines 15 to 19
from ..frdata import FrequencyResponseData
from ..margins import margin, phase_crossover_frequencies, stability_margins
from ..statesp import StateSpace
from ..xferfcn import TransferFunction
from ..exception import ControlMIMONotImplemented
Copy link
Member

Choose a reason for hiding this comment

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

Should we use relative imports in test files?

Arguments against relative imports in test files

  • Although the tests/ directory is a subpackage and therefore can use the relative import syntax, this change will prevent running tests from outside of the control package.
  • Users of control necessarily write absolute imports (import control or from control...). Tests of the public API should follow the patterns of users.

Arguments in favor

  • Relative import syntax is more concise.
  • I might have missed something, but none of the CI jobs run the tests against a copy of control other than where they are located. In other words, "running tests from outside of the control package" is not done in practice, so not important to support.
  • We are already using the relative import syntax in config_test.py.

For comparison, neither numpy nor scipy seem to be consistent: most of their tests are written using absolute imports (import numpy or import scipy etc.), but some tests use relative imports.

Conclusion

I like the generality in principle of keeping these as absolute imports, but practically both patterns seem good.

@@ -119,6 +118,8 @@ def test_margin_3input(tsys):
(([2], [1, 3, 3, 1]), [1.732, 0.], [-0.25, 2.]),
((np.array([3, 11, 3]) * 1e-4, [1., -2.7145, 2.4562, -0.7408], .1),
[1.6235, 0.], [-0.28598, 1.88889]),
(([200.0], [1.0, 21.0, 20.0, 0.0]),
[4.47213595, 0], [-0.47619048, inf]),
Copy link
Member

Choose a reason for hiding this comment

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

Warnings do not cause the test to fail, so this case does not provide a regression test. To fix this, add the decorator @pytest.mark.filterwarnings("error") as done in another test in margin_test.py.

@murrayrm murrayrm merged commit ebff125 into python-control:main Jan 30, 2025
23 checks passed
@murrayrm murrayrm added this to the 0.10.2 milestone Feb 19, 2025
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.

3 participants