Infleqtion / client-superstaq

https://superstaq.readthedocs.io
Apache License 2.0
87 stars 19 forks source link

The verbatim flag has unexpected behavior #830

Closed ColinCampbellCQ closed 11 months ago

ColinCampbellCQ commented 11 months ago

What is happening?

I was trying to submit benchmarking circuits on Friday, but when I saw them reach the machine, they looked very different than the circuits I had asked to run. I checked the compiled circuits for my job, and they were different than I expected as well. It appears that the compiler had been run despite verbatim being set to True.

How can we reproduce the issue?

from qiskit import QuantumCircuit
import qiskit_superstaq as qss
provider = qss.SuperstaqProvider(token)
backend = provider.get_backend("cq_hilbert_qpu")
qc = QuantumCircuit(1)
qc.rz(1, 0)
qc.measure_all()
job = backend.run(qc, shots=50, verbatim=True)

This block will result in a SuperstaqException where the submitted circuit has no logical effect. This is true if the compiler is run on the circuit, but in this example the machine was asked to run one rz gate even though the circuit would compile to the identity.

What should happen?

This block should run a circuit on Hilbert without compiling it to the identity or at least error for a different reason. Other circuits should also be able to be submitted without the compiler running if verbatim is set to True.

Environment

Any additional context?

See the superstaq Team for details. @SalahedeenIssa and I discussed this a bit on Friday and he was able to reproduce this error message.

ColinCampbellCQ commented 11 months ago

This PR includes Salah's fix to this problem: https://github.com/Infleqtion/server-superstaq/pull/2884 However, has there been a test that this problem has been resolved @SalahedeenIssa?

SalahedeenIssa commented 11 months ago

Seems to be running fine. I tried this circuit:



qubits = cirq.LineQubit.range(9)
gate1 = css.ParallelRGate(np.pi, np.pi, 9).on(*qubits)
gate2 = css.ParallelRGate(np.pi / 2, np.pi / 2, 9).on(*qubits)
circuit = cirq.Circuit(gate1, gate2, cirq.measure(*qubits))
circuit

Output:
0: ───RGate(π, π)───RGate(0.5π, 0.5π)───M───
      │             │                   │
1: ───#2────────────#2──────────────────M───
      │             │                   │
2: ───#3────────────#3──────────────────M───
      │             │                   │
3: ───#4────────────#4──────────────────M───
      │             │                   │
4: ───#5────────────#5──────────────────M───
      │             │                   │
5: ───#6────────────#6──────────────────M───
      │             │                   │
6: ───#7────────────#7──────────────────M───
      │             │                   │
7: ───#8────────────#8──────────────────M───
      │             │                   │
8: ───#9────────────#9──────────────────M───

Running it without verbatim: 

job_css = service.create_job(circuit, repetitions=100, target="cq_hilbert_simulator", method="dry-run")
result_css = job_css.counts(0)
job_css.compiled_circuits()[0]

Output:
0: ───RGate(0.5π, 0.5π)───M───
      │                   │
1: ───#2──────────────────M───
      │                   │
2: ───#3──────────────────M───
      │                   │
3: ───#4──────────────────M───
      │                   │
4: ───#5──────────────────M───
      │                   │
5: ───#6──────────────────M───
      │                   │
6: ───#7──────────────────M───
      │                   │
7: ───#8──────────────────M───
      │                   │
8: ───#9──────────────────M───

Running it with verbatim:
job_css = service.create_job(circuit, repetitions=100, target="cq_hilbert_simulator", method="dry-run", verbatim=True)
result_css = job_css.counts(0)
job_css.compiled_circuits()[0]

Output:
0: ───RGate(π, π)───RGate(0.5π, 0.5π)───M───
      │             │                   │
1: ───#2────────────#2──────────────────M───
      │             │                   │
2: ───#3────────────#3──────────────────M───
      │             │                   │
3: ───#4────────────#4──────────────────M───
      │             │                   │
4: ───#5────────────#5──────────────────M───
      │             │                   │
5: ───#6────────────#6──────────────────M───
      │             │                   │
6: ───#7────────────#7──────────────────M───
      │             │                   │
7: ───#8────────────#8──────────────────M───
      │             │                   │
8: ───#9────────────#9──────────────────M───