ProjectQ
ProjectQ copied to clipboard
Add support for import/export with OpenQASM
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
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 | |
|---|---|
| Change from base Build 1660129124: | 0.0% |
| Covered Lines: | 7561 |
| Relevant Lines: | 7561 |
💛 - Coveralls
@Takishima, I know a long time has passed but is this still relevant? Are we still considering implementing QASM translation to ProjectQ?
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,