utils
utils
¤
InputLayerFactory
¤
Bases: Protocol
The protocol of a factory that constructs input layers.
Source code in cirkit/templates/utils.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 | |
__call__(scope, num_units, num_channels)
¤
Constructs an input layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scope
|
Scope
|
The scope of the layer. |
required |
num_units
|
int
|
The number of input units composing the layer. |
required |
num_channels
|
int
|
The number of channel variables. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
InputLayer |
InputLayer
|
An input layer. |
Source code in cirkit/templates/utils.py
54 55 56 57 58 59 60 61 62 63 64 | |
Parameterization
dataclass
¤
The settings for a parameterization: the initialization method, the activation function to use, and the data type of the parameter tensor.
Source code in cirkit/templates/utils.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | |
activation = 'none'
class-attribute
instance-attribute
¤
The activation function. Defaults to 'none', i.e., no activation.
activation_kwargs = field(default_factory=dict)
class-attribute
instance-attribute
¤
Additional arguments to pass to the activation function.
dtype = 'real'
class-attribute
instance-attribute
¤
The data type. Defaults to 'real', i.e., real numbers.
initialization
instance-attribute
¤
The initialization method.
initialization_kwargs = field(default_factory=dict)
class-attribute
instance-attribute
¤
Additional arguments to pass to the initializatiot method.
__init__(initialization, activation='none', dtype='real', initialization_kwargs=dict(), activation_kwargs=dict())
¤
ProductLayerFactory
¤
Bases: Protocol
The protocol of a factory that constructs product layers.
Source code in cirkit/templates/utils.py
82 83 84 85 86 87 88 89 90 91 92 93 94 | |
__call__(num_input_units, arity)
¤
Constructs a product layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_input_units
|
int
|
The number of units in each layer that is an input. |
required |
arity
|
int
|
The number of input layers. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
ProductLayer |
ProductLayer
|
A product layer. |
Source code in cirkit/templates/utils.py
85 86 87 88 89 90 91 92 93 94 | |
SumLayerFactory
¤
Bases: Protocol
The protocol of a factory that constructs sum layers.
Source code in cirkit/templates/utils.py
67 68 69 70 71 72 73 74 75 76 77 78 79 | |
__call__(num_input_units, num_output_units)
¤
Constructs a sum layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_input_units
|
int
|
The number of units in each layer that is an input. |
required |
num_output_units
|
int
|
The number of sum units in the layer. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
SumLayer |
SumLayer
|
A sum layer. |
Source code in cirkit/templates/utils.py
70 71 72 73 74 75 76 77 78 79 | |
_build_tensor_parameter(shape, unary_op_factory, dtype, initializer)
¤
Source code in cirkit/templates/utils.py
241 242 243 244 245 246 247 248 249 250 | |
name_to_dtype(name)
¤
Retrieves a data type by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the data type. It can be either 'integer, 'real' or 'complex'. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
DataType |
DataType
|
The corresponding symbolic data type. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the given data type name is not known. |
Source code in cirkit/templates/utils.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | |
name_to_initializer(name, **kwargs)
¤
Retrieves a symbolic initializer object by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The initialization name. It can be one of the following: 'uniform' (in the range 0-1), 'normal' (with mean 0 and standard deviation 1), 'dirichlet' (with concentration parameters 1). |
required |
**kwargs
|
Optional arguments to pass to the initializer. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Initializer |
Initializer
|
The symbolic initializer. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the given initialization name is not known. |
Source code in cirkit/templates/utils.py
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 | |
name_to_input_layer_factory(name, **kwargs)
¤
Retrieves a factory that constructs symbolic input layers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the input layer. It can be one of the following: 'embedding', 'categorical', 'gaussian', 'binomial'. |
required |
**kwargs
|
Arguments to pass to the factory. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
InputLayerFactory |
InputLayerFactory
|
A symbolic input layer factory. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the given input layer name is not known. |
Source code in cirkit/templates/utils.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | |
name_to_parameter_activation(name, **kwargs)
¤
Retrieves a symbolic unary parameter operator by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the parameter activation. It can be either 'none', 'softmax', 'sigmoid', or 'positive-clamp'. |
required |
**kwargs
|
Optional arguments to pass to symbolic unary parameter. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
None |
Callable[[tuple[int, ...]], UnaryParameterOp] | None
|
If name is 'none' |
Callable[[tuple[int, ...]], UnaryParameterOp] | None
|
Callable[[tuple[int, ...]], UnaryParameterOp]: If name is not 'none', then a function that takes the parameter shape and returns a unary parameter operator is given. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the given activation name is not known. |
Source code in cirkit/templates/utils.py
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | |
parameterization_to_factory(param)
¤
Given the settings of a parameterization, retrieves a factory that constructs symbolic parameters with that parameterization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
param
|
Parameterization
|
The parameterization. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
ParameterFactory |
ParameterFactory
|
A symbolic parameter factory. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If one of the settings in the given parameterization is unknown. |
Source code in cirkit/templates/utils.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | |