-
Notifications
You must be signed in to change notification settings - Fork 440
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
Turn off warn_infinite for phase_crossover_frequencies() calculation #1106
Conversation
There was a problem hiding this 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.
control/tests/margin_test.py
Outdated
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 |
There was a problem hiding this comment.
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
orfrom 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 thecontrol
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]), |
There was a problem hiding this comment.
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.
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
).