ProjectQ icon indicating copy to clipboard operation
ProjectQ copied to clipboard

Add support for import/export with OpenQASM

Open Takishima opened this issue 5 years ago • 3 comments

OpenQASM support

This is a first attempt at implementing conversion to and from OpenQASM.

U2 and U3 gates

Introduced U2 and U3 gates with identical definitions as the u2 and u3 gates in OpenQASM standard library.

Conversion ProjectQ -> QASM

This does not require qiskit to be installed. All the ProjectQ gates are automatically converted into QASM code.

For all gates that are not currently supported by QASM need to be decomposed before reaching the OpenQASMBackend.

Also note that you may also use OpenQASMBackend as a regular compiler engine in order to generate QASM and use the simulator at the same time:

from projectq.cengines import MainEngine
from projectq.backends import OpenQASMBackend, Simulator

eng = MainEngine(backend=Simulator(), engine_list=[OpenQASMBackend()])

# ...

Conversion QASM -> ProjectQ

At this point, this does require either qiskit or pyparsing to be installed.

Typical use case:

from projectq import MainEngine
from projectq.libs.qasm import read_qasm_str, read_qasm_file

eng = MainEngine()
read_qasm_file(eng, '/path/to/file.qasm')

The implementation currently supports most features of OpenQASM 2.0 (and some OpenQASM 3.0 features, although support for that version is still experimental)

Feature Comments Using qiskit Using PyParsing
C-style comments // some text
C++-style comments /* some text */
Include files
Quantum registers
Classical registers
If-expressions if(creg==int) qop;
Custom gate definitions
Apply builtin gates
Apply custom gates
Apply opaque gates ❌ (ignored)
Apply measurements
OpenQASM 3.0 features*
If-expressions (3.0) if(creg[0] > 1) {...}
Extended types const, int, float, ...

*support at time of writing.

Closes #345 and closes #380

Takishima avatar Nov 06 '20 17:11 Takishima

Pull Request Test Coverage Report for Build 1660297125

  • 573 of 573 (100.0%) changed or added relevant lines in 9 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 100.0%

Totals Coverage Status
Change from base Build 1660129124: 0.0%
Covered Lines: 7561
Relevant Lines: 7561

💛 - Coveralls

coveralls avatar Jun 15 '21 14:06 coveralls

@Takishima, I know a long time has passed but is this still relevant? Are we still considering implementing QASM translation to ProjectQ?

pedromartinssouza avatar Mar 24 '24 18:03 pedromartinssouza

I will work on fixing the CI (hopefully this coming weekend) and I will then try to fix this PR. Will ping @andreashehn for a review then,

Takishima avatar Mar 27 '24 21:03 Takishima