hqm.circuits.angleencoding

  1from types import FunctionType
  2import pennylane as qml
  3import numpy as np
  4import sys
  5
  6sys.path += ['.', './utils/']
  7
  8from .circuit import QuantumCircuit
  9
 10class BasicEntangledCircuit(QuantumCircuit):
 11    '''
 12        This class implements a torch/keras quantum layer using a basic entangler
 13        circuit. 
 14    '''
 15    
 16    def __init__(self, n_qubits : int, n_layers : int, dev : qml.devices = None) -> None:
 17        '''
 18            BasicEntangledCircuit constructor.  
 19
 20            Parameters:  
 21            -----------
 22            - n_qubits : int  
 23                number of qubits for the quantum circuit  
 24            - n_layers : int  
 25                number of layers for the quantum circuit  
 26            - dev : qml.device  
 27                PennyLane device on wich run quantum operations (dafault : None). When None it will be set
 28                to 'default.qubit'  
 29            
 30            Returns:  
 31            --------  
 32            Nothing, a BasicEntangledCircuit object will be created.  
 33        '''
 34
 35        super().__init__(n_qubits=n_qubits, n_layers=n_layers, dev=dev)
 36               
 37        self.weight_shape = {"weights": (n_layers, n_qubits)}
 38        self.circuit      = self.circ(self.dev, self.n_qubits)
 39        
 40
 41    @staticmethod
 42    def circ(dev : qml.devices, n_qubits : int) -> FunctionType:
 43        '''
 44            BasicEntangledCircuit static method that implements the quantum circuit.  
 45
 46            Parameters:  
 47            -----------  
 48            - dev : qml.device  
 49                PennyLane device on wich run quantum operations (dafault : None). When None it will be set  
 50                to 'default.qubit'  
 51            - n_qubits : int  
 52                number of qubits for the quantum circuit  
 53
 54            Returns:  
 55            --------  
 56            - qnode : qml.qnode  
 57                the actual PennyLane circuit   
 58        '''
 59
 60        @qml.qnode(dev)
 61        def qnode(inputs : np.ndarray, weights : np.ndarray) -> list:
 62            '''
 63                PennyLane based quantum circuit composed of an angle embedding layer and a basic entangler
 64                layer.  
 65
 66                Parameters:  
 67                -----------  
 68                - inputs : np.ndarray  
 69                    array containing input values (can came from previous torch/keras layers or quantum layers)  
 70                - weights : np.ndarray  
 71                    array containing the weights of the circuit that are tuned during training, the shape of this
 72                    array depends on circuit's layers and qubits.   
 73                
 74                Returns:  
 75                --------  
 76                - measurements : list  
 77                    list of values measured from the quantum circuits  
 78            '''
 79            qml.AngleEmbedding(inputs, wires=range(n_qubits))
 80            qml.BasicEntanglerLayers(weights, wires=range(n_qubits))
 81            measurements = [qml.expval(qml.PauliZ(wires=i)) for i in range(n_qubits)]
 82            return measurements
 83    
 84        return qnode
 85    
 86class StronglyEntangledCircuit(QuantumCircuit):
 87    '''
 88        This class implements a torch/keras quantum layer using a strongly entangler
 89        circuit.
 90    '''
 91
 92    def __init__(self, n_qubits : int, n_layers : int, dev : qml.devices = None) -> None:
 93        '''
 94            StronglyEntangledCircuit constructor.  
 95
 96            Parameters:  
 97            -----------  
 98            - n_qubits : int  
 99                number of qubits for the quantum circuit  
100            - n_layers : int  
101                number of layers for the quantum circuit    
102            - dev : qml.device  
103                PennyLane device on wich run quantum operations (dafault : None). When None it will be set
104                to 'default.qubit'  
105            
106            Returns:  
107            --------  
108            Nothing, a StronglyEntangledCircuit object will be created.  
109        '''        
110
111        super().__init__(n_qubits=n_qubits, n_layers=n_layers, dev=dev)
112        
113        self.weight_shape = {"weights": (n_layers, n_qubits, 3)}
114        self.circuit      = self.circ(self.dev, self.n_qubits)
115        
116    @staticmethod
117    def circ(dev : qml.devices, n_qubits : int) -> FunctionType:
118        '''
119            StronglyEntangledCircuit static method that implements the quantum circuit.  
120
121            Parameters:  
122            -----------  
123            - dev : qml.device  
124                PennyLane device on wich run quantum operations (dafault : None). When None it will be set
125                to 'default.qubit'  
126            - n_qubits : int  
127                number of qubits for the quantum circuit  
128
129            Returns:  
130            --------  
131            - qnode : qml.qnode  
132                the actual PennyLane circuit  
133        '''
134        @qml.qnode(dev)
135        def qnode(inputs : np.ndarray, weights : np.ndarray) -> list:
136            '''
137                PennyLane based quantum circuit composed of an angle embedding layer and a strongly entangler
138                layer.  
139
140                Parameters:  
141                -----------  
142                - inputs : np.ndarray  
143                    array containing input values (can came from previous torch/keras layers or quantum layers)  
144                - weights : np.ndarray  
145                    array containing the weights of the circuit that are tuned during training, the shape of this
146                    array depends on circuit's layers and qubits.   
147                
148                Returns:  
149                --------  
150                - measurements : list   
151                    list of values measured from the quantum circuits  
152            '''
153
154            qml.AngleEmbedding(inputs, wires=range(n_qubits))
155            qml.StronglyEntanglingLayers(weights, wires=range(n_qubits))
156            measurements = [qml.expval(qml.PauliZ(wires=i)) for i in range(n_qubits)]
157            return measurements
158    
159        return qnode
160
161class RandomCircuit(QuantumCircuit):
162    '''
163        This class implements a torch/keras quantum layer using a random
164        circuit. 
165    '''
166    
167    def __init__(self, n_qubits : int, n_layers : int, dev : qml.devices = None) -> None:
168        '''
169            RandomCircuit constructor.  
170
171            Parameters:  
172            -----------
173            - n_qubits : int  
174                number of qubits for the quantum circuit  
175            - n_layers : int  
176                number of layers for the quantum circuit  
177            - dev : qml.device  
178                PennyLane device on wich run quantum operations (dafault : None). When None it will be set
179                to 'default.qubit'  
180            
181            Returns:  
182            --------  
183            Nothing, a RandomCircuit object will be created.  
184        '''
185
186        super().__init__(n_qubits=n_qubits, n_layers=n_layers, dev=dev)
187               
188        self.weight_shape = {"weights": (n_layers, n_qubits)}
189        self.circuit      = self.circ(self.dev, self.n_qubits)
190
191    @staticmethod
192    def circ(dev : qml.devices, n_qubits : int) -> FunctionType:
193        '''
194            RandomCircuit static method that implements the quantum circuit.  
195
196            Parameters:  
197            -----------  
198            - dev : qml.device  
199                PennyLane device on wich run quantum operations (dafault : None). When None it will be set  
200                to 'default.qubit'  
201            - n_qubits : int  
202                number of qubits for the quantum circuit  
203
204            Returns:  
205            --------  
206            - qnode : qml.qnode  
207                the actual PennyLane circuit   
208        '''
209
210        @qml.qnode(dev)
211        def qnode(inputs : np.ndarray, weights : np.ndarray) -> list:
212            '''
213                PennyLane based quantum circuit composed of an angle embedding layer and a basic entangler
214                layer.  
215
216                Parameters:  
217                -----------  
218                - inputs : np.ndarray  
219                    array containing input values (can came from previous torch/keras layers or quantum layers)  
220                - weights : np.ndarray  
221                    array containing the weights of the circuit that are tuned during training, the shape of this
222                    array depends on circuit's layers and qubits.   
223                
224                Returns:  
225                --------  
226                - measurements : list  
227                    list of values measured from the quantum circuits  
228            '''
229            
230            qml.AngleEmbedding(inputs, wires=range(n_qubits))
231            qml.RandomLayers(weights, wires=range(n_qubits))
232            measurements = [qml.expval(qml.PauliZ(wires=i)) for i in range(n_qubits)]
233            return measurements
234    
235        return qnode
class BasicEntangledCircuit(typing.Generic[~quantumcircuit]):
11class BasicEntangledCircuit(QuantumCircuit):
12    '''
13        This class implements a torch/keras quantum layer using a basic entangler
14        circuit. 
15    '''
16    
17    def __init__(self, n_qubits : int, n_layers : int, dev : qml.devices = None) -> None:
18        '''
19            BasicEntangledCircuit constructor.  
20
21            Parameters:  
22            -----------
23            - n_qubits : int  
24                number of qubits for the quantum circuit  
25            - n_layers : int  
26                number of layers for the quantum circuit  
27            - dev : qml.device  
28                PennyLane device on wich run quantum operations (dafault : None). When None it will be set
29                to 'default.qubit'  
30            
31            Returns:  
32            --------  
33            Nothing, a BasicEntangledCircuit object will be created.  
34        '''
35
36        super().__init__(n_qubits=n_qubits, n_layers=n_layers, dev=dev)
37               
38        self.weight_shape = {"weights": (n_layers, n_qubits)}
39        self.circuit      = self.circ(self.dev, self.n_qubits)
40        
41
42    @staticmethod
43    def circ(dev : qml.devices, n_qubits : int) -> FunctionType:
44        '''
45            BasicEntangledCircuit static method that implements the quantum circuit.  
46
47            Parameters:  
48            -----------  
49            - dev : qml.device  
50                PennyLane device on wich run quantum operations (dafault : None). When None it will be set  
51                to 'default.qubit'  
52            - n_qubits : int  
53                number of qubits for the quantum circuit  
54
55            Returns:  
56            --------  
57            - qnode : qml.qnode  
58                the actual PennyLane circuit   
59        '''
60
61        @qml.qnode(dev)
62        def qnode(inputs : np.ndarray, weights : np.ndarray) -> list:
63            '''
64                PennyLane based quantum circuit composed of an angle embedding layer and a basic entangler
65                layer.  
66
67                Parameters:  
68                -----------  
69                - inputs : np.ndarray  
70                    array containing input values (can came from previous torch/keras layers or quantum layers)  
71                - weights : np.ndarray  
72                    array containing the weights of the circuit that are tuned during training, the shape of this
73                    array depends on circuit's layers and qubits.   
74                
75                Returns:  
76                --------  
77                - measurements : list  
78                    list of values measured from the quantum circuits  
79            '''
80            qml.AngleEmbedding(inputs, wires=range(n_qubits))
81            qml.BasicEntanglerLayers(weights, wires=range(n_qubits))
82            measurements = [qml.expval(qml.PauliZ(wires=i)) for i in range(n_qubits)]
83            return measurements
84    
85        return qnode

This class implements a torch/keras quantum layer using a basic entangler circuit.

BasicEntangledCircuit( n_qubits: int, n_layers: int, dev: <module 'pennylane.devices' from '/Users/asebastianelli/miniforge3/envs/hqm/lib/python3.10/site-packages/pennylane/devices/__init__.py'> = None)
17    def __init__(self, n_qubits : int, n_layers : int, dev : qml.devices = None) -> None:
18        '''
19            BasicEntangledCircuit constructor.  
20
21            Parameters:  
22            -----------
23            - n_qubits : int  
24                number of qubits for the quantum circuit  
25            - n_layers : int  
26                number of layers for the quantum circuit  
27            - dev : qml.device  
28                PennyLane device on wich run quantum operations (dafault : None). When None it will be set
29                to 'default.qubit'  
30            
31            Returns:  
32            --------  
33            Nothing, a BasicEntangledCircuit object will be created.  
34        '''
35
36        super().__init__(n_qubits=n_qubits, n_layers=n_layers, dev=dev)
37               
38        self.weight_shape = {"weights": (n_layers, n_qubits)}
39        self.circuit      = self.circ(self.dev, self.n_qubits)

BasicEntangledCircuit constructor.

Parameters:

  • 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'

Returns:

Nothing, a BasicEntangledCircuit object will be created.

@staticmethod
def circ( dev: <module 'pennylane.devices' from '/Users/asebastianelli/miniforge3/envs/hqm/lib/python3.10/site-packages/pennylane/devices/__init__.py'>, n_qubits: int) -> function:
42    @staticmethod
43    def circ(dev : qml.devices, n_qubits : int) -> FunctionType:
44        '''
45            BasicEntangledCircuit static method that implements the quantum circuit.  
46
47            Parameters:  
48            -----------  
49            - dev : qml.device  
50                PennyLane device on wich run quantum operations (dafault : None). When None it will be set  
51                to 'default.qubit'  
52            - n_qubits : int  
53                number of qubits for the quantum circuit  
54
55            Returns:  
56            --------  
57            - qnode : qml.qnode  
58                the actual PennyLane circuit   
59        '''
60
61        @qml.qnode(dev)
62        def qnode(inputs : np.ndarray, weights : np.ndarray) -> list:
63            '''
64                PennyLane based quantum circuit composed of an angle embedding layer and a basic entangler
65                layer.  
66
67                Parameters:  
68                -----------  
69                - inputs : np.ndarray  
70                    array containing input values (can came from previous torch/keras layers or quantum layers)  
71                - weights : np.ndarray  
72                    array containing the weights of the circuit that are tuned during training, the shape of this
73                    array depends on circuit's layers and qubits.   
74                
75                Returns:  
76                --------  
77                - measurements : list  
78                    list of values measured from the quantum circuits  
79            '''
80            qml.AngleEmbedding(inputs, wires=range(n_qubits))
81            qml.BasicEntanglerLayers(weights, wires=range(n_qubits))
82            measurements = [qml.expval(qml.PauliZ(wires=i)) for i in range(n_qubits)]
83            return measurements
84    
85        return qnode

BasicEntangledCircuit static 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'
  • n_qubits : int
    number of qubits for the quantum circuit

Returns:

  • qnode : qml.qnode
    the actual PennyLane circuit
class StronglyEntangledCircuit(typing.Generic[~quantumcircuit]):
 87class StronglyEntangledCircuit(QuantumCircuit):
 88    '''
 89        This class implements a torch/keras quantum layer using a strongly entangler
 90        circuit.
 91    '''
 92
 93    def __init__(self, n_qubits : int, n_layers : int, dev : qml.devices = None) -> None:
 94        '''
 95            StronglyEntangledCircuit constructor.  
 96
 97            Parameters:  
 98            -----------  
 99            - n_qubits : int  
100                number of qubits for the quantum circuit  
101            - n_layers : int  
102                number of layers for the quantum circuit    
103            - dev : qml.device  
104                PennyLane device on wich run quantum operations (dafault : None). When None it will be set
105                to 'default.qubit'  
106            
107            Returns:  
108            --------  
109            Nothing, a StronglyEntangledCircuit object will be created.  
110        '''        
111
112        super().__init__(n_qubits=n_qubits, n_layers=n_layers, dev=dev)
113        
114        self.weight_shape = {"weights": (n_layers, n_qubits, 3)}
115        self.circuit      = self.circ(self.dev, self.n_qubits)
116        
117    @staticmethod
118    def circ(dev : qml.devices, n_qubits : int) -> FunctionType:
119        '''
120            StronglyEntangledCircuit static method that implements the quantum circuit.  
121
122            Parameters:  
123            -----------  
124            - dev : qml.device  
125                PennyLane device on wich run quantum operations (dafault : None). When None it will be set
126                to 'default.qubit'  
127            - n_qubits : int  
128                number of qubits for the quantum circuit  
129
130            Returns:  
131            --------  
132            - qnode : qml.qnode  
133                the actual PennyLane circuit  
134        '''
135        @qml.qnode(dev)
136        def qnode(inputs : np.ndarray, weights : np.ndarray) -> list:
137            '''
138                PennyLane based quantum circuit composed of an angle embedding layer and a strongly entangler
139                layer.  
140
141                Parameters:  
142                -----------  
143                - inputs : np.ndarray  
144                    array containing input values (can came from previous torch/keras layers or quantum layers)  
145                - weights : np.ndarray  
146                    array containing the weights of the circuit that are tuned during training, the shape of this
147                    array depends on circuit's layers and qubits.   
148                
149                Returns:  
150                --------  
151                - measurements : list   
152                    list of values measured from the quantum circuits  
153            '''
154
155            qml.AngleEmbedding(inputs, wires=range(n_qubits))
156            qml.StronglyEntanglingLayers(weights, wires=range(n_qubits))
157            measurements = [qml.expval(qml.PauliZ(wires=i)) for i in range(n_qubits)]
158            return measurements
159    
160        return qnode

This class implements a torch/keras quantum layer using a strongly entangler circuit.

StronglyEntangledCircuit( n_qubits: int, n_layers: int, dev: <module 'pennylane.devices' from '/Users/asebastianelli/miniforge3/envs/hqm/lib/python3.10/site-packages/pennylane/devices/__init__.py'> = None)
 93    def __init__(self, n_qubits : int, n_layers : int, dev : qml.devices = None) -> None:
 94        '''
 95            StronglyEntangledCircuit constructor.  
 96
 97            Parameters:  
 98            -----------  
 99            - n_qubits : int  
100                number of qubits for the quantum circuit  
101            - n_layers : int  
102                number of layers for the quantum circuit    
103            - dev : qml.device  
104                PennyLane device on wich run quantum operations (dafault : None). When None it will be set
105                to 'default.qubit'  
106            
107            Returns:  
108            --------  
109            Nothing, a StronglyEntangledCircuit object will be created.  
110        '''        
111
112        super().__init__(n_qubits=n_qubits, n_layers=n_layers, dev=dev)
113        
114        self.weight_shape = {"weights": (n_layers, n_qubits, 3)}
115        self.circuit      = self.circ(self.dev, self.n_qubits)

StronglyEntangledCircuit constructor.

Parameters:

  • 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'

Returns:

Nothing, a StronglyEntangledCircuit object will be created.

@staticmethod
def circ( dev: <module 'pennylane.devices' from '/Users/asebastianelli/miniforge3/envs/hqm/lib/python3.10/site-packages/pennylane/devices/__init__.py'>, n_qubits: int) -> function:
117    @staticmethod
118    def circ(dev : qml.devices, n_qubits : int) -> FunctionType:
119        '''
120            StronglyEntangledCircuit static method that implements the quantum circuit.  
121
122            Parameters:  
123            -----------  
124            - dev : qml.device  
125                PennyLane device on wich run quantum operations (dafault : None). When None it will be set
126                to 'default.qubit'  
127            - n_qubits : int  
128                number of qubits for the quantum circuit  
129
130            Returns:  
131            --------  
132            - qnode : qml.qnode  
133                the actual PennyLane circuit  
134        '''
135        @qml.qnode(dev)
136        def qnode(inputs : np.ndarray, weights : np.ndarray) -> list:
137            '''
138                PennyLane based quantum circuit composed of an angle embedding layer and a strongly entangler
139                layer.  
140
141                Parameters:  
142                -----------  
143                - inputs : np.ndarray  
144                    array containing input values (can came from previous torch/keras layers or quantum layers)  
145                - weights : np.ndarray  
146                    array containing the weights of the circuit that are tuned during training, the shape of this
147                    array depends on circuit's layers and qubits.   
148                
149                Returns:  
150                --------  
151                - measurements : list   
152                    list of values measured from the quantum circuits  
153            '''
154
155            qml.AngleEmbedding(inputs, wires=range(n_qubits))
156            qml.StronglyEntanglingLayers(weights, wires=range(n_qubits))
157            measurements = [qml.expval(qml.PauliZ(wires=i)) for i in range(n_qubits)]
158            return measurements
159    
160        return qnode

StronglyEntangledCircuit static 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'
  • n_qubits : int
    number of qubits for the quantum circuit

Returns:

  • qnode : qml.qnode
    the actual PennyLane circuit
class RandomCircuit(typing.Generic[~quantumcircuit]):
162class RandomCircuit(QuantumCircuit):
163    '''
164        This class implements a torch/keras quantum layer using a random
165        circuit. 
166    '''
167    
168    def __init__(self, n_qubits : int, n_layers : int, dev : qml.devices = None) -> None:
169        '''
170            RandomCircuit constructor.  
171
172            Parameters:  
173            -----------
174            - n_qubits : int  
175                number of qubits for the quantum circuit  
176            - n_layers : int  
177                number of layers for the quantum circuit  
178            - dev : qml.device  
179                PennyLane device on wich run quantum operations (dafault : None). When None it will be set
180                to 'default.qubit'  
181            
182            Returns:  
183            --------  
184            Nothing, a RandomCircuit object will be created.  
185        '''
186
187        super().__init__(n_qubits=n_qubits, n_layers=n_layers, dev=dev)
188               
189        self.weight_shape = {"weights": (n_layers, n_qubits)}
190        self.circuit      = self.circ(self.dev, self.n_qubits)
191
192    @staticmethod
193    def circ(dev : qml.devices, n_qubits : int) -> FunctionType:
194        '''
195            RandomCircuit static method that implements the quantum circuit.  
196
197            Parameters:  
198            -----------  
199            - dev : qml.device  
200                PennyLane device on wich run quantum operations (dafault : None). When None it will be set  
201                to 'default.qubit'  
202            - n_qubits : int  
203                number of qubits for the quantum circuit  
204
205            Returns:  
206            --------  
207            - qnode : qml.qnode  
208                the actual PennyLane circuit   
209        '''
210
211        @qml.qnode(dev)
212        def qnode(inputs : np.ndarray, weights : np.ndarray) -> list:
213            '''
214                PennyLane based quantum circuit composed of an angle embedding layer and a basic entangler
215                layer.  
216
217                Parameters:  
218                -----------  
219                - inputs : np.ndarray  
220                    array containing input values (can came from previous torch/keras layers or quantum layers)  
221                - weights : np.ndarray  
222                    array containing the weights of the circuit that are tuned during training, the shape of this
223                    array depends on circuit's layers and qubits.   
224                
225                Returns:  
226                --------  
227                - measurements : list  
228                    list of values measured from the quantum circuits  
229            '''
230            
231            qml.AngleEmbedding(inputs, wires=range(n_qubits))
232            qml.RandomLayers(weights, wires=range(n_qubits))
233            measurements = [qml.expval(qml.PauliZ(wires=i)) for i in range(n_qubits)]
234            return measurements
235    
236        return qnode

This class implements a torch/keras quantum layer using a random circuit.

RandomCircuit( n_qubits: int, n_layers: int, dev: <module 'pennylane.devices' from '/Users/asebastianelli/miniforge3/envs/hqm/lib/python3.10/site-packages/pennylane/devices/__init__.py'> = None)
168    def __init__(self, n_qubits : int, n_layers : int, dev : qml.devices = None) -> None:
169        '''
170            RandomCircuit constructor.  
171
172            Parameters:  
173            -----------
174            - n_qubits : int  
175                number of qubits for the quantum circuit  
176            - n_layers : int  
177                number of layers for the quantum circuit  
178            - dev : qml.device  
179                PennyLane device on wich run quantum operations (dafault : None). When None it will be set
180                to 'default.qubit'  
181            
182            Returns:  
183            --------  
184            Nothing, a RandomCircuit object will be created.  
185        '''
186
187        super().__init__(n_qubits=n_qubits, n_layers=n_layers, dev=dev)
188               
189        self.weight_shape = {"weights": (n_layers, n_qubits)}
190        self.circuit      = self.circ(self.dev, self.n_qubits)

RandomCircuit constructor.

Parameters:

  • 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'

Returns:

Nothing, a RandomCircuit object will be created.

@staticmethod
def circ( dev: <module 'pennylane.devices' from '/Users/asebastianelli/miniforge3/envs/hqm/lib/python3.10/site-packages/pennylane/devices/__init__.py'>, n_qubits: int) -> function:
192    @staticmethod
193    def circ(dev : qml.devices, n_qubits : int) -> FunctionType:
194        '''
195            RandomCircuit static method that implements the quantum circuit.  
196
197            Parameters:  
198            -----------  
199            - dev : qml.device  
200                PennyLane device on wich run quantum operations (dafault : None). When None it will be set  
201                to 'default.qubit'  
202            - n_qubits : int  
203                number of qubits for the quantum circuit  
204
205            Returns:  
206            --------  
207            - qnode : qml.qnode  
208                the actual PennyLane circuit   
209        '''
210
211        @qml.qnode(dev)
212        def qnode(inputs : np.ndarray, weights : np.ndarray) -> list:
213            '''
214                PennyLane based quantum circuit composed of an angle embedding layer and a basic entangler
215                layer.  
216
217                Parameters:  
218                -----------  
219                - inputs : np.ndarray  
220                    array containing input values (can came from previous torch/keras layers or quantum layers)  
221                - weights : np.ndarray  
222                    array containing the weights of the circuit that are tuned during training, the shape of this
223                    array depends on circuit's layers and qubits.   
224                
225                Returns:  
226                --------  
227                - measurements : list  
228                    list of values measured from the quantum circuits  
229            '''
230            
231            qml.AngleEmbedding(inputs, wires=range(n_qubits))
232            qml.RandomLayers(weights, wires=range(n_qubits))
233            measurements = [qml.expval(qml.PauliZ(wires=i)) for i in range(n_qubits)]
234            return measurements
235    
236        return qnode

RandomCircuit static 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'
  • n_qubits : int
    number of qubits for the quantum circuit

Returns:

  • qnode : qml.qnode
    the actual PennyLane circuit