Qiskit / benchpress

Apache License 2.0
20 stars 13 forks source link

Staq gym #23

Closed ashsaki closed 1 month ago

ashsaki commented 2 months ago

This PR adds the staq_gym for Staq (https://github.com/softwareQinc/staq/tree/main) package.

  1. Adds a .sh file to install Staq using homebrew and its Python wrapper Pystaq using pip.
  2. Staq does not have circuit building and manipulation features. Therefore, those tests are skipped with reason "No circuit building and manipulation in staq."
  3. Adds:
    • device_transpile
    • abstract_transpile
  4. Staq reads device specifications (number of qubits, qubit connectivity, single- and two-qubit errors) from a JSON file. Therefore, a temporary JSON file is created from IBM and Flexible backends and saved in a temporary directory using pytest's tmp_path_factory.
    • Unlike other gyms StaqFlexibleBackend does not inherit from any Pystaq class. Instead, it has a get_staq_flexible_backend() method, which creates a Pystaq Device object (This Device object will be saved as JSON in the temporary directory).
  5. Staq takes the input circuit a QASM file. Therefore, necessary test circuits are saved as QASM files, again, in tmp_path_factory from which Staq reads them. However, many test circuits in Benchpress are already in QASM format. For them, we just supply the path to the file to Staq.
  6. While Staq can generate circuit statistics like depth and number of gates, it cannot compute 2Q-depth which we are benchmarking. Therefore, Staq output, a QASM string (in the console), is loaded as a qiskit.QuantumCircuit to compute necessary circuit statistics. Note that, Python subprocess.run is used to compile circuits using Staq, which is a command-line tool. The console output (stdout) is captured and processed to get results.
  7. staq -S -O2 -c -l bestfit -M swap flags are used as default to transpile a circuit from QASM file.
  8. Staq transpiles a circuit into CX gates as 2Q gate. I could not find a way to target other two-qubits gates such as CZ. Therefore, backend ibm_torino may have CZ gate in the basis, number of and depth of CX gate are counted for Staq gym.
  9. Some QASM files from the qasmbench are updated as Staq's qelib1.inc is missing many gate definitions. The missing gate definitions are borrowed from Qiskit qelib1.inc.
ashsaki commented 1 month ago

@nonhermitian - The PR is ready for review.