Investigate Performance Transpiling Large QASM Circuits To Cirq

by ADMIN 64 views

Introduction

In the field of quantum computing, transpiling large QASM circuits to Cirq is a crucial step in the quantum circuit compilation process. However, we have noticed that this process is significantly slower than other supported compilers. In this article, we will investigate the performance of transpiling large QASM circuits to Cirq and identify potential bottlenecks in the process.

Background

For benchmarking ucc, we rely on qbraid for converting between circuit formats. qbraid is an excellent tool for converting between different circuit formats, but we have noticed that converting to Cirq is significantly slower than other supported compilers. From our analysis, this might be upstream in openqasm3, pyqasm, and ply/yacc. We will investigate these potential bottlenecks in this article.

Example

As an example, consider the code below, transpiling this QASM circuit (originally from benchpress):

from qbraid import transpile
transpile(open("qv_N100_12345_basis_rz_rx_ry_cx.qasm", "r").read(), target="cirq")

This takes ~44 seconds on my M4 Pro. With a target of qiskit, this takes ~0.5 seconds.

Profiling Output

We ran py-spy on the script above and obtained the profiling output in profile.speedscope.cirq.qvN100.json. You can upload to https://www.speedscope.app/ to inspect the results.

Looking at the time-ordered view, there are 3 big sections in parts of qasm2_to_cirq:

  1. 21.35 seconds on https://github.com/qBraid/qBraid/blob/7ac709340740e6703acb81cbee586112573d703b/qbraid/transpiler/conversions/qasm2/qasm2_to_cirq.py#L49 Looking down the callstack shows time is almost entirely in openqasm3 package, and the _antlr parsing module within.
  2. 13.67 seconds on https://github.com/qBraid/qBraid/blob/7ac709340740e6703acb81cbee586112573d703b/qbraid/transpiler/conversions/qasm2/qasm2_to_cirq.py#L50 has a lot of time in pyqasm visit_basic_block, with a lot of time on this deepcopy.
  3. 8.5 seconds on https://github.com/qBraid/qBraid/blob/7ac709340740e6703acb81cbee586112573d703b/qbraid/transpiler/conversions/qasm2asm2_to_cirq.py#L59 with most time in yacc parsing.

Environment Details

Our environment details are as follows:

Package                  Version
------------------------ ---------------
annotated-types          0.7.0
antlr4-python3-runtime   4.13.2
anyio                    4.9.0
attrs                    25.3.0
cachetools               5.5.2
certifi                  2025.1.31
charset-normalizer       3.4.1
cirq                     1.4.1
cirq-aqt                 1.4.1
cirq-core                1.4.1
cirq-google              1.4.1
cirq-ionq                1.4.1
cirq-pasqal              1.4.1
cirq-rigetti             1.4.1
cirq-web                 1.4.1
contourpy                1.3.1
cycler                   0.12.1
deprecated               1.2.18
dill                     0.3.9
duet                     0.2.9
fonttools                4.57.0
google-api-core          2.24.2
google-auth              2.38.0
googleapis-common-protos 1.69.2
grpc-interceptor         0.15.4
grpcio                   1.71.0
grpcio-status            1.62.3
h11                      0.14.0
httpcore                 1.0.7
httpx                    0.28.1
idna                     3.10
kiwisolver               1.4.8
matplotlib               3.10.1
mpmath                   1.3.0
msgpack                  1.1.0
networkx                 3.4.2
numpy                    1.26.4
openqasm3                1.0.1
packaging                23.2
pandas                   2.2.3
pbr                      6.1.1
pillow                   11.1.0
ply                      3.11
proto-plus               1.26.1
protobuf                 4.25.6
pyasn1                   0.6.1
pyasn1-modules           0.4.2
pydantic                 2.11.2
pydantic-core            2.33.1
pyparsing                3.2.3
pyqasm                   0.3.0
pyquil                   4.16.1
python-dateutil          2.9.0.post0
python-rapidjson         1.20
pytz                     2025.2
pyzmq                    26.4.0
qbraid                   0.9.5
qbraid-core              0.1.36
qcs-api-client-common    0.11.8
qcs-sdk-python           0.21.18
qiskit                   2.0.0
quil                     0.16.0
requests                 2.32.3
rpcq                     3.11.0
rsa                      4.9
ruamel-yaml              0.18.10ruamel-yaml-clib         0.2.12
rustworkx                0.16.0
scipy                    1.15.2
setuptools               78.1.0
six                      1.17.0
sniffio                  1.3.1
sortedcontainers         2.4.0
stevedore                5.4.1
symengine                0.13.0
sympy                    1.13.3
tqdm                     4.67.1
types-deprecated         1.2.15.20250304
typing-extensions        4.13.1
typing-inspection        0.4.0
tzdata                   2025.2
urllib3                  2.3.0
wrapt                    1.17.2

Conclusion

In this article, we investigated the performance of transpiling large QASM circuits to Cirq and identified potential bottlenecks in the process. We found that the process is significantly slower than other supported compilers and that the bottlenecks are in the openqasm3, pyqasm, and ply/yacc packages. We will continue to investigate these bottlenecks and work on improving the performance of transpiling large QASM circuits to Cirq.

Future Work

  • Investigate the performance of openqasm3, pyqasm, and ply/yacc packages and identify potential bottlenecks.
  • Work on improving the performance of transpiling large QASM circuits to Cirq.
  • Explore alternative circuit formats and compilers to improve the performance of transpiling large QASM circuits.

References

Q: What is the current performance of transpiling large QASM circuits to Cirq?

A: The current performance of transpiling large QASM circuits to Cirq is significantly slower than other supported compilers. We have observed that the process takes around 44 seconds on a M4 Pro machine, while the same process takes around 0.5 seconds with a target of qiskit.

Q: What are the potential bottlenecks in the transpiling process?

A: We have identified potential bottlenecks in the openqasm3, pyqasm, and ply/yacc packages. These packages are responsible for parsing and converting the QASM circuit to Cirq, and their performance is critical to the overall transpiling process.

Q: What is the current state of the openqasm3, pyqasm, and ply/yacc packages?

A: The openqasm3 package is currently the most performant of the three, but it still has room for improvement. The pyqasm package is the slowest of the three, and its performance is critical to the overall transpiling process. The ply/yacc packages are also slow and need to be optimized.

Q: What are the potential solutions to improve the performance of transpiling large QASM circuits to Cirq?

A: There are several potential solutions to improve the performance of transpiling large QASM circuits to Cirq. These include:

  • Optimizing the openqasm3, pyqasm, and ply/yacc packages to improve their performance.
  • Exploring alternative circuit formats and compilers to improve the performance of transpiling large QASM circuits.
  • Using parallel processing or distributed computing to speed up the transpiling process.

Q: What is the expected outcome of improving the performance of transpiling large QASM circuits to Cirq?

A: The expected outcome of improving the performance of transpiling large QASM circuits to Cirq is to reduce the time it takes to transpile large QASM circuits. This will enable researchers and developers to work more efficiently and effectively with large QASM circuits, and will also enable the development of more complex and sophisticated quantum algorithms.

Q: What is the next step in improving the performance of transpiling large QASM circuits to Cirq?

A: The next step in improving the performance of transpiling large QASM circuits to Cirq is to optimize the pyqasm package. This will involve identifying the bottlenecks in the package and implementing optimizations to improve its performance.

Q: What is the expected timeline for improving the performance of transpiling large QASM circuits to Cirq?

A: The expected timeline for improving the performance of transpiling large QASM circuits to Cirq is several months. This will involve a combination of optimization and testing, and will require the collaboration of multiple researchers and developers.

Q: What is the impact of improving the performance of transpiling large QASM circuits to Cirq?

A: The expected impact of improving the performance of transpiling large QASM circuits to Cirq is to enable researchers and developers to work more efficiently and effectively with large QASM circuits. This will enable the development of more complex and sophisticated quantum algorithms, and will also enable the exploration of new quantum computing applications.

Q: What is the expected outcome of improving the performance of transpiling large QASM circuits to Cirq in terms of quantum computing applications?

A: The expected outcome of improving the performance of transpiling large QASM circuits to Cirq in terms of quantum computing applications is to enable the development of more complex and sophisticated quantum algorithms. This will enable the exploration of new quantum computing applications, such as quantum machine learning and quantum simulation.

Q: What is the expected outcome of improving the performance of transpiling large QASM circuits to Cirq in terms of quantum computing hardware?

A: The expected outcome of improving the performance of transpiling large QASM circuits to Cirq in terms of quantum computing hardware is to enable the development of more complex and sophisticated quantum computing hardware. This will enable the exploration of new quantum computing architectures, such as quantum annealers and quantum simulators.