GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix timebase bug in InterconnectedSystem (issue #754) by murrayrm · Pull Request #755 · python-control/python-control

Fix timebase bug in InterconnectedSystem (issue #754) #755

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.

Sign up for GitHub

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
bnavigator merged 3 commits into python-control:main from murrayrm:timebase_bug-03Aug2022
Aug 6, 2022

Uh oh!

There was an error while loading. Please reload this page.

Merged

Fix timebase bug in InterconnectedSystem (issue #754) #755

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
3 commits
Select commit Hold shift + click to select a range
f17c919
fix timebase bug in InterconnectedSystem (issue #754)
murrayrm Aug 4, 2022
3c13f2c
add additional checks for overriding timebase
murrayrm Aug 4, 2022
cf30479
added tests for dt=True case per @sawyerbfuller suggestion
murrayrm Aug 4, 2022
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

7 changes: 5 additions & 2 deletions 7 control/iosys.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -871,9 +871,12 @@ def __init__(self, syslist, connections=[], inplist=[], outlist=[],
if not isinstance(outlist, (list, tuple)):
outlist = [outlist]

# Process keyword arguments
# Check if dt argument was given; if not, pull from systems
dt = kwargs.pop('dt', None)

# Process keyword arguments (except dt)
defaults = {'inputs': len(inplist), 'outputs': len(outlist)}
name, inputs, outputs, states, dt = _process_namedio_keywords(
name, inputs, outputs, states, _ = _process_namedio_keywords(
kwargs, defaults, end=True)

# Initialize the system list and index
Expand Down
69 changes: 69 additions & 0 deletions 69 control/tests/timebase_test.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import pytest
import inspect
import numpy as np
import control as ct

@pytest.mark.parametrize(
"dt1, dt2, dt3", [
(0, 0, 0),
(0, 0.1, ValueError),
(0, None, 0),
(0, True, ValueError),
(0.1, 0, ValueError),
(0.1, 0.1, 0.1),
(0.1, None, 0.1),
(0.1, True, 0.1),
(None, 0, 0),
(None, 0.1, 0.1),
(None, None, None),
(None, True, True),
(True, 0, ValueError),
(True, 0.1, 0.1),
(True, None, True),
(True, True, True),
(0.2, None, 0.2),
(0.2, 0.1, ValueError),
Comment thread

@sawyerbfuller sawyerbfuller Aug 4, 2022

Copy link
Copy Markdown
Contributor

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.

Great PR. Would be good to add tests for dt=True, which are compatible with all other discrete-time timebases. https://python-control.readthedocs.io/en/0.9.2/conventions.html

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@murrayrm murrayrm Aug 4, 2022

Copy link
Copy Markdown
Member Author

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.

Great suggestion. Done.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
])
@pytest.mark.parametrize("op", [ct.series, ct.parallel, ct.feedback])
@pytest.mark.parametrize("type", [ct.StateSpace, ct.ss, ct.tf])
def test_composition(dt1, dt2, dt3, op, type):
# Define the system
A, B, C, D = [[1, 1], [0, 1]], [[0], [1]], [[1, 0]], 0
sys1 = ct.StateSpace(A, B, C, D, dt1)
sys2 = ct.StateSpace(A, B, C, D, dt2)

# Convert to the desired form
sys1 = type(sys1)
sys2 = type(sys2)

if inspect.isclass(dt3) and issubclass(dt3, Exception):
with pytest.raises(dt3, match="incompatible timebases"):
sys3 = op(sys1, sys2)
else:
sys3 = op(sys1, sys2)
assert sys3.dt == dt3


@pytest.mark.parametrize("dt", [None, 0, 0.1])
def test_composition_override(dt):
# Define the system
A, B, C, D = [[1, 1], [0, 1]], [[0], [1]], [[1, 0]], 0
sys1 = ct.ss(A, B, C, D, None, inputs='u1', outputs='y1')
sys2 = ct.ss(A, B, C, D, None, inputs='y1', outputs='y2')

# Show that we can override the type
sys3 = ct.interconnect([sys1, sys2], inputs='u1', outputs='y2', dt=dt)
assert sys3.dt == dt

# Overriding the type with an inconsistent type generates an error
sys1 = ct.StateSpace(A, B, C, D, 0.1, inputs='u1', outputs='y1')
if dt != 0.1 and dt is not None:
with pytest.raises(ValueError, match="incompatible timebases"):
sys3 = ct.interconnect(
[sys1, sys2], inputs='u1', outputs='y2', dt=dt)

sys1 = ct.StateSpace(A, B, C, D, 0, inputs='u1', outputs='y1')
if dt != 0 and dt is not None:
with pytest.raises(ValueError, match="incompatible timebases"):
sys3 = ct.interconnect(
[sys1, sys2], inputs='u1', outputs='y2', dt=dt)
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.