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 constructor methods to build QuantumCircuits from QASM #1172

Merged
merged 8 commits into from
Nov 3, 2018

Conversation

mtreinish
Copy link
Member

Summary

This commit adds 2 new static methods to the QuantumCircuit class to
enable constructing a QuantumCircuit from a QASM string or file. This
gives users to option of building a QuantumCircuit object with a qasm
file simply by calling:

circuit = QuantumCircuit.from_qasm_file(path)

or

circuit = QuantumCircuit.from_qasm_str(qasm_str)

Details and comments

As part of this change the circuitbackend imports for Unroller() had to
be updated to be module imports. This was to avoid having a circular
import with the _quantumcircuit module (now that _quantumcircuit
leverages uses it).

Fixes #971

@jaygambetta
Copy link
Member

jaygambetta commented Oct 31, 2018

can we get some tests and update the example also i would depreciate the wrapper functions that use load_from_file and load_from_string

@mtreinish
Copy link
Member Author

Sure, I'll add some tests for this and deprecate the wrapper methods

@jaygambetta
Copy link
Member

this looks good. Its just failing in the linter.

@mtreinish
Copy link
Member Author

sigh, it's failing on tempfile in appveyor just like @nonhermitian PR. I guess I'll do the same skip on the tests here too

@mtreinish mtreinish force-pushed the add-qasm-constructor branch from 4543160 to 5a36392 Compare November 1, 2018 17:40
jaygambetta
jaygambetta previously approved these changes Nov 2, 2018
@jaygambetta
Copy link
Member

@mtreinish can you fix the conflicts with @ajavadia addition and then we should merge

This commit adds 2 new static methods to the QuantumCircuit class to
enable constructing a QuantumCircuit from a QASM string or file. This
gives users to option of building a QuantumCircuit object with a qasm
file simply by calling:

circuit = QuantumCircuit.from_qasm_file(path)

or

circuit = QuantumCircuit.from_qasm_str(qasm_str)

As part of this change the circuitbackend imports for Unroller() had to
be updated to be module imports. This was to avoid having a circular
import with the _quantumcircuit module (now that _quantumcircuit
leverages uses it).

Fixes Qiskit#971
This commit deprecates the qasm loading functions from the wrapper
module. Now that we have top level static constructor methods off the
quantum circuit class these aren't needed anymore.
This commit adds unit test coverage for the new from_qasm_str() and
from_qasm_file() constructor methods on the QuantumCircuit class.
@jaygambetta jaygambetta merged commit c7e404e into Qiskit:master Nov 3, 2018
@mtreinish mtreinish deleted the add-qasm-constructor branch November 3, 2018 00:21
lia-approves pushed a commit to edasgupta/qiskit-terra that referenced this pull request Jul 30, 2019
* Add constructor methods to build QuantumCircuits from QASM

This commit adds 2 new static methods to the QuantumCircuit class to
enable constructing a QuantumCircuit from a QASM string or file. This
gives users to option of building a QuantumCircuit object with a qasm
file simply by calling:

circuit = QuantumCircuit.from_qasm_file(path)

or

circuit = QuantumCircuit.from_qasm_str(qasm_str)

As part of this change the circuitbackend imports for Unroller() had to
be updated to be module imports. This was to avoid having a circular
import with the _quantumcircuit module (now that _quantumcircuit
leverages uses it).

Fixes Qiskit#971

* Disable cyclic import pylint

* Deprecate qasm loading functions in wrapper

This commit deprecates the qasm loading functions from the wrapper
module. Now that we have top level static constructor methods off the
quantum circuit class these aren't needed anymore.

* Add tests for new from_qasm*() QuantumCircuit methods

This commit adds unit test coverage for the new from_qasm_str() and
from_qasm_file() constructor methods on the QuantumCircuit class.

* Fix pylint nitpicks

* Add skip for appveyor
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.

load_qasm_file and load_qasm_string should be part of circuits
3 participants