Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for import/export with OpenQASM #381

Open
wants to merge 43 commits into
base: develop
Choose a base branch
from

Conversation

Takishima
Copy link
Collaborator

@Takishima Takishima commented Nov 6, 2020

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 Takishima self-assigned this Nov 6, 2020
@Takishima Takishima changed the title Feature/openqasm Add support for import/export with OpenQASM Nov 6, 2020
@Takishima Takishima force-pushed the feature/openqasm branch 2 times, most recently from d3bf713 to da62e6b Compare November 11, 2020 10:09
@Takishima Takishima force-pushed the feature/openqasm branch 3 times, most recently from 61dd83f to eb66430 Compare February 24, 2021 15:29
@Takishima Takishima force-pushed the feature/openqasm branch 6 times, most recently from 9eab148 to 6055312 Compare June 15, 2021 14:39
@coveralls
Copy link

coveralls commented Jun 15, 2021

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

@pedromartinssouza
Copy link

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

@Takishima
Copy link
Collaborator Author

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,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Qasm interface How would one work with CommandPrinter()
3 participants