@@ -29,26 +29,29 @@ class DepolarizingNoiseModel(devices.NoiseModel):
29
29
also contain gates.
30
30
"""
31
31
32
- def __init__ (self , depol_prob : float ):
32
+ def __init__ (self , depol_prob : float , prepend : bool = False ):
33
33
"""A depolarizing noise model
34
34
35
35
Args:
36
36
depol_prob: Depolarizing probability.
37
+ prepend: If True, put noise before affected gates. Default: False.
37
38
"""
38
39
value .validate_probability (depol_prob , 'depol prob' )
39
40
self .qubit_noise_gate = ops .DepolarizingChannel (depol_prob )
41
+ self ._prepend = prepend
40
42
41
43
def noisy_moment (self , moment : 'cirq.Moment' , system_qubits : Sequence ['cirq.Qid' ]):
42
44
if validate_all_measurements (moment ) or self .is_virtual_moment (moment ):
43
45
# coverage: ignore
44
46
return moment
45
47
46
- return [
48
+ output = [
47
49
moment ,
48
50
circuits .Moment (
49
51
self .qubit_noise_gate (q ).with_tags (ops .VirtualTag ()) for q in system_qubits
50
52
),
51
53
]
54
+ return output [::- 1 ] if self ._prepend else output
52
55
53
56
54
57
class ReadoutNoiseModel (devices .NoiseModel ):
@@ -63,25 +66,28 @@ class ReadoutNoiseModel(devices.NoiseModel):
63
66
also contain gates.
64
67
"""
65
68
66
- def __init__ (self , bitflip_prob : float ):
69
+ def __init__ (self , bitflip_prob : float , prepend : bool = True ):
67
70
"""A noise model with readout error.
68
71
69
72
Args:
70
73
bitflip_prob: Probability of a bit-flip during measurement.
74
+ prepend: If True, put noise before affected gates. Default: True.
71
75
"""
72
76
value .validate_probability (bitflip_prob , 'bitflip prob' )
73
77
self .readout_noise_gate = ops .BitFlipChannel (bitflip_prob )
78
+ self ._prepend = prepend
74
79
75
80
def noisy_moment (self , moment : 'cirq.Moment' , system_qubits : Sequence ['cirq.Qid' ]):
76
81
if self .is_virtual_moment (moment ):
77
82
return moment
78
83
if validate_all_measurements (moment ):
79
- return [
84
+ output = [
80
85
circuits .Moment (
81
86
self .readout_noise_gate (q ).with_tags (ops .VirtualTag ()) for q in system_qubits
82
87
),
83
88
moment ,
84
89
]
90
+ return output if self ._prepend else output [::- 1 ]
85
91
return moment
86
92
87
93
@@ -97,25 +103,28 @@ class DampedReadoutNoiseModel(devices.NoiseModel):
97
103
also contain gates.
98
104
"""
99
105
100
- def __init__ (self , decay_prob : float ):
106
+ def __init__ (self , decay_prob : float , prepend : bool = True ):
101
107
"""A depolarizing noise model with damped readout error.
102
108
103
109
Args:
104
110
decay_prob: Probability of T1 decay during measurement.
111
+ prepend: If True, put noise before affected gates. Default: True.
105
112
"""
106
113
value .validate_probability (decay_prob , 'decay_prob' )
107
114
self .readout_decay_gate = ops .AmplitudeDampingChannel (decay_prob )
115
+ self ._prepend = prepend
108
116
109
117
def noisy_moment (self , moment : 'cirq.Moment' , system_qubits : Sequence ['cirq.Qid' ]):
110
118
if self .is_virtual_moment (moment ):
111
119
return moment
112
120
if validate_all_measurements (moment ):
113
- return [
121
+ output = [
114
122
circuits .Moment (
115
123
self .readout_decay_gate (q ).with_tags (ops .VirtualTag ()) for q in system_qubits
116
124
),
117
125
moment ,
118
126
]
127
+ return output if self ._prepend else output [::- 1 ]
119
128
return moment
120
129
121
130
0 commit comments