ProjectQ-Framework / ProjectQ

ProjectQ: An open source software framework for quantum computing
https://projectq.ch
Apache License 2.0
893 stars 276 forks source link

Add support for import/export with OpenQASM #381

Open Takishima opened 4 years ago

Takishima commented 4 years ago

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

coveralls commented 3 years ago

Pull Request Test Coverage Report for Build 1660297125


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

💛 - Coveralls
pedromartinssouza commented 8 months ago

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

Takishima commented 8 months ago

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,