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 a QURI Parts converter #210

Merged
merged 15 commits into from
Apr 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/github-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,26 @@ jobs:
- name: Run unit test
run: |
python3 -m unittest discover -v ./test/with_qiskit/

test_with_quri_parts_and_qulacs:
# Python 3.10 is used because quri_parts supports python > 3.9
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Python3.10
uses: actions/setup-python@v4
with:
python-version: "3.10"
cache: "pip"
cache-dependency-path: "pyproject.toml"

- name: Install library
run: |
pip install .[quri_parts_with_qulacs]

- name: Run unit test
run: |
python3 -m unittest discover -v ./test/with_quri_parts_and_qulacs/
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ ci = [
qiskit = [
"qiskit == 0.*"
]
quri_parts = [
"quri_parts == 0.*"
]
quri_parts_with_qulacs = [
"quri_parts[qulacs] == 0.*"
]

[tool.setuptools]
include-package-data = true
Expand Down
12 changes: 11 additions & 1 deletion quantestpy/converter/converter_to_quantestpy_circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
from quantestpy.converter.sdk.qasm import _cvt_openqasm_to_quantestpy_circuit
from quantestpy.converter.sdk.qiskit import (
_cvt_qiskit_to_quantestpy_circuit, _is_instance_of_qiskit_quantumcircuit)
from quantestpy.converter.sdk.quri_parts import (
_cvt_quri_parts_circuit_to_quantestpy_circuit,
_is_instance_of_quri_parts_quantumcircuit)
from quantestpy.exceptions import QuantestPyError


Expand All @@ -19,10 +22,17 @@ def cvt_input_circuit_to_quantestpy_circuit(circuit) -> QuantestPyCircuit:
elif _is_instance_of_qiskit_quantumcircuit(circuit):
quantestpy_circuit = _cvt_qiskit_to_quantestpy_circuit(circuit)

elif _is_instance_of_quri_parts_quantumcircuit(circuit):
quantestpy_circuit = _cvt_quri_parts_circuit_to_quantestpy_circuit(
circuit)

else:
raise QuantestPyError(
"Input circuit must be one of the following: "
"qasm, qiskit.QuantumCircuit and QuantestPyCircuit."
"qasm, qiskit.QuantumCircuit,"
"quri_parts.circuit.NonParametricQuantumCircuit,"
"quri_parts.circuit.ImmutableBoundParametricQuantumCircuit,"
"and QuantestPyCircuit."
)

return quantestpy_circuit
21 changes: 10 additions & 11 deletions quantestpy/converter/sdk/qasm.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
from quantestpy import QuantestPyCircuit
from quantestpy.converter.sdk.qiskit import (
_cvt_qiskit_to_quantestpy_circuit, _raise_error_if_not_qiskit_installed)
from quantestpy.converter.sdk.qiskit import _cvt_qiskit_to_quantestpy_circuit
from quantestpy.exceptions import QuantestPyError

try:
from qiskit import QuantumCircuit

except ModuleNotFoundError:
pass


def _cvt_openqasm_to_quantestpy_circuit(qasm: str) -> QuantestPyCircuit:

_raise_error_if_not_qiskit_installed()

qiskit_circuit = QuantumCircuit.from_qasm_str(qasm)
return _cvt_qiskit_to_quantestpy_circuit(qiskit_circuit)
def _cvt_openqasm_to_quantestpy_circuit(qasm: str) -> QuantestPyCircuit:
raise QuantestPyError(
"Qiskit is missing. Please install it."
)
else:
def _cvt_openqasm_to_quantestpy_circuit(qasm: str) -> QuantestPyCircuit:
qiskit_circuit = QuantumCircuit.from_qasm_str(qasm)
return _cvt_qiskit_to_quantestpy_circuit(qiskit_circuit)
Loading