Infleqtion / client-superstaq

https://superstaq.readthedocs.io
Apache License 2.0
83 stars 18 forks source link

Remove unneeded cirq dependency in qiskit-superstaq #117

Closed singular-value closed 3 years ago

singular-value commented 3 years ago

Right now, we convert qiskit circuits to cirq circuits just so that we can call cirq.to_json(circuit) and get a JSON-serialized version. But then on the server, we go back down to the qiskit circuit anyways.

There should be a way to get qiskit circuits down to a serialized format; there shouldn't be a need for a cirq dependency. repr(qc) doesn't work, but maybe just taking the qc.qasm() would work.

mtreinish commented 3 years ago

If you going from Qiskit's QuantumCircuit object in the client to a qiskit QuantumCircuit on the server side I'd suggest you take a look at QPY serialization which is a new feature we added in the latest qiskit-terra 0.18.x release:

https://qiskit.org/documentation/apidoc/qpy.html

it's a native binary serialization format for Qiskit's quantum circuit object. You can pass qpy_serialization.dump a circuit (or a list of circuits) and get the same circuits out from runing load().

For example, IBM Quantum has started to use it for the circuit runner serialization by b64 encoding the QPY file written to a BytesIO buffer and embedding that in the json payload: https://github.com/Qiskit/qiskit-ibmq-provider/blob/abc88dbd224cae3c492af177c08a610592e7cd7f/qiskit/providers/ibmq/runtime/utils.py#L124-L132

It also gives you a certain level of backwards compatibility as the format is designed such that newer versions of Qiskit can always load QPY files generated with older versions of Qiskit.

vtomole commented 3 years ago

Thank you very much for the recommendation. @mtreinish. We are going to serialize our circuits to qasm strings for now as a stopgap and circle around to QPY in the future.

singular-value commented 3 years ago

Yup, thanks @mtreinish — that makes a lot of sense. Tracking in SupertechLabs/superstaq-client#118.