Skip to content

Commit 0d46889

Browse files
fix qiskit1.0
1 parent 5c1ea1d commit 0d46889

File tree

6 files changed

+27
-8
lines changed

6 files changed

+27
-8
lines changed

.pylintrc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ max-module-lines=2000
5353

5454
# Exceptions that will emit a warning when being caught. Defaults to
5555
# "BaseException, Exception".
56-
overgeneral-exceptions=BaseException,
57-
Exception
56+
overgeneral-exceptions=builtins.BaseException,
57+
builtins.Exception
5858

5959
# Note how codecc doesn't accept goddnames in pylintrc, and how we use pylint disable invalid name per file instead
6060
# it is not neat at all, but this is codecc's badness :(

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ TensorCircuit-NG is a high performance quantum software framework, supporting fo
2929

3030
TensorCircuit-NG is built on top of modern machine learning frameworks: Jax, TensorFlow, and PyTorch. It is specifically suitable for highly efficient simulations of quantum-classical hybrid paradigm and variational quantum algorithms in ideal, noisy and approximate cases. It also supports quantum hardware access and provides CPU/GPU/QPU hybrid deployment solutions.
3131

32-
TensorCircuit-NG is [fully compatible](https://tensorcircuit-ng.readthedocs.io/en/latest/faq.html#what-is-the-relation-between-tensorcircuit-and-tensorcircuit-ng) with TensorCircuit with more new features and bug fixes.
32+
TensorCircuit-NG is [fully compatible](https://tensorcircuit-ng.readthedocs.io/en/latest/faq.html#what-is-the-relation-between-tensorcircuit-and-tensorcircuit-ng) with TensorCircuit with more new features and bug fixes (support numpy>2 and qiskit>1).
3333

3434
## Getting Started
3535

requirements/requirements-extra.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ torch==2.2.2
88
# jupyter
99
mthree==1.1.0
1010
openfermion
11+
pylatexenc

tensorcircuit/abstractcircuit.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,14 @@ def to_openqasm(self, **kws: Any) -> str:
783783
:return: circuit representation in openqasm format
784784
:rtype: str
785785
"""
786-
return self.to_qiskit(enable_instruction=True).qasm(**kws) # type: ignore
786+
qc = self.to_qiskit(enable_instruction=True)
787+
try:
788+
qasm_str = qc.qasm(**kws) # type: ignore
789+
except AttributeError: # qiskit 1.0
790+
from qiskit.qasm2 import dumps
791+
792+
qasm_str = dumps(qc) # type: ignore
793+
return qasm_str # type: ignore
787794

788795
@classmethod
789796
def from_openqasm(

tensorcircuit/compiler/qiskit_compiler.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from ..abstractcircuit import AbstractCircuit
99
from ..circuit import Circuit
10-
from ..translation import qiskit_from_qasm_str_ordered_measure
10+
from ..translation import qiskit_from_qasm_str_ordered_measure, get_qiskit_qasm
1111

1212

1313
def _free_pi(s: str) -> str:
@@ -156,14 +156,14 @@ def qiskit_compile(
156156
ncircuit = RemoveBarriers()(ncircuit)
157157

158158
if output.lower() in ["qasm", "openqasm"]:
159-
r0 = ncircuit.qasm()
159+
r0 = get_qiskit_qasm(ncircuit)
160160

161161
elif output.lower() in ["qiskit", "ibm"]:
162162
r0 = ncircuit
163163

164164
elif output.lower() in ["tc", "tensorcircuit"]:
165-
s = _free_pi(ncircuit.qasm())
166-
r0 = Circuit.from_openqasm(
165+
s = _free_pi(get_qiskit_qasm(ncircuit))
166+
r0 = Circuit.from_openqasm( # type: ignore
167167
s,
168168
keep_measure_order=True,
169169
)

tensorcircuit/translation.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,17 @@
4444
Tensor = Any
4545

4646

47+
def get_qiskit_qasm(qc: Any) -> str:
48+
49+
try:
50+
qasm_str = qc.qasm(**kws) # type: ignore
51+
except AttributeError: # qiskit 1.0
52+
from qiskit.qasm2 import dumps
53+
54+
qasm_str = dumps(qc)
55+
return qasm_str # type: ignore
56+
57+
4758
def perm_matrix(n: int) -> Tensor:
4859
r"""
4960
Generate a permutation matrix P.

0 commit comments

Comments
 (0)