@@ -34,9 +34,9 @@ class NoiseModel(ABC):
34
34
or negative. When the size of the gate is higher than the number of target qubits.
35
35
"""
36
36
37
- def __init__ (self , targets : list [ int ], gates : Optional [ list [ type [ Gate ]]] = None ):
38
- if len ( targets ) == 0 :
39
- raise ValueError ( "Expected non-empty target list" )
37
+ def __init__ (
38
+ self , targets : list [ int ] = [], gates : Optional [ list [ type [ Gate ]]] = None
39
+ ):
40
40
41
41
if len (set (targets )) != len (targets ):
42
42
raise ValueError (f"Duplicate indices in targets: { targets } " )
@@ -53,7 +53,9 @@ def __init__(self, targets: list[int], gates: Optional[list[type[Gate]]] = None)
53
53
" the noise target, please add `nb_qubits` to this "
54
54
"class as a class attribute."
55
55
)
56
- if nb_qubits > len (targets ): # pyright: ignore[reportOperatorIssue]
56
+ if len (targets ) != 0 and nb_qubits > len (
57
+ targets
58
+ ): # pyright: ignore[reportOperatorIssue]
57
59
raise ValueError (
58
60
"Size mismatch between gate and noise: gate size is "
59
61
f"{ nb_qubits } but noise size is { len (targets )} "
@@ -125,30 +127,32 @@ class Depolarizing(NoiseModel):
125
127
Examples:
126
128
>>> circuit = QCircuit([H(i) for i in range(3)])
127
129
>>> d1 = Depolarizing(0.32, list(range(circuit.nb_qubits)))
128
- >>> d2 = Depolarizing(0.05, [0, 1], dimension=2)
129
- >>> d3 = Depolarizing(0.12, [2], gates=[H, Rx, Ry, Rz])
130
- >>> d4 = Depolarizing(0.05, [0, 1, 2], dimension=2, gates=[CNOT, CZ])
131
- >>> circuit.add([d1, d2, d3, d4])
130
+ >>> d2 = Depolarizing(0.01)
131
+ >>> d3 = Depolarizing(0.05, [0, 1], dimension=2)
132
+ >>> d4 = Depolarizing(0.12, [2], gates=[H, Rx, Ry, Rz])
133
+ >>> d5 = Depolarizing(0.05, [0, 1, 2], dimension=2, gates=[CNOT, CZ])
134
+ >>> circuit.add([d1, d2, d3, d4, d5])
132
135
>>> print(circuit) # doctest: +NORMALIZE_WHITESPACE
133
- ┌───┐
134
- q_0: ┤ H ├
135
- ├───┤
136
- q_1: ┤ H ├
137
- ├───┤
138
- q_2: ┤ H ├
139
- └───┘
140
- NoiseModel:
141
- Depolarizing(0.32, [0, 1, 2], 1)
142
- Depolarizing(0.05, [0, 1], 2)
143
- Depolarizing(0.12, [2], 1, [H, Rx, Ry, Rz])
144
- Depolarizing(0.05, [0, 1, 2], 2, [CNOT, CZ])
136
+ ┌───┐
137
+ q_0: ┤ H ├
138
+ ├───┤
139
+ q_1: ┤ H ├
140
+ ├───┤
141
+ q_2: ┤ H ├
142
+ └───┘
143
+ NoiseModel:
144
+ Depolarizing(0.32, [0, 1, 2], 1)
145
+ Depolarizing(0.01, [0, 1, 2], 1)
146
+ Depolarizing(0.05, [0, 1], 2)
147
+ Depolarizing(0.12, [2], 1, [H, Rx, Ry, Rz])
148
+ Depolarizing(0.05, [0, 1, 2], 2, [CNOT, CZ])
145
149
146
150
"""
147
151
148
152
def __init__ (
149
153
self ,
150
154
prob : float ,
151
- targets : list [int ],
155
+ targets : list [int ] = [] ,
152
156
dimension : int = 1 ,
153
157
gates : Optional [list [type [Gate ]]] = None ,
154
158
):
@@ -179,7 +183,7 @@ def __init__(
179
183
)
180
184
181
185
nb_targets = len (targets )
182
- if nb_targets < dimension :
186
+ if nb_targets != 0 and nb_targets < dimension :
183
187
raise ValueError (
184
188
f"Number of target qubits { nb_targets } should be higher than the dimension { dimension } ."
185
189
)
0 commit comments