-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #112 from BQSKit/1.0.4-dev
1.0.4
- Loading branch information
Showing
24 changed files
with
377 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,38 @@ | ||
"""This module implements functions for translating to and from Cirq.""" | ||
from __future__ import annotations | ||
|
||
import cirq | ||
from cirq.contrib.qasm_import import circuit_from_qasm | ||
from typing import TYPE_CHECKING | ||
if TYPE_CHECKING: | ||
import cirq | ||
|
||
from bqskit.ir.circuit import Circuit | ||
from bqskit.ir.lang.qasm2 import OPENQASM2Language | ||
|
||
|
||
def cirq_to_bqskit(cc: cirq.Circuit) -> Circuit: | ||
"""Convert Cirq's Circuit `cc` to a BQSKit Circuit.""" | ||
try: | ||
import cirq | ||
except ImportError as e: | ||
raise ImportError( | ||
'\n\nUnable to import cirq package.\n' | ||
'Please ensure that it is installed with the following command:\n' | ||
'\tpip install cirq\n', | ||
) from e | ||
|
||
circuit = OPENQASM2Language().decode(cirq.qasm(cc)) | ||
return circuit | ||
|
||
|
||
def bqskit_to_cirq(circuit: Circuit) -> cirq.Circuit: | ||
"""Convert a BQSKit Circuit to Cirq's Circuit.""" | ||
try: | ||
from cirq.contrib.qasm_import import circuit_from_qasm | ||
except ImportError as e: | ||
raise ImportError( | ||
'\n\nUnable to import cirq package.\n' | ||
'Please ensure that it is installed with the following command:\n' | ||
'\tpip install cirq\n', | ||
) from e | ||
|
||
return circuit_from_qasm(OPENQASM2Language().encode(circuit)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,38 @@ | ||
"""This module implements functions for translating to and from PyTKet.""" | ||
from __future__ import annotations | ||
|
||
import pytket | ||
from pytket.qasm import circuit_from_qasm_str | ||
from pytket.qasm import circuit_to_qasm_str | ||
from typing import TYPE_CHECKING | ||
if TYPE_CHECKING: | ||
import pytket | ||
|
||
from bqskit.ir.circuit import Circuit | ||
from bqskit.ir.lang.qasm2 import OPENQASM2Language | ||
|
||
|
||
def pytket_to_bqskit(qc: pytket.Circuit) -> Circuit: | ||
"""Convert PyTKet's Circuit `cc` to a BQSKit Circuit.""" | ||
try: | ||
from pytket.qasm import circuit_to_qasm_str | ||
except ImportError as e: | ||
raise ImportError( | ||
'\n\nUnable to import pytket package.\n' | ||
'Please ensure that it is installed with the following command:\n' | ||
'\tpip install pytket\n', | ||
) from e | ||
|
||
circuit = OPENQASM2Language().decode(circuit_to_qasm_str(qc)) | ||
return circuit | ||
|
||
|
||
def bqskit_to_pytket(circuit: Circuit) -> pytket.Circuit: | ||
"""Convert a BQSKit Circuit to a PyTKet Circuit.""" | ||
try: | ||
from pytket.qasm import circuit_from_qasm_str | ||
except ImportError as e: | ||
raise ImportError( | ||
'\n\nUnable to import pytket package.\n' | ||
'Please ensure that it is installed with the following command:\n' | ||
'\tpip install pytket\n', | ||
) from e | ||
|
||
return circuit_from_qasm_str(OPENQASM2Language().encode(circuit)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,38 @@ | ||
"""This module implements functions for translating to and from QuTiP.""" | ||
from __future__ import annotations | ||
|
||
from qutip import QubitCircuit | ||
from qutip.qip.qasm import circuit_to_qasm_str | ||
from qutip.qip.qasm import read_qasm | ||
from typing import TYPE_CHECKING | ||
if TYPE_CHECKING: | ||
from qutip import QubitCircuit | ||
|
||
from bqskit.ir.circuit import Circuit | ||
from bqskit.ir.lang.qasm2 import OPENQASM2Language | ||
|
||
|
||
def qutip_to_bqskit(qc: QubitCircuit) -> Circuit: | ||
"""Convert QuTiP's QubitCircuit `qc` to a BQSKit Circuit.""" | ||
try: | ||
from qutip.qip.qasm import circuit_to_qasm_str | ||
except ImportError as e: | ||
raise ImportError( | ||
'\n\nUnable to import qutip package.\n' | ||
'Please ensure that it is installed with the following command:\n' | ||
'\tpip install qutip\n', | ||
) from e | ||
|
||
circuit = OPENQASM2Language().decode(circuit_to_qasm_str(qc)) | ||
return circuit | ||
|
||
|
||
def bqskit_to_qutip(circuit: Circuit) -> QubitCircuit: | ||
"""Convert a BQSKit Circuit to QuTiP's QubitCircuit.""" | ||
try: | ||
from qutip.qip.qasm import read_qasm | ||
except ImportError as e: | ||
raise ImportError( | ||
'\n\nUnable to import qutip package.\n' | ||
'Please ensure that it is installed with the following command:\n' | ||
'\tpip install qutip\n', | ||
) from e | ||
|
||
return read_qasm(OPENQASM2Language().encode(circuit), strmode=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.