Skip to content

Add missing labels when returning TimeResponseData #892

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 5 commits into from
May 27, 2023

Conversation

joaoantoniocardoso
Copy link
Contributor

Fixes #891

Copy link
Member

@murrayrm murrayrm left a comment

Choose a reason for hiding this comment

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

Thanks for this nice contribution. I suggest using *_labels instead of *_index, which I think makes the code a bit more readable.

Comment on lines 1114 to 1115
output_labels=sys.output_index, input_labels=sys.input_index,
state_labels=sys.state_index,
Copy link
Member

Choose a reason for hiding this comment

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

This is OK, but it might be more clear to use sys.output_labels, etc.

Comment on lines 1379 to 1387
# Select only the given input and output, if any
input_index = sys.input_index if input is None else {k: 0 for k, v in sys.input_index.items() if v == input}
output_index = sys.output_index if output is None else {k: 0 for k, v in sys.output_index.items() if v == output}

Copy link
Member

Choose a reason for hiding this comment

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

Consider changing this to

    input_labels = sys.input_labels if input is None \
        else sys.input_labels[input]
    output_labels = sys.output_labels if output is None else \
        sys.output_labels[output]

which seems cleaner.

Comment on lines 1385 to 1388
output_labels=output_index, input_labels=input_index,
state_labels=sys.state_index,
Copy link
Member

Choose a reason for hiding this comment

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

        output_labels=output_labels, input_labels=input_labels,
        state_labels=sys.state_labels,

Comment on lines 1715 to 1723
# Select only the given output, if any
output_index = sys.output_index if output is None else {k: 0 for k, v in sys.output_index.items() if v == output}

Copy link
Member

Choose a reason for hiding this comment

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

As above.

Comment on lines 1721 to 1725
output_labels=output_index, input_labels=None,
state_labels=sys.state_index,
Copy link
Member

Choose a reason for hiding this comment

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

As above.

Comment on lines 1885 to 1896
# Select only the given input and output, if any
input_index = sys.input_index if input is None else {k: 0 for k, v in sys.input_index.items() if v == input}
output_index = sys.output_index if output is None else {k: 0 for k, v in sys.output_index.items() if v == output}

Copy link
Member

Choose a reason for hiding this comment

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

As above.

Comment on lines 1891 to 1897
output_labels=output_index, input_labels=input_index,
state_labels=sys.state_index,
Copy link
Member

Choose a reason for hiding this comment

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

As above.

@joaoantoniocardoso
Copy link
Contributor Author

Thanks for this nice contribution. I suggest using *_labels instead of *_index, which I think makes the code a bit more readable.

Thanks, it surely makes it more readable, but I was unsure of using *_labels because the input_output_response is using *_index and I'm not aware of the reasons behind it.. I was suspecting that *_labels might not guarantee the order, which *_index surely does. Are you sure it's okay to use *_labels?

@joaoantoniocardoso joaoantoniocardoso force-pushed the patch-2 branch 6 times, most recently from 7b8db61 to 4ed8491 Compare May 26, 2023 00:03
@joaoantoniocardoso
Copy link
Contributor Author

joaoantoniocardoso commented May 26, 2023

Hi @murrayrm, I did the changes regarding using _labels instead of _index, can you take a look again? Thanks!

Comment on lines 1361 to 1366
# Get labels for the inputs/outputs (prior to mimo -> simo conversion)
input_labels = sys.input_labels if input is None \
else [sys.input_labels[input]]
output_labels = sys.output_labels if output is None \
else [sys.output_labels[output]]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was thinking about it. Should we move it to here, or should we make the mimo/siso/simo conversions to also propagate the labels (and name)?

Copy link
Member

Choose a reason for hiding this comment

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

Either way works, but because _get_ss_simo is an internal function, it is fine for it to ignore labels.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

take a look at this commit

Copy link
Member

@murrayrm murrayrm May 27, 2023

Choose a reason for hiding this comment

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

It's your PR, so feel free to revert the code moves that I made and put in your proposed commit. I was just trying to get something that passed the unit tests, since they were failing.

Copy link
Member

Choose a reason for hiding this comment

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

Also: I think it should work to do sys.output_labels[output] instead of [sys.output_labels[output]] (eg, remove the outer list). The code underneath is smart enough to deal with getting passed a string for a single input/output.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also: I think it should work to do sys.output_labels[output] instead of [sys.output_labels[output]] (eg, remove the outer list). The code underneath is smart enough to deal with getting passed a string for a single input/output.

The _process_labels had a small bug, now it works with plain str instead of [str]

@joaoantoniocardoso
Copy link
Contributor Author

@murrayrm I'm good with the patch, let me know if you need any changes, otherwise feel free to merge it

@murrayrm murrayrm merged commit 147d531 into python-control:main May 27, 2023
@murrayrm murrayrm added this to the 0.9.4 milestone Jun 7, 2023
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.

Missing labels from forced_response output
2 participants