`cirq.Circuit(cirq.I(cirq.LineQubit(0)))` segfaults when trying to execute on qsim
Opened this issue · 2 comments
vtomole commented
Trying to run a circuit that contains an identity operation on the simulator:
import cirq
import qsimcirq
circuit = cirq.Circuit(cirq.I(cirq.LineQubit(0)))
qsim_simulator = qsimcirq.QSimSimulator()
print("Running simulation for the following circuit:")
print(circuit)
qsim_results = qsim_simulator.compute_amplitudes(
circuit, bitstrings=[0b00, 0b01])
print("qsim results:")
print(qsim_results)
Outputs:
Running simulation for the following circuit:
0: ───I───
Segmentation fault (core dumped)
95-martin-orion commented
Further testing suggests that the circuit must contain only identity gates to trigger the segfault - for example, X(q0), I(q1)
will run successfully.
qsim_circuit
is conspicuously lacking in translators for identity gates - it's possible they got lost in recent optimizations. I'll take a closer look.
95-martin-orion commented
It looks like the translation is fine - cirq.decompose
converts to an empty circuit - but compute_amplitudes
is misbehaving due to all qubits having been abstracted away. qsim ought to preserve the identity qubits for use in amplitude retrieval.
Some similar tests for comparison:
>>> qsim_results = qsim_simulator.compute_amplitudes(cirq.Circuit(), bitstrings=[0b00, 0b01])
# wrong bitstring length in bitstrings_str: got 1; should be 0.
# Unable to parse provided bit strings.
>>> qsim_results = qsim_simulator.compute_amplitudes(cirq.Circuit(), bitstrings=[])
# Segmentation fault