Skip to content

Add binary literal example to methods of SimulatesAmplitudes class#5818

Merged
viathor merged 6 commits intoquantumlib:masterfrom
Caffetaria:new
Aug 10, 2022
Merged

Add binary literal example to methods of SimulatesAmplitudes class#5818
viathor merged 6 commits intoquantumlib:masterfrom
Caffetaria:new

Conversation

@Caffetaria
Copy link
Copy Markdown
Contributor

@Caffetaria Caffetaria commented Aug 6, 2022

Resolves #2603

@Caffetaria Caffetaria requested review from a team, cduck and vtomole as code owners August 6, 2022 13:55
@Caffetaria Caffetaria requested a review from pavoljuhas August 6, 2022 13:55
@Caffetaria Caffetaria changed the title Add binary literal example to methods of SimulatesAmplitudes class (#2603) Add binary literal example to methods of SimulatesAmplitudes class Aug 6, 2022
Copy link
Copy Markdown
Collaborator

@viathor viathor left a comment

Choose a reason for hiding this comment

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

The added comments document python, not cirq, so I think they are gratuitous. What's the reason for this PR?

Comment thread cirq-core/cirq/sim/simulator.py Outdated
qubit values according to `qubit_order` from most to least
significant qubit, i.e. in big-endian ordering.
Binary literals should be input with the prefix 0b or 0B.
For example, 0010 should be input as 0b0010 or 0B0010.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

As indicated by the function signature, the bitstrings are supposed to be good old python ints. All valid ways of writing int literals will work, not just 0b-prefixed binary literals.

@Caffetaria
Copy link
Copy Markdown
Contributor Author

@viathor I made the changes to address #2603 (python3 does not allow leading zeroes for ints). Please let me know if I'm missing or misunderstanding something :)

Copy link
Copy Markdown
Collaborator

@viathor viathor left a comment

Choose a reason for hiding this comment

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

I see. Thank you for the context. I suggest the following changes before we merge this:

  • reword the comments to make it clear that these are mere examples and not the only supported way of specifying bitstrings,
  • add a non-binary example, e.g. 32641, 0x7F81,
  • fix the formatting errors.

@Caffetaria
Copy link
Copy Markdown
Contributor Author

I see. Thank you for the context. I suggest the following changes before we merge this:

  • reword the comments to make it clear that these are mere examples and not the only supported way of specifying bitstrings,
  • add a non-binary example, e.g. 32641, 0x7F81,
  • fix the formatting errors.

@viathor Thanks for the feedback! I've made the changes. Hope this is fine?

Copy link
Copy Markdown
Collaborator

@viathor viathor left a comment

Choose a reason for hiding this comment

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

Nearly there!

Comment thread cirq-core/cirq/sim/simulator.py Outdated
qubit values according to `qubit_order` from most to least
significant qubit, i.e. in big-endian ordering.
If inputting a binary literal add the prefix 0b or 0B.
For example: 0010 can be input as 0b0010, 0B0010, 2, 0x2, etc.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This needs to be indented by four spaces to align with the line above. Also, you can put "If inputting" on line 159 above that.

(Applies to the comment on lines 221-222 as well.)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@viathor Made these changes in the latest commit :)

Copy link
Copy Markdown
Collaborator

@viathor viathor Aug 9, 2022

Choose a reason for hiding this comment

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

I only meant a part of the "if inputting" line since there is an overall line length limit (and in any case we should stick to the rough right text boundary of the surrounding text). I'm approving this PR, but note that you will need to take care of this before the merge since at the moment the line-too-long issue makes the formatter and linter checks go red.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks! The last two recent commits resolve this (only 'if inputting' is on the previous line).

@CirqBot CirqBot added the Size: XS <10 lines changed label Aug 8, 2022
@viathor viathor merged commit c25d74f into quantumlib:master Aug 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Size: XS <10 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add binary literal example to compute_amplitudes_sweep and compute_amplitudes methods of SimulatesAmplitudes class.

3 participants