-
Notifications
You must be signed in to change notification settings - Fork 634
Fix warnings about unused variables in circuit_parser_qsim.cc #838
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
Fix warnings about unused variables in circuit_parser_qsim.cc #838
Conversation
This file produces many warnings of the form
```
tensorflow_quantum/core/src/circuit_parser_qsim.cc:185:8:
warning: variable 'unused' set but not used [-Wunused-but-set-variable]
185 | bool unused = absl::SimpleAtoi(op.qubits(0).id(), &q0);
| ^
```
Inspecting the code reveals that variable `unused` is indeed set but
never used. I replaced the code with simple testing of the return
values, similar to what is used in one place in the file, and in a way
that follows the recommendations from the Abseil docs.
MichaelBroughton
left a comment
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.
Thanks for the PR. Looking at
| tensorflow::Status ResolveQubitIds( |
I remember our process for getting to qsim circuits is this:
- Replace Grid/Line Qubit representations in the circuit and paulisum protos with integer indices that all line up and are well ordered across the batch.
- Forward this partially processed proto here to unpack into qsim circuit structs.
- Actually simulate the circuit placing results back into tensors in the right order.
So whenever I call into any of these gate constructors it is a requirement that all the proto messages contain integers. I might be more inclined to use assertions (or nothing at all and just (void) it out) here.
Oh, I understand now: due to the other steps around these calls to SimpleAtoi, the calls will always get valid values, therefore the returns don't need to be tested. I lean towards using void for these cases, mainly due to having had the principle of "assert is for test code, not production code" drilled into me for too long … |
MichaelBroughton
left a comment
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.
LGTM
This file produces many warnings of the form
Inspecting the code reveals that variable
unusedis indeed set but never used. This construct was used in many places in this file, and always involvingSimpleAtoi.I replaced the code with a simple alternative that tests the returned value from
SimpleAtoi, in a way that mirrors what was already done in one place in the file whereunusedwas not used. This approach follows the recommendations from the Abseil docs, too.Since this change means that new exceptions may be returned if the status from
SimpleAtoiis not okay, it also needed the addition of test cases incircuit_parser_qsim_test.cc.A final change is to fix a couple of warnings involving int versus unsignned int.