qsimcirq: Applying global phase causes "ValueError: Only up to 6-qubit matrix gates are supported"
rht opened this issue · 4 comments
Minimal reproducer:
import numpy as np
import cirq
import qsimcirq
simulator = qsimcirq.QSimSimulator()
circuit = cirq.Circuit([
cirq.global_phase_operation(np.exp(0.5j * np.pi))
])
simulator.simulate(circuit)
Traceback:
Traceback (most recent call last):
File "***/minimal_reproducer.py", line 10, in <module>
simulator.simulate(circuit)
File "***/venv/lib/python3.10/site-packages/cirq/sim/simulator.py", line 491, in simulate
return self.simulate_sweep(
File "***/venv/lib/python3.10/site-packages/cirq/sim/simulator.py", line 506, in simulate_sweep
return list(self.simulate_sweep_iter(program, params, qubit_order, initial_state))
File "***/venv/lib/python3.10/site-packages/qsimcirq/qsim_simulator.py", line 519, in simulate_sweep_iter
options["c"], _ = self._translate_circuit(
File "***/venv/lib/python3.10/site-packages/qsimcirq/qsim_simulator.py", line 808, in _translate_circuit
translated, moment_indices = translator_fn(qubit_order)
File "***/venv/lib/python3.10/site-packages/qsimcirq/qsim_circuit.py", line 413, in translate_cirq_to_qsim
add_op_to_circuit(qsim_op, time, qubit_to_index_dict, qsim_circuit)
File "***/venv/lib/python3.10/site-packages/qsimcirq/qsim_circuit.py", line 315, in add_op_to_circuit
qsim.add_matrix_gate(time, qsim_qubits, m, circuit)
ValueError: Only up to 6-qubit matrix gates are supported.
When I inspected the object associated with the global phase operator, I got something like cirq.MatrixGate(np.array([[(6.123233995736766e-17-1j)]], dtype=np.complex128)).on()
.
The same circuit works just fine on cirq.Simulator
.
Version
cirq-core==1.0.0
qsimcirq==0.14.0
The error is being raised from this method:
qsim/pybind_interface/pybind_main.cpp
Line 232 in 0041775
In short, we don't have a handler set up for zero-qubit gates (like global phase), and the error message is poorly worded (it should mention zero-qubit gates as well).
@sergeisakov, is there a simple way to add this support? My first thought is to just add case 0:
to the switch, but I get the feeling that a no-qubit gate may run into problems elsewhere.
Yes, I think there should be a relatively simple way to add this support. I will do that next week.
Bump. @sergeisakov any update on this?
#579 should fix this issue.