Skip to content

Commit d95848d

Browse files
committed
Try to decouple tq and qiskit, works on cuquantum qaoa example
1 parent 5ad32eb commit d95848d

File tree

21 files changed

+232
-124
lines changed

21 files changed

+232
-124
lines changed

examples/cuquantum/qaoa.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212

1313

1414

15-
16-
1715
class MAXCUT(nn.Module):
1816
def __init__(self, n_wires, input_graph, n_layers):
1917
super().__init__()

torchquantum/__init__.py

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,30 +35,36 @@
3535
from .layer import *
3636
from .encoding import *
3737
from .util import *
38-
from .noise_model import *
38+
# Note: noise_model requires qiskit and is not imported by default
39+
# from .noise_model import *
3940
from .algorithm import *
4041
from .dataset import *
4142
from .pulse import *
4243

4344
# here we check whether the Qiskit parameterization bug is fixed, if not, a
4445
# warning message will be printed
45-
import qiskit
46-
import os
46+
# This is only done if qiskit is available
47+
try:
48+
import qiskit
49+
import os
4750

48-
path = os.path.abspath(qiskit.__file__)
49-
# print(path)
50-
# path for aer provider
51-
path_provider = path.replace("__init__.py", "providers/aer/backends/aerbackend.py")
52-
# print(path_provider)
51+
path = os.path.abspath(qiskit.__file__)
52+
# print(path)
53+
# path for aer provider
54+
path_provider = path.replace("__init__.py", "providers/aer/backends/aerbackend.py")
55+
# print(path_provider)
5356

54-
# with open(path_provider, 'r') as fid:
55-
# for line in fid.readlines():
56-
# if 'FIXED' in line:
57-
# # print('The qiskit parameterization bug is already fixed!')
58-
# break
59-
# else:
60-
# print(f'\n\n WARNING: The qiskit parameterization bug is not '
61-
# f'fixed!\n\n'
62-
# f'run python fix_qiskit_parameterization.py to fix it!'
63-
# )
64-
# break
57+
# with open(path_provider, 'r') as fid:
58+
# for line in fid.readlines():
59+
# if 'FIXED' in line:
60+
# # print('The qiskit parameterization bug is already fixed!')
61+
# break
62+
# else:
63+
# print(f'\n\n WARNING: The qiskit parameterization bug is not '
64+
# f'fixed!\n\n'
65+
# f'run python fix_qiskit_parameterization.py to fix it!'
66+
# )
67+
# break
68+
except ImportError:
69+
# qiskit not available, skip the check
70+
pass

torchquantum/layer/entanglement/entanglement.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
from .op2_layer import Op2QAllLayer
3636

3737
from typing import Iterable
38-
from torchquantum.plugin.qiskit import QISKIT_INCOMPATIBLE_FUNC_NAMES
38+
from torchquantum.util.constants import QISKIT_INCOMPATIBLE_FUNC_NAMES
3939
from torchpack.utils.logging import logger
4040

4141
__all__ = [

torchquantum/layer/entanglement/op2_layer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131

3232
from typing import Iterable
33-
from torchquantum.plugin.qiskit import QISKIT_INCOMPATIBLE_FUNC_NAMES
33+
from torchquantum.util.constants import QISKIT_INCOMPATIBLE_FUNC_NAMES
3434
from torchpack.utils.logging import logger
3535

3636
__all__ = [

torchquantum/layer/layers/cx_layer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import numpy as np
3030

3131
from typing import Iterable
32-
from torchquantum.plugin.qiskit import QISKIT_INCOMPATIBLE_FUNC_NAMES
32+
from torchquantum.util.constants import QISKIT_INCOMPATIBLE_FUNC_NAMES
3333
from torchpack.utils.logging import logger
3434

3535

torchquantum/layer/layers/layers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import numpy as np
3030

3131
from typing import Iterable
32-
from torchquantum.plugin.qiskit import QISKIT_INCOMPATIBLE_FUNC_NAMES
32+
from torchquantum.util.constants import QISKIT_INCOMPATIBLE_FUNC_NAMES
3333
from torchpack.utils.logging import logger
3434
from torchquantum.layer.entanglement.op2_layer import Op2QAllLayer
3535

torchquantum/layer/layers/module_from_ops.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131

3232
from typing import Iterable
33-
from torchquantum.plugin.qiskit import QISKIT_INCOMPATIBLE_FUNC_NAMES
33+
from torchquantum.util.constants import QISKIT_INCOMPATIBLE_FUNC_NAMES
3434
from torchpack.utils.logging import logger
3535

3636
__all__ = [

torchquantum/layer/layers/op_all.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131

3232
from typing import Iterable
33-
from torchquantum.plugin.qiskit import QISKIT_INCOMPATIBLE_FUNC_NAMES
33+
from torchquantum.util.constants import QISKIT_INCOMPATIBLE_FUNC_NAMES
3434
from torchpack.utils.logging import logger
3535

3636
__all__ = [

torchquantum/layer/layers/qft_layer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import numpy as np
66

77
from typing import Iterable
8-
from torchquantum.plugin.qiskit import QISKIT_INCOMPATIBLE_FUNC_NAMES
8+
from torchquantum.util.constants import QISKIT_INCOMPATIBLE_FUNC_NAMES
99
from torchpack.utils.logging import logger
1010

1111
class QFTLayer(tq.QuantumModule):

torchquantum/layer/layers/random_layers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import numpy as np
3030

3131
from typing import Iterable
32-
from torchquantum.plugin.qiskit import QISKIT_INCOMPATIBLE_FUNC_NAMES
32+
from torchquantum.util.constants import QISKIT_INCOMPATIBLE_FUNC_NAMES
3333
from torchpack.utils.logging import logger
3434

3535
__all__ = [

0 commit comments

Comments
 (0)