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

cirq.Circuit(cirq.I(cirq.LineQubit(0))) segfaults when trying to execute on qsim #540

Open
vtomole opened this issue Jul 8, 2022 · 2 comments
Assignees

Comments

@vtomole
Copy link
Contributor

vtomole commented Jul 8, 2022

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
Copy link
Collaborator

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 95-martin-orion self-assigned this Jul 8, 2022
@95-martin-orion
Copy link
Collaborator

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

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