quantumlib/qsim

Runtime error when attempting to simulate statevector

paaige opened this issue · 3 comments

paaige commented

I'm getting the following error (using the CuQuantum container here) when attempting to simulate the statevector of a circuit.

Was able to produce a MWE where this repros with:

import cirq
import qsimcirq
from cirq.contrib import quantum_volume

options = {"f": 4, "g": True, "gmode": 1}
gpu_options = qsimcirq.QSimOptions(options)
sim = qsimcirq.QSimSimulator(gpu_options)

def qv_circuit_cirq(depth, num_qubits, seed=None):
    if seed is not None:
        state = np.random.RandomState(int(seed, 2))
    else:
        state=None
    return quantum_volume.generate_model_circuit(num_qubits, depth, random_state=state)

qc = qv_circuit_cirq(9, num_qubits=3)
print(sim.simulate(program=qc).final_state_vector)

Traceback (most recent call last):
File "gpu_simulation.py", line 90, in
print(get_statevector(qc))
File "gpu_simulation.py", line 79, in get_statevector
sv = sim.simulate(program=circuit).final_state_vector
File "/home/cuquantum/conda/envs/cuquantum-23.03/lib/python3.8/site-packages/cirq/sim/simulator.py", line 495, in simulate
return self.simulate_sweep(
File "/home/cuquantum/conda/envs/cuquantum-23.03/lib/python3.8/site-packages/cirq/sim/simulator.py", line 510, in simulate_sweep
return list(self.simulate_sweep_iter(program, params, qubit_order, initial_state))
File "/home/cuquantum/conda/envs/cuquantum-23.03/lib/python3.8/site-packages/qsimcirq/qsim_simulator.py", line 523, in simulate_sweep_iter
qsim_state = fullstate_simulator_fn(options, initial_state)
RuntimeError: Unable to cast Python instance to C++ type (#define PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for details)

edit: this also repros with the example full state vector simulation in this tutorial here.

qsimcirq version 0.16.3
cuda version 11.8
Ubuntu 18.04

cc: @leofang

@paaige if you're using the cuQuantum Appliance, I'd recommend posting this issue on our GitHub as well so that we can follow/update this issue.

I did this on your behalf: NVIDIA/cuQuantum#75

I provide edits that avoid the error you post here.

Added a clarifying note to the linked issue. In short: QSimOptions only accepts individual option values, not a dict. The {string: value} input format referenced in the docstring can be passed to QSimSimulator as the options parameter.