libqasm 0.5.2__cp38-cp38-win_amd64.whl → 0.6.1__cp38-cp38-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
cqasm/v1x/error_model.py DELETED
@@ -1,41 +0,0 @@
1
- import cqasm.v1x.types
2
-
3
- class ErrorModel:
4
- def __init__(self, name, types=None):
5
- super().__init__()
6
- self._name = str(name)
7
- if types is None:
8
- self._types = ()
9
- else:
10
- for typ in types:
11
- if not isinstance(typ, cqasm.v1x.types.Node):
12
- raise TypeError('types must be an iterable of cqasm.v1x.types.Node if specified')
13
- self._types = tuple(types)
14
-
15
- @property
16
- def name(self):
17
- return self._name
18
-
19
- @property
20
- def types(self):
21
- return self._types
22
-
23
- def __str__(self):
24
- return '{}({})'.format(self._name, ', '.join(map(str, self._types)))
25
-
26
-
27
- class ErrorModelRef(object):
28
- def __init__(self, *args, **kwargs):
29
- if not args and not kwargs:
30
- self._data = None
31
- elif len(args) == 1 and not kwargs and (isinstance(args[0], ErrorModel) or args[0] is None):
32
- self._data = args[0]
33
- else:
34
- self._data = ErrorModel(*args, **kwargs)
35
-
36
- @property
37
- def data(self):
38
- return self._data
39
-
40
- def __str__(self):
41
- return 'unresolved' if self._data is None else str(self._data)
cqasm/v1x/instruction.py DELETED
@@ -1,70 +0,0 @@
1
- import cqasm.v1x.types
2
-
3
-
4
- class Instruction(object):
5
- def __init__(
6
- self,
7
- name,
8
- types=None,
9
- allow_conditional=True,
10
- allow_parallel=True,
11
- allow_reused_qubits=False,
12
- allow_different_index_sizes=False
13
- ):
14
- super().__init__()
15
- self._name = str(name)
16
- if types is None:
17
- self._types = ()
18
- else:
19
- for typ in types:
20
- if not isinstance(typ, cqasm.v1x.types.Node):
21
- raise TypeError('types must be an iterable of cqasm.v1x.types.Node if specified')
22
- self._types = tuple(types)
23
- self._allow_conditional = bool(allow_conditional)
24
- self._allow_parallel = bool(allow_parallel)
25
- self._allow_reused_qubits = bool(allow_reused_qubits)
26
- self._allow_different_index_sizes = bool(allow_different_index_sizes)
27
-
28
- @property
29
- def name(self):
30
- return self._name
31
-
32
- @property
33
- def types(self):
34
- return self._types
35
-
36
- @property
37
- def allow_conditional(self):
38
- return self._allow_conditional
39
-
40
- @property
41
- def allow_parallel(self):
42
- return self._allow_parallel
43
-
44
- @property
45
- def allow_reused_qubits(self):
46
- return self._allow_reused_qubits
47
-
48
- @property
49
- def allow_different_index_sizes(self):
50
- return self._allow_different_index_sizes
51
-
52
- def __str__(self):
53
- return '{}({})'.format(self._name, ', '.join(map(str, self._types)))
54
-
55
-
56
- class InstructionRef(object):
57
- def __init__(self, *args, **kwargs):
58
- if not args and not kwargs:
59
- self._data = None
60
- elif len(args) == 1 and not kwargs and (isinstance(args[0], Instruction) or args[0] is None):
61
- self._data = args[0]
62
- else:
63
- self._data = Instruction(*args, **kwargs)
64
-
65
- @property
66
- def data(self):
67
- return self._data
68
-
69
- def __str__(self):
70
- return 'unresolved' if self._data is None else str(self._data)
cqasm/v1x/primitives.py DELETED
@@ -1,177 +0,0 @@
1
- from enum import Enum
2
- import numpy as np
3
-
4
- import cqasm.v1x.error_model
5
- import cqasm.v1x.instruction
6
- import cqasm.v1x.types
7
-
8
- Str = str
9
- Bool = bool
10
- Int = int
11
- Real = float
12
- Complex = complex
13
-
14
-
15
- class Axis(Enum):
16
- X = 0
17
- Y = 1
18
- Z = 2
19
-
20
-
21
- class _Matrix(object):
22
- """Matrix adapter."""
23
-
24
- def __init__(self, data):
25
- super().__init__()
26
- self._data = data
27
- if len(self._data.shape) == 1:
28
- self._ncols = self._data.shape[0]
29
- self._nrows = 1
30
- elif len(self._data.shape) == 2:
31
- self._ncols = self._data.shape[0]
32
- self._nrows = self._data.shape[1]
33
- else:
34
- raise TypeError('expecting a real-valued vector or matrix, got ' + repr(data))
35
-
36
- def size_rows(self):
37
- return self._nrows
38
-
39
- def size_cols(self):
40
- return self._ncols
41
-
42
- def as_raw_data(self):
43
- return self._data.reshape([self._nrows * self._ncols])
44
-
45
- def as_numpy(self):
46
- return self._data
47
-
48
-
49
- class RMatrix(_Matrix):
50
- """Real-valued matrix adapter."""
51
-
52
- def __init__(self, data):
53
- super().__init__(np.array(data, float))
54
-
55
-
56
- class CMatrix(_Matrix):
57
- """Complex-valued matrix adapter."""
58
-
59
- def __init__(self, data):
60
- super().__init__(np.array(data, complex))
61
-
62
-
63
- class Version(tuple):
64
- """cQASM file version number."""
65
-
66
- def __new__(cls, elements):
67
- if isinstance(elements, str):
68
- elements = elements.split('.')
69
- return super(Version, cls).__new__(cls, tuple(map(int, elements)))
70
-
71
-
72
- def serialize(typ, val):
73
- if isinstance(typ, str):
74
- return None
75
- elif typ is Str:
76
- return {'x': val}
77
- elif typ is Bool:
78
- return {'x': val}
79
- elif typ is Int:
80
- return {'x': val}
81
- elif typ is Real:
82
- return {'x': val}
83
- elif typ is Complex:
84
- return {'r': val.real, 'i': val.imag}
85
- elif typ is Axis:
86
- if val == Axis.X:
87
- return {'x': 0}
88
- elif val == Axis.Y:
89
- return {'x': 1}
90
- elif val == Axis.Z:
91
- return {'x': 2}
92
- else:
93
- assert False
94
- elif typ is RMatrix:
95
- return {'c': val.size_cols(), 'd': list(val.as_raw_data())}
96
- elif typ is CMatrix:
97
- data = []
98
- for c in val.as_raw_data():
99
- data.append(c.real)
100
- data.append(c.imag)
101
- return {'c': val.size_cols(), 'd': data}
102
- elif typ is Version:
103
- return {'x': list(val)}
104
- elif typ is cqasm.v1x.error_model.ErrorModelRef:
105
- if val.data is None:
106
- return {}
107
- else:
108
- return {
109
- 'n': val.data.name,
110
- 't': [x.serialize() for x in val.data.types]
111
- }
112
- elif typ is cqasm.v1x.instruction.InstructionRef:
113
- if val.data is None:
114
- return {}
115
- else:
116
- return {
117
- 'n': val.data.name,
118
- 'c': val.data.allow_conditional,
119
- 'p': val.data.allow_parallel,
120
- 'r': val.data.allow_reused_qubits,
121
- 'd': val.data.allow_different_index_sizes,
122
- 't': [x.serialize() for x in val.data.types]
123
- }
124
- else:
125
- assert False
126
-
127
-
128
- def deserialize(typ, val):
129
- if isinstance(typ, str):
130
- return None
131
- elif typ is Str:
132
- return Str(val['x'])
133
- elif typ is Bool:
134
- return Bool(val['x'])
135
- elif typ is Int:
136
- return Int(val['x'])
137
- elif typ is Real:
138
- return Real(val['x'])
139
- elif typ is Complex:
140
- return Complex(val['r'], val['i'])
141
- elif typ is Axis:
142
- if val['x'] == 0:
143
- return Axis.X
144
- elif val['x'] == 1:
145
- return Axis.Y
146
- elif val['x'] == 2:
147
- return Axis.Z
148
- else:
149
- assert False
150
- elif typ is RMatrix:
151
- return RMatrix(np.array(val['d'], dtype=float).reshape([val['c'], len(val['d']) // val['c']]))
152
- elif typ is CMatrix:
153
- return CMatrix(np.array(val['d'], dtype=complex).reshape([val['c'], len(val['d']) // val['c']]))
154
- elif typ is Version:
155
- return Version(val['x'])
156
- elif typ is cqasm.v1x.error_model.ErrorModelRef:
157
- if 'n' in val:
158
- return cqasm.v1x.error_model.ErrorModelRef(
159
- val['n'],
160
- [cqasm.v1x.types.Node.deserialize(x) for x in val['t']]
161
- )
162
- else:
163
- return cqasm.v1x.error_model.ErrorModelRef()
164
- elif typ is cqasm.v1x.instruction.InstructionRef:
165
- if 'n' in val:
166
- return cqasm.v1x.instruction.InstructionRef(
167
- val['n'],
168
- [cqasm.v1x.types.Node.deserialize(x) for x in val['t']],
169
- val['c'],
170
- val['p'],
171
- val['r'],
172
- val['d']
173
- )
174
- else:
175
- return cqasm.v1x.instruction.InstructionRef()
176
- else:
177
- assert False