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

Adding Qsim confusion matrix runtime exception #630

Conversation

angelo-laskaris
Copy link
Contributor

QSim currently does not support confusion matrices on measurement gates. See quantumlib/Cirq#6305 for more info. While work is done to support confusion matrices surfacing a runtime exception.

qsimcirq/qsim_simulator.py Outdated Show resolved Hide resolved
param_resolver = param_resolver or cirq.ParamResolver({})
solved_circuit = cirq.resolve_parameters(circuit, param_resolver)

return self._sample_measure_results(solved_circuit, repetitions)

def _check_for_confusion_matrix(self, circuit: cirq.Circuit):
Copy link
Collaborator

Choose a reason for hiding this comment

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

I recommend moving this to qsim_circuit.py and calling it in QSimCircuit.translate_cirq_to_qsim instead. Every Cirq circuit that gets converted to qsim must go through that method, so putting it there would save having to call it from every simulation method in this file.

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 moved the method to QSimCircuit and updated the unit test accordingly. However, I want to note the invocation pattern seen here: quantumlib/Cirq#6305 does not result in an exception being thrown.

Copy link
Collaborator

Choose a reason for hiding this comment

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

the invocation pattern seen here: quantumlib/Cirq#6305 does not result in an exception being thrown.

That's deeply surprising to me. Could you try adding the check in translate_cirq_to_qtrajectory as well?

def translate_cirq_to_qtrajectory(

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 added the check here as well and the ValueError still wasn't raised. Your surprise makes me want to make sure my environment doesn't have anything odd/wonky. Let me get a summary of my env (python version qsim ver, cirq ver) and follow up

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Python version: 3.9

cirq==1.2.0
qsimcirq==0.16.3

Copy link
Collaborator

Choose a reason for hiding this comment

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

How was this resolved?

Copy link
Contributor Author

@angelo-laskaris angelo-laskaris Nov 9, 2023

Choose a reason for hiding this comment

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

I confirmed that there was nothing wonky with my setup or library versions and that indeed in neither translate_cirq_to_qsim or translate_cirq_to_qtrajectory is a part of the call stack when the circuit is executed like so

qsimcirq.QSimSimulator(seed=0).run(circuit, repetitions=100)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ohhhhhh, I missed that you had moved the check into the constructor. LGTM.

(I'm still confused by the translate_* methods not being called, as these lines should call them, but it's no longer blocking this PR.)

qsimcirq/qsim_simulator.py Outdated Show resolved Hide resolved
qsimcirq/qsim_simulator.py Outdated Show resolved Hide resolved
@angelo-laskaris angelo-laskaris force-pushed the qsim_confusion_matrix_exception branch from cf1110e to 401ebec Compare October 20, 2023 17:10
@angelo-laskaris
Copy link
Contributor Author

Adding black formatter to my IDE, rebasing and then posting a commit on top of this one

eliottrosenberg and others added 2 commits October 27, 2023 14:26
…cified in a cirquit and Qsim is the target simulator a ValueError Exception will be thrown until confusion maps for Measurement Gates is supported in QSim.
@angelo-laskaris angelo-laskaris force-pushed the qsim_confusion_matrix_exception branch from 401ebec to 0f04453 Compare October 27, 2023 18:29
@angelo-laskaris
Copy link
Contributor Author

@95-martin-orion The one test that failed doesn't seem to be related to the change. Is this test ever flaky?

@95-martin-orion
Copy link
Collaborator

Hmmm. This seems related to this SO answer, as the logs indicate that python 3.12.0 was installed for the test. I'm not quite sure how this happened, though, seeing as both setup.py and the Github Actions workflow specify a maximum python version of 3.11.

It's possible we need to pin our python version in the test workflow.

@95-martin-orion
Copy link
Collaborator

Opened #632 to track the issue.

@95-martin-orion
Copy link
Collaborator

#632 is fixed - I'm going to go ahead with the v0.17.0 release to unblock some things, but I'm happy to cut a v0.17.1 once this is merged.

@95-martin-orion 95-martin-orion added the kokoro:run Trigger Kokoro builds for this PR. label Oct 30, 2023
@qsim-qsimh-bot qsim-qsimh-bot removed the kokoro:run Trigger Kokoro builds for this PR. label Oct 30, 2023
@angelo-laskaris
Copy link
Contributor Author

#632 is fixed - I'm going to go ahead with the v0.17.0 release to unblock some things, but I'm happy to cut a v0.17.1 once this is merged.

Okay sounds good!

@95-martin-orion 95-martin-orion added the kokoro:run Trigger Kokoro builds for this PR. label Oct 31, 2023
@qsim-qsimh-bot qsim-qsimh-bot removed the kokoro:run Trigger Kokoro builds for this PR. label Oct 31, 2023
@tanujkhattar
Copy link
Contributor

@95-martin-orion Are there any further concerns or can we LGTM?

@95-martin-orion
Copy link
Collaborator

@95-martin-orion Are there any further concerns or can we LGTM?

Sorry about the delay - this dropped off my radar. I've unresolved one comment above that I'd like clarity on, otherwise this is good to go. I'll follow up with a release shortly after.

@angelo-laskaris
Copy link
Contributor Author

@95-martin-orion Are there any further concerns or can we LGTM?

Sorry about the delay - this dropped off my radar. I've unresolved one comment above that I'd like clarity on, otherwise this is good to go. I'll follow up with a release shortly after.

No worries! Followed up on your comment

@95-martin-orion 95-martin-orion merged commit 3e7da1b into quantumlib:master Nov 9, 2023
15 checks passed
This was referenced Nov 9, 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.

5 participants