hqm.noise.randomcircuit
1from types import FunctionType 2import pennylane as qml 3import numpy as np 4import random 5import sys 6 7sys.path += ['.', './ciruits/'] 8 9from hqm.circuits.circuit import QuantumCircuit 10 11class RandomCircuitNoiseGenerator(QuantumCircuit): 12 ''' 13 This class implements a quantum noise generator using a random circuit for each sample. 14 ''' 15 16 def __init__(self, location : float, scale : float, n_qubits: int, n_layers : int, dev : qml.devices = None) -> None: 17 ''' 18 RandomCircuitNoiseGenerator constructor. 19 20 Parameters: 21 ----------- 22 - location : float 23 location parameter translate the pdf, relative to the standard normal distribution 24 - scale : float 25 scale parameter that stretches the pdf. The greater the magnitude, the greater the stretching. 26 - n_qubits : int 27 number of qubits for the quantum circuit 28 - n_layers : int 29 number of layers for the quantum circuit 30 - dev : qml.device 31 PennyLane device on wich run quantum operations (dafault : None). When None it will be set 32 to 'default.qubit'. Recommendent qml.device("default.mixed", wires=1, shots=1000). 33 34 Returns: 35 -------- 36 Nothing, a RandomCircuitNoiseGenerator object will be created. 37 ''' 38 39 super().__init__(n_qubits=n_qubits, n_layers=n_layers, dev=dev) 40 41 self.shots = dev.shots 42 self.location = location 43 self.scale = scale 44 self.n_qubits = n_qubits 45 self.n_layers = n_layers 46 self.dev = dev 47 48 def generate_noise(self): 49 ''' 50 GaussianLikeNoiseGenerator that generates on observable 51 52 Parameters: 53 ----------- 54 Nothing 55 56 Returns: 57 -------- 58 n : float 59 gaussianlike quantum noise observable 60 ''' 61 expval = self.circ(self.dev) 62 n = self.location + self.scale*expval 63 return n 64 65 66 def generate_noise_array(self, shape:tuple): 67 ''' 68 GaussianLikeNoiseGenerator that generates a matrix of observables 69 70 Parameters: 71 ----------- 72 shape : tuple 73 shape of the desired maxtrix of observables 74 75 Returns: 76 -------- 77 n : float 78 gaussianlike quantum noise matrix of observables 79 ''' 80 n = [] 81 for _ in range(np.prod(shape)): n.append(self.generate_noise()) 82 n = np.array(n) 83 84 return n.reshape(shape) 85 86 def circ(self, dev : qml.devices) -> FunctionType: 87 ''' 88 GaussianLikeNoiseGenerator method that implements the quantum circuit. 89 90 Parameters: 91 ----------- 92 - dev : qml.device 93 PennyLane device on wich run quantum operations (dafault : None). When None it will be set 94 to 'default.qubit' 95 96 Returns: 97 -------- 98 - qnode : qml.qnode 99 the actual PennyLane circuit 100 ''' 101 102 @qml.qnode(dev) 103 def qnode() -> dict: 104 ''' 105 PennyLane based quantum circuit composed of a Ry gate 106 107 Parameters: 108 ----------- 109 Nothing 110 111 Returns: 112 -------- 113 - counts : dict 114 Sample from the supplied observable, with the number of shots determined from the dev.shots attribute of the corresponding device, 115 returning the number of counts for each sample. If no observable is provided then basis state samples are returned directly 116 from the device. Note that the output shape of this measurement process depends on the shots specified on the device. 117 ''' 118 119 qml.RandomLayers(np.random.random((len(dev.wires),self.n_layers)), range(len(dev.wires))) 120 return qml.expval(qml.PauliZ(0)) 121 122 return qnode() 123 124class RandomCZNoiseGenerator(QuantumCircuit): 125 ''' 126 This class implements a quantum noise generator using a random circuit 127 ''' 128 129 def __init__(self, location : float, scale : float, n_qubits: int, n_layers : int, n_entangling_layers : int = 2, bit_string : bool = True, state_id : int = 0, dev : qml.devices = None) -> None: 130 ''' 131 RandomCircuitNoiseGenerator constructor. 132 133 Parameters: 134 ----------- 135 - location : float 136 location parameter translate the pdf, relative to the standard normal distribution 137 - scale : float 138 scale parameter that stretches the pdf. The greater the magnitude, the greater the stretching. 139 - n_qubits : int 140 number of qubits for the quantum circuit 141 - n_layers : int 142 number of layers for the quantum circuit 143 - n_entangling_layers : int 144 number of layers with entanglement 145 - state_id : int 146 name of the state to consider 147 - dev : qml.device 148 PennyLane device on wich run quantum operations (dafault : None). When None it will be set 149 to 'default.qubit'. Recommendent qml.device("default.mixed", wires=1, shots=1000). 150 151 Returns: 152 -------- 153 Nothing, a RandomCircuitNoiseGenerator object will be created. 154 ''' 155 156 super().__init__(n_qubits=n_qubits, n_layers=n_layers, dev=dev) 157 158 self.shots = dev.shots 159 self.location = location 160 self.scale = scale 161 self.n_qubits = n_qubits 162 self.n_layers = n_layers 163 self.n_entangling_layers = n_entangling_layers 164 self.bit_string = bit_string 165 self.state_id = state_id 166 self.dev = dev 167 self.circuit = self.circ(self.dev) 168 169 def generate_noise(self): 170 ''' 171 GaussianLikeNoiseGenerator that generates on observable 172 173 Parameters: 174 ----------- 175 Nothing 176 177 Returns: 178 -------- 179 n : float 180 gaussianlike quantum noise observable 181 ''' 182 if self.bit_string: 183 unitary_probs = self.circuit() 184 state_id = np.random.choice(2**self.n_qubits, p=unitary_probs) 185 expval = unitary_probs[state_id] 186 else: 187 expval = self.circuit()[self.state_id] 188 189 n = self.location + self.scale*expval 190 return n 191 192 193 def generate_noise_array(self, shape:tuple): 194 ''' 195 GaussianLikeNoiseGenerator that generates a matrix of observables 196 197 Parameters: 198 ----------- 199 shape : tuple 200 shape of the desired maxtrix of observables 201 202 Returns: 203 -------- 204 n : float 205 gaussianlike quantum noise matrix of observables 206 ''' 207 n = [] 208 for _ in range(np.prod(shape)): n.append(self.generate_noise()) 209 n = np.array(n) 210 211 return n.reshape(shape) 212 213 def circ(self, dev : qml.devices) -> FunctionType: 214 ''' 215 GaussianLikeNoiseGenerator method that implements the quantum circuit. 216 217 Parameters: 218 ----------- 219 - dev : qml.device 220 PennyLane device on wich run quantum operations (dafault : None). When None it will be set 221 to 'default.qubit' 222 223 Returns: 224 -------- 225 - qnode : qml.qnode 226 the actual PennyLane circuit 227 ''' 228 229 @qml.qnode(dev) 230 def qnode() -> dict: 231 ''' 232 PennyLane based quantum circuit composed of a Ry gate 233 234 Parameters: 235 ----------- 236 Nothing 237 238 Returns: 239 -------- 240 - counts : dict 241 Sample from the supplied observable, with the number of shots determined from the dev.shots attribute of the corresponding device, 242 returning the number of counts for each sample. If no observable is provided then basis state samples are returned directly 243 from the device. Note that the output shape of this measurement process depends on the shots specified on the device. 244 ''' 245 246 for _ in range(self.n_layers): 247 for j in range(self.n_qubits): 248 249 qml.Hadamard(wires=j) 250 rZ = 2*np.pi*random.random() 251 qml.RZ(rZ,wires=j) 252 253 rY = 2*np.pi*random.random() 254 qml.RY(rY,wires=j) 255 256 for _ in range(self.n_entangling_layers): 257 r = random.sample(range(0, self.n_qubits), 2) 258 qml.CZ(wires=r) 259 260 #qml.CZ(wires=r) 261 # Hadamards 262 qml.Barrier() 263 for i in range(self.n_qubits): qml.Hadamard(wires=i) 264 265 return qml.probs(wires=range(0,self.n_qubits)) 266 267 return qnode
12class RandomCircuitNoiseGenerator(QuantumCircuit): 13 ''' 14 This class implements a quantum noise generator using a random circuit for each sample. 15 ''' 16 17 def __init__(self, location : float, scale : float, n_qubits: int, n_layers : int, dev : qml.devices = None) -> None: 18 ''' 19 RandomCircuitNoiseGenerator constructor. 20 21 Parameters: 22 ----------- 23 - location : float 24 location parameter translate the pdf, relative to the standard normal distribution 25 - scale : float 26 scale parameter that stretches the pdf. The greater the magnitude, the greater the stretching. 27 - n_qubits : int 28 number of qubits for the quantum circuit 29 - n_layers : int 30 number of layers for the quantum circuit 31 - dev : qml.device 32 PennyLane device on wich run quantum operations (dafault : None). When None it will be set 33 to 'default.qubit'. Recommendent qml.device("default.mixed", wires=1, shots=1000). 34 35 Returns: 36 -------- 37 Nothing, a RandomCircuitNoiseGenerator object will be created. 38 ''' 39 40 super().__init__(n_qubits=n_qubits, n_layers=n_layers, dev=dev) 41 42 self.shots = dev.shots 43 self.location = location 44 self.scale = scale 45 self.n_qubits = n_qubits 46 self.n_layers = n_layers 47 self.dev = dev 48 49 def generate_noise(self): 50 ''' 51 GaussianLikeNoiseGenerator that generates on observable 52 53 Parameters: 54 ----------- 55 Nothing 56 57 Returns: 58 -------- 59 n : float 60 gaussianlike quantum noise observable 61 ''' 62 expval = self.circ(self.dev) 63 n = self.location + self.scale*expval 64 return n 65 66 67 def generate_noise_array(self, shape:tuple): 68 ''' 69 GaussianLikeNoiseGenerator that generates a matrix of observables 70 71 Parameters: 72 ----------- 73 shape : tuple 74 shape of the desired maxtrix of observables 75 76 Returns: 77 -------- 78 n : float 79 gaussianlike quantum noise matrix of observables 80 ''' 81 n = [] 82 for _ in range(np.prod(shape)): n.append(self.generate_noise()) 83 n = np.array(n) 84 85 return n.reshape(shape) 86 87 def circ(self, dev : qml.devices) -> FunctionType: 88 ''' 89 GaussianLikeNoiseGenerator method that implements the quantum circuit. 90 91 Parameters: 92 ----------- 93 - dev : qml.device 94 PennyLane device on wich run quantum operations (dafault : None). When None it will be set 95 to 'default.qubit' 96 97 Returns: 98 -------- 99 - qnode : qml.qnode 100 the actual PennyLane circuit 101 ''' 102 103 @qml.qnode(dev) 104 def qnode() -> dict: 105 ''' 106 PennyLane based quantum circuit composed of a Ry gate 107 108 Parameters: 109 ----------- 110 Nothing 111 112 Returns: 113 -------- 114 - counts : dict 115 Sample from the supplied observable, with the number of shots determined from the dev.shots attribute of the corresponding device, 116 returning the number of counts for each sample. If no observable is provided then basis state samples are returned directly 117 from the device. Note that the output shape of this measurement process depends on the shots specified on the device. 118 ''' 119 120 qml.RandomLayers(np.random.random((len(dev.wires),self.n_layers)), range(len(dev.wires))) 121 return qml.expval(qml.PauliZ(0)) 122 123 return qnode()
This class implements a quantum noise generator using a random circuit for each sample.
17 def __init__(self, location : float, scale : float, n_qubits: int, n_layers : int, dev : qml.devices = None) -> None: 18 ''' 19 RandomCircuitNoiseGenerator constructor. 20 21 Parameters: 22 ----------- 23 - location : float 24 location parameter translate the pdf, relative to the standard normal distribution 25 - scale : float 26 scale parameter that stretches the pdf. The greater the magnitude, the greater the stretching. 27 - n_qubits : int 28 number of qubits for the quantum circuit 29 - n_layers : int 30 number of layers for the quantum circuit 31 - dev : qml.device 32 PennyLane device on wich run quantum operations (dafault : None). When None it will be set 33 to 'default.qubit'. Recommendent qml.device("default.mixed", wires=1, shots=1000). 34 35 Returns: 36 -------- 37 Nothing, a RandomCircuitNoiseGenerator object will be created. 38 ''' 39 40 super().__init__(n_qubits=n_qubits, n_layers=n_layers, dev=dev) 41 42 self.shots = dev.shots 43 self.location = location 44 self.scale = scale 45 self.n_qubits = n_qubits 46 self.n_layers = n_layers 47 self.dev = dev
RandomCircuitNoiseGenerator constructor.
Parameters:
- location : float
location parameter translate the pdf, relative to the standard normal distribution - scale : float
scale parameter that stretches the pdf. The greater the magnitude, the greater the stretching. - n_qubits : int
number of qubits for the quantum circuit - n_layers : int
number of layers for the quantum circuit - dev : qml.device
PennyLane device on wich run quantum operations (dafault : None). When None it will be set to 'default.qubit'. Recommendent qml.device("default.mixed", wires=1, shots=1000).
Returns:
Nothing, a RandomCircuitNoiseGenerator object will be created.
49 def generate_noise(self): 50 ''' 51 GaussianLikeNoiseGenerator that generates on observable 52 53 Parameters: 54 ----------- 55 Nothing 56 57 Returns: 58 -------- 59 n : float 60 gaussianlike quantum noise observable 61 ''' 62 expval = self.circ(self.dev) 63 n = self.location + self.scale*expval 64 return n
GaussianLikeNoiseGenerator that generates on observable
Parameters:
Nothing
Returns:
n : float gaussianlike quantum noise observable
67 def generate_noise_array(self, shape:tuple): 68 ''' 69 GaussianLikeNoiseGenerator that generates a matrix of observables 70 71 Parameters: 72 ----------- 73 shape : tuple 74 shape of the desired maxtrix of observables 75 76 Returns: 77 -------- 78 n : float 79 gaussianlike quantum noise matrix of observables 80 ''' 81 n = [] 82 for _ in range(np.prod(shape)): n.append(self.generate_noise()) 83 n = np.array(n) 84 85 return n.reshape(shape)
GaussianLikeNoiseGenerator that generates a matrix of observables
Parameters:
shape : tuple shape of the desired maxtrix of observables
Returns:
n : float gaussianlike quantum noise matrix of observables
87 def circ(self, dev : qml.devices) -> FunctionType: 88 ''' 89 GaussianLikeNoiseGenerator method that implements the quantum circuit. 90 91 Parameters: 92 ----------- 93 - dev : qml.device 94 PennyLane device on wich run quantum operations (dafault : None). When None it will be set 95 to 'default.qubit' 96 97 Returns: 98 -------- 99 - qnode : qml.qnode 100 the actual PennyLane circuit 101 ''' 102 103 @qml.qnode(dev) 104 def qnode() -> dict: 105 ''' 106 PennyLane based quantum circuit composed of a Ry gate 107 108 Parameters: 109 ----------- 110 Nothing 111 112 Returns: 113 -------- 114 - counts : dict 115 Sample from the supplied observable, with the number of shots determined from the dev.shots attribute of the corresponding device, 116 returning the number of counts for each sample. If no observable is provided then basis state samples are returned directly 117 from the device. Note that the output shape of this measurement process depends on the shots specified on the device. 118 ''' 119 120 qml.RandomLayers(np.random.random((len(dev.wires),self.n_layers)), range(len(dev.wires))) 121 return qml.expval(qml.PauliZ(0)) 122 123 return qnode()
GaussianLikeNoiseGenerator method that implements the quantum circuit.
Parameters:
- dev : qml.device
PennyLane device on wich run quantum operations (dafault : None). When None it will be set
to 'default.qubit'
Returns:
- qnode : qml.qnode
the actual PennyLane circuit
125class RandomCZNoiseGenerator(QuantumCircuit): 126 ''' 127 This class implements a quantum noise generator using a random circuit 128 ''' 129 130 def __init__(self, location : float, scale : float, n_qubits: int, n_layers : int, n_entangling_layers : int = 2, bit_string : bool = True, state_id : int = 0, dev : qml.devices = None) -> None: 131 ''' 132 RandomCircuitNoiseGenerator constructor. 133 134 Parameters: 135 ----------- 136 - location : float 137 location parameter translate the pdf, relative to the standard normal distribution 138 - scale : float 139 scale parameter that stretches the pdf. The greater the magnitude, the greater the stretching. 140 - n_qubits : int 141 number of qubits for the quantum circuit 142 - n_layers : int 143 number of layers for the quantum circuit 144 - n_entangling_layers : int 145 number of layers with entanglement 146 - state_id : int 147 name of the state to consider 148 - dev : qml.device 149 PennyLane device on wich run quantum operations (dafault : None). When None it will be set 150 to 'default.qubit'. Recommendent qml.device("default.mixed", wires=1, shots=1000). 151 152 Returns: 153 -------- 154 Nothing, a RandomCircuitNoiseGenerator object will be created. 155 ''' 156 157 super().__init__(n_qubits=n_qubits, n_layers=n_layers, dev=dev) 158 159 self.shots = dev.shots 160 self.location = location 161 self.scale = scale 162 self.n_qubits = n_qubits 163 self.n_layers = n_layers 164 self.n_entangling_layers = n_entangling_layers 165 self.bit_string = bit_string 166 self.state_id = state_id 167 self.dev = dev 168 self.circuit = self.circ(self.dev) 169 170 def generate_noise(self): 171 ''' 172 GaussianLikeNoiseGenerator that generates on observable 173 174 Parameters: 175 ----------- 176 Nothing 177 178 Returns: 179 -------- 180 n : float 181 gaussianlike quantum noise observable 182 ''' 183 if self.bit_string: 184 unitary_probs = self.circuit() 185 state_id = np.random.choice(2**self.n_qubits, p=unitary_probs) 186 expval = unitary_probs[state_id] 187 else: 188 expval = self.circuit()[self.state_id] 189 190 n = self.location + self.scale*expval 191 return n 192 193 194 def generate_noise_array(self, shape:tuple): 195 ''' 196 GaussianLikeNoiseGenerator that generates a matrix of observables 197 198 Parameters: 199 ----------- 200 shape : tuple 201 shape of the desired maxtrix of observables 202 203 Returns: 204 -------- 205 n : float 206 gaussianlike quantum noise matrix of observables 207 ''' 208 n = [] 209 for _ in range(np.prod(shape)): n.append(self.generate_noise()) 210 n = np.array(n) 211 212 return n.reshape(shape) 213 214 def circ(self, dev : qml.devices) -> FunctionType: 215 ''' 216 GaussianLikeNoiseGenerator method that implements the quantum circuit. 217 218 Parameters: 219 ----------- 220 - dev : qml.device 221 PennyLane device on wich run quantum operations (dafault : None). When None it will be set 222 to 'default.qubit' 223 224 Returns: 225 -------- 226 - qnode : qml.qnode 227 the actual PennyLane circuit 228 ''' 229 230 @qml.qnode(dev) 231 def qnode() -> dict: 232 ''' 233 PennyLane based quantum circuit composed of a Ry gate 234 235 Parameters: 236 ----------- 237 Nothing 238 239 Returns: 240 -------- 241 - counts : dict 242 Sample from the supplied observable, with the number of shots determined from the dev.shots attribute of the corresponding device, 243 returning the number of counts for each sample. If no observable is provided then basis state samples are returned directly 244 from the device. Note that the output shape of this measurement process depends on the shots specified on the device. 245 ''' 246 247 for _ in range(self.n_layers): 248 for j in range(self.n_qubits): 249 250 qml.Hadamard(wires=j) 251 rZ = 2*np.pi*random.random() 252 qml.RZ(rZ,wires=j) 253 254 rY = 2*np.pi*random.random() 255 qml.RY(rY,wires=j) 256 257 for _ in range(self.n_entangling_layers): 258 r = random.sample(range(0, self.n_qubits), 2) 259 qml.CZ(wires=r) 260 261 #qml.CZ(wires=r) 262 # Hadamards 263 qml.Barrier() 264 for i in range(self.n_qubits): qml.Hadamard(wires=i) 265 266 return qml.probs(wires=range(0,self.n_qubits)) 267 268 return qnode
This class implements a quantum noise generator using a random circuit
130 def __init__(self, location : float, scale : float, n_qubits: int, n_layers : int, n_entangling_layers : int = 2, bit_string : bool = True, state_id : int = 0, dev : qml.devices = None) -> None: 131 ''' 132 RandomCircuitNoiseGenerator constructor. 133 134 Parameters: 135 ----------- 136 - location : float 137 location parameter translate the pdf, relative to the standard normal distribution 138 - scale : float 139 scale parameter that stretches the pdf. The greater the magnitude, the greater the stretching. 140 - n_qubits : int 141 number of qubits for the quantum circuit 142 - n_layers : int 143 number of layers for the quantum circuit 144 - n_entangling_layers : int 145 number of layers with entanglement 146 - state_id : int 147 name of the state to consider 148 - dev : qml.device 149 PennyLane device on wich run quantum operations (dafault : None). When None it will be set 150 to 'default.qubit'. Recommendent qml.device("default.mixed", wires=1, shots=1000). 151 152 Returns: 153 -------- 154 Nothing, a RandomCircuitNoiseGenerator object will be created. 155 ''' 156 157 super().__init__(n_qubits=n_qubits, n_layers=n_layers, dev=dev) 158 159 self.shots = dev.shots 160 self.location = location 161 self.scale = scale 162 self.n_qubits = n_qubits 163 self.n_layers = n_layers 164 self.n_entangling_layers = n_entangling_layers 165 self.bit_string = bit_string 166 self.state_id = state_id 167 self.dev = dev 168 self.circuit = self.circ(self.dev)
RandomCircuitNoiseGenerator constructor.
Parameters:
- location : float
location parameter translate the pdf, relative to the standard normal distribution - scale : float
scale parameter that stretches the pdf. The greater the magnitude, the greater the stretching. - n_qubits : int
number of qubits for the quantum circuit - n_layers : int
number of layers for the quantum circuit - n_entangling_layers : int
number of layers with entanglement - state_id : int name of the state to consider
- dev : qml.device
PennyLane device on wich run quantum operations (dafault : None). When None it will be set to 'default.qubit'. Recommendent qml.device("default.mixed", wires=1, shots=1000).
Returns:
Nothing, a RandomCircuitNoiseGenerator object will be created.
170 def generate_noise(self): 171 ''' 172 GaussianLikeNoiseGenerator that generates on observable 173 174 Parameters: 175 ----------- 176 Nothing 177 178 Returns: 179 -------- 180 n : float 181 gaussianlike quantum noise observable 182 ''' 183 if self.bit_string: 184 unitary_probs = self.circuit() 185 state_id = np.random.choice(2**self.n_qubits, p=unitary_probs) 186 expval = unitary_probs[state_id] 187 else: 188 expval = self.circuit()[self.state_id] 189 190 n = self.location + self.scale*expval 191 return n
GaussianLikeNoiseGenerator that generates on observable
Parameters:
Nothing
Returns:
n : float gaussianlike quantum noise observable
194 def generate_noise_array(self, shape:tuple): 195 ''' 196 GaussianLikeNoiseGenerator that generates a matrix of observables 197 198 Parameters: 199 ----------- 200 shape : tuple 201 shape of the desired maxtrix of observables 202 203 Returns: 204 -------- 205 n : float 206 gaussianlike quantum noise matrix of observables 207 ''' 208 n = [] 209 for _ in range(np.prod(shape)): n.append(self.generate_noise()) 210 n = np.array(n) 211 212 return n.reshape(shape)
GaussianLikeNoiseGenerator that generates a matrix of observables
Parameters:
shape : tuple shape of the desired maxtrix of observables
Returns:
n : float gaussianlike quantum noise matrix of observables
214 def circ(self, dev : qml.devices) -> FunctionType: 215 ''' 216 GaussianLikeNoiseGenerator method that implements the quantum circuit. 217 218 Parameters: 219 ----------- 220 - dev : qml.device 221 PennyLane device on wich run quantum operations (dafault : None). When None it will be set 222 to 'default.qubit' 223 224 Returns: 225 -------- 226 - qnode : qml.qnode 227 the actual PennyLane circuit 228 ''' 229 230 @qml.qnode(dev) 231 def qnode() -> dict: 232 ''' 233 PennyLane based quantum circuit composed of a Ry gate 234 235 Parameters: 236 ----------- 237 Nothing 238 239 Returns: 240 -------- 241 - counts : dict 242 Sample from the supplied observable, with the number of shots determined from the dev.shots attribute of the corresponding device, 243 returning the number of counts for each sample. If no observable is provided then basis state samples are returned directly 244 from the device. Note that the output shape of this measurement process depends on the shots specified on the device. 245 ''' 246 247 for _ in range(self.n_layers): 248 for j in range(self.n_qubits): 249 250 qml.Hadamard(wires=j) 251 rZ = 2*np.pi*random.random() 252 qml.RZ(rZ,wires=j) 253 254 rY = 2*np.pi*random.random() 255 qml.RY(rY,wires=j) 256 257 for _ in range(self.n_entangling_layers): 258 r = random.sample(range(0, self.n_qubits), 2) 259 qml.CZ(wires=r) 260 261 #qml.CZ(wires=r) 262 # Hadamards 263 qml.Barrier() 264 for i in range(self.n_qubits): qml.Hadamard(wires=i) 265 266 return qml.probs(wires=range(0,self.n_qubits)) 267 268 return qnode
GaussianLikeNoiseGenerator method that implements the quantum circuit.
Parameters:
- dev : qml.device
PennyLane device on wich run quantum operations (dafault : None). When None it will be set
to 'default.qubit'
Returns:
- qnode : qml.qnode
the actual PennyLane circuit