qsim
qsim copied to clipboard
QSimSimulator accepts nonsense qsim_options
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.
In the pre-release version, we have a QSimOptions
dataclass to replace the {string: value} dict: https://github.com/quantumlib/qsim/blob/d15f5f86bdf6e2d5ff1ea5855add6820dcddca94/qsimcirq/qsim_simulator.py#L121-L122
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.)