In Qiskit, there are explicit transpile [1] (where a circuit is transpiled to primitive gates) and backend.run [2] (where the circuit is executed in either statevector simulation or real hardware) steps. I wonder what would be the equivalent in Cirq. In Cirq, you only have 1 API of simulator.simulate() [3].

Note: I am executing my circuit multiple times under various parameters in a hybrid quantum-classical feedback loop algorithm. And so, using sweep is not possible.

[1] https://github.com/Qiskit/qiskit-terra/blob/6a5adf20e86c74ce507dfb82a4d67ab05522048d/qiskit/compiler/transpiler.py#L60
[2] https://github.com/Qiskit/qiskit-terra/blob/6a5adf20e86c74ce507dfb82a4d67ab05522048d/qiskit/providers/backend.py#L211
[3] https://quantumai.google/reference/python/cirq/Simulator#simulate

  • 1
    $\begingroup$ Welcome to QCSE! Some feedback on your question: Ideally, the post would explain what transpile and backend.rundo in order to make the question self-contained. At minimum it should provide links, though these are discouraged since they can become dead reducing the future value of the post. As it stands, the post shifts the burden of figuring out what it is you're trying to do in cirq on the readers which further reduces its future value and your current chances of getting an answer. $\endgroup$ Aug 9 at 3:39
  • $\begingroup$ Thank you for the feedback. I have added permalinks to the functions, and added elaboration for what they did. $\endgroup$
    – pcr
    Aug 9 at 7:32

1 Answer 1


You could play around with Cirq's transformers. Each transformer is a potential compilation step, such as decomposition into target gatesets, mapping/routing, and hardware-specific optimizations. There are several built-in transformers (including cirq.optimize_for_target_gateset, which may help with the transpilation into primitive gates that you mentioned), and you can also define your own custom transformers if you want something more complex.

See also this previous question on stackexchange.

  • $\begingroup$ Thank you for the answer. Looks like there are several in the Cirq repo: cz_gateset.py, sqrt_iswap_gateset.py, sycamore_gateset.py, ionq_gateset.py, and pasqal_gateset.py. I tried cirq.optimize_for_target_gateset(circuit, gateset=ionq_gateset.IonQTargetGateset()), and this step alone is >45x slower than doing simulator.simulate() on the original circuit. $\endgroup$
    – pcr
    Aug 10 at 5:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.