Skip to content
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 str/repr explosion in separated states #4518

Merged
merged 16 commits into from
Dec 21, 2021

Conversation

daxfohl
Copy link
Contributor

@daxfohl daxfohl commented Sep 23, 2021

Fixes #4477 by outputting separated states individually rather than kronning them all together first.

@CirqBot CirqBot added the size: M 50< lines changed <250 label Sep 23, 2021
@google-cla google-cla bot added the cla: yes Makes googlebot stop complaining. label Sep 23, 2021
@daxfohl daxfohl marked this pull request as ready for review September 23, 2021 17:47
@daxfohl daxfohl requested review from cduck, vtomole and a team as code owners September 23, 2021 17:47
@daxfohl daxfohl requested a review from maffoo September 23, 2021 17:47
@95-martin-orion 95-martin-orion self-assigned this Sep 27, 2021
@95-martin-orion 95-martin-orion requested review from 95-martin-orion and removed request for maffoo September 27, 2021 20:29
cirq-core/cirq/sim/density_matrix_simulator_test.py Outdated Show resolved Hide resolved
cirq-core/cirq/sim/simulator_base.py Outdated Show resolved Hide resolved
cirq-core/cirq/sim/act_on_state_vector_args.py Outdated Show resolved Hide resolved
cirq-core/cirq/sim/state_vector_simulator_test.py Outdated Show resolved Hide resolved
@daxfohl
Copy link
Contributor Author

daxfohl commented Dec 17, 2021

@95-martin-orion FWIW I think before cirq 1.0 we should get rid of all the extra MySimulatorStepResult and MySimulatorTrialResult classes, and just yield/return TActOnArgs as the result (renamed to TSimulatorState). I don't see any value added by the various StepResult and TrialResult classes, but they add a bunch of unnecessary code obfuscation.

Obviously a big breaking change.....

Copy link
Collaborator

@95-martin-orion 95-martin-orion left a comment

Choose a reason for hiding this comment

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

Looks good to go. Let me know when you're ready to merge, in case there's any issues colliding with your other PRs in flight.

@95-martin-orion
Copy link
Collaborator

@95-martin-orion FWIW I think before cirq 1.0 we should get rid of all the extra MySimulatorStepResult and MySimulatorTrialResult classes, {...}

Could you open an issue and CC @MichaelBroughton on it? There's a laundry list of TODOs like this somewhere that he's been keeping track of.

@daxfohl
Copy link
Contributor Author

daxfohl commented Dec 20, 2021 via email

@95-martin-orion 95-martin-orion added the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Dec 20, 2021
@CirqBot CirqBot added the front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. label Dec 20, 2021
@CirqBot
Copy link
Collaborator

CirqBot commented Dec 20, 2021

Automerge cancelled: A status check is failing.

@CirqBot CirqBot removed automerge Tells CirqBot to sync and merge this PR. (If it's running.) front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. labels Dec 20, 2021
@95-martin-orion
Copy link
Collaborator

Looks like the rigetti/quilc install timed out. Will retry as soon as I figure out how to trigger it.

@95-martin-orion
Copy link
Collaborator

Looks like an ongoing Docker outage is breaking us: https://downdetector.com/status/docker/

We'll need to wait it out before merging.

@daxfohl
Copy link
Contributor Author

daxfohl commented Dec 21, 2021

Looks like it's up again

@95-martin-orion 95-martin-orion merged commit 1d27a00 into quantumlib:master Dec 21, 2021
@daxfohl daxfohl deleted the str_repr branch December 21, 2021 18:26
MichaelBroughton pushed a commit to MichaelBroughton/Cirq that referenced this pull request Jan 22, 2022
* Fix str/repr explosion in separated states

* format

* Fix str/repr explosion in state vector

* format

* nondirac_str

* TrialResultBase

* cleanup

* Add get_state_containing_qubit

* Ensure eval(repr(obj)) holds

* substates not a property

* fix test

* coverage

* test

* fix windows

Co-authored-by: Cirq Bot <craiggidney+github+cirqbot@google.com>
@verult
Copy link
Collaborator

verult commented Apr 28, 2022

Hi @daxfohl , I tried running the following:

>>> q = cirq.GridQubit(0,0)
>>> c = cirq.Circuit(cirq.H(q))
>>> sim = cirq.Simulator()
>>> r = sim.simulate(c)
>>> print(r)
measurements: (no measurements)

qubits: (cirq.GridQubit(0, 0),)
output vector: 0.707|0⟩ + 0.707|1⟩

phase:
output vector: |⟩

Is the phase output expected? I was surprised to see an output vector after "phase" but I might be misunderstanding something. Thanks!

@daxfohl
Copy link
Contributor Author

daxfohl commented Apr 29, 2022

There is a phase component. Try adding a global phase and see how it changes? I can't remember. Maybe there's a better way to output the phase.

@verult
Copy link
Collaborator

verult commented Apr 29, 2022

I appended a cirq.global_phase_operation(-1) and got this:

phase:
output vector: -1|⟩

Would it make sense to just have the phase in the output and remove the output vector part?

@daxfohl
Copy link
Contributor Author

daxfohl commented Apr 29, 2022

Yes that would probably make more sense :)

rht pushed a commit to rht/Cirq that referenced this pull request May 1, 2023
* Fix str/repr explosion in separated states

* format

* Fix str/repr explosion in state vector

* format

* nondirac_str

* TrialResultBase

* cleanup

* Add get_state_containing_qubit

* Ensure eval(repr(obj)) holds

* substates not a property

* fix test

* coverage

* test

* fix windows

Co-authored-by: Cirq Bot <craiggidney+github+cirqbot@google.com>
harry-phasecraft pushed a commit to PhaseCraft/Cirq that referenced this pull request Oct 31, 2024
* Fix str/repr explosion in separated states

* format

* Fix str/repr explosion in state vector

* format

* nondirac_str

* TrialResultBase

* cleanup

* Add get_state_containing_qubit

* Ensure eval(repr(obj)) holds

* substates not a property

* fix test

* coverage

* test

* fix windows

Co-authored-by: Cirq Bot <craiggidney+github+cirqbot@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Makes googlebot stop complaining. size: M 50< lines changed <250
Projects
None yet
Development

Successfully merging this pull request may close these issues.

str/repr blows up for large disjoint states
4 participants