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

QSimSimulator accepts nonsense qsim_options #425

Open
peterse opened this issue Sep 15, 2021 · 1 comment
Open

QSimSimulator accepts nonsense qsim_options #425

peterse opened this issue Sep 15, 2021 · 1 comment

Comments

@peterse
Copy link

peterse commented Sep 15, 2021

I've noticed that the following code runs fine in qsimcirq==0.10.2:

import cirq
import qsimcirq

qsim_options = {'r': 100, 'g': True, 'z': True, 'foo': 'bar'}
simulator = qsimcirq.QSimSimulator(qsim_options=qsim_options)

q0, q1 = cirq.GridQubit.rect(1, 2)
circuit = cirq.Circuit(cirq.H(q0), cirq.CNOT(q0, q1))
print(simulator.simulate(circuit).final_state_vector)
>> [0.70710677+0.j 0.        +0.j 0.        +0.j 0.70710677+0.j]

To me this is confusing behavior since the 'z' option has only been implemented upstream, and my device does not have any GPU accelerators as far as i know.

I think it would be helpful if the simulator either threw an error when the user tries to invoke options that are unavailable on the current release or device, or at least nudged users with some kind of warning on how to check for the compatibility of device-specific qsim_options with the user's machine.

@95-martin-orion
Copy link
Collaborator

In the pre-release version, we have a QSimOptions dataclass to replace the {string: value} dict:

class QSimOptions:
"""Container for options to the QSimSimulator.

This class provides clearer option names and only accepts valid options, so it should resolve this issue. (We do still allow dict-formatted options for backwards compatibility, but will recommend use of the dataclass.)

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

No branches or pull requests

2 participants