base
base
¤
TorchLayer
¤
Bases: AbstractTorchModule, ABC
The abstract base class for all layers implemented in torch.
Source code in cirkit/backend/torch/layers/base.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
arity = arity
instance-attribute
¤
config
abstractmethod
property
¤
Retrieves the configuration of the layer, i.e., a dictionary mapping hyperparameters
of the layer to their values. The hyperparameter names must match the argument names in
the __init__ method.
Returns:
| Type | Description |
|---|---|
Mapping[str, Any]
|
Mapping[str, Any]: A dictionary from hyperparameter names to their value. |
num_buffers
cached
property
¤
Retrieve the number of scalar buffers. Note that if a buffer is complex-valued, this will double count them.
Returns:
| Type | Description |
|---|---|
int
|
The number of scalar buffers. |
num_input_units = num_input_units
instance-attribute
¤
num_output_units = num_output_units
instance-attribute
¤
num_parameters
cached
property
¤
Retrieve the number of scalar parameters. Note that if a parameter is complex-valued, this will double count them.
Returns:
| Type | Description |
|---|---|
int
|
The number of scalar parameters. |
params
property
¤
Retrieve the torch parameters of the layer, i.e., a dictionary mapping the names of
the torch parameters to the actual torch parameter instance. The parameter names must
match the argument names in the__init__ method.
Returns:
| Type | Description |
|---|---|
Mapping[str, TorchParameter]
|
Mapping[str, TorchParameter]: A dictionary from parameter names to the corresponding torch parameter instance. |
semiring = semiring if semiring is not None else SumProductSemiring
instance-attribute
¤
sub_modules
property
¤
Retrieve a dictionary mapping string identifiers to torch sub-module layers.,
that must be passed to the __init__ method of the top-level layer
Returns:
| Type | Description |
|---|---|
Mapping[str, TorchLayer]
|
A dictionary of torch modules. |
__init__(num_input_units, num_output_units, arity=1, *, semiring=None, num_folds=1)
¤
Initialize a layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_input_units
|
int
|
The number of input units. |
required |
num_output_units
|
int
|
The number of output units. |
required |
arity
|
int
|
The arity of the layer. |
1
|
semiring
|
Semiring | None
|
The evaluation semiring. Defaults to SumProductSemiring. |
None
|
num_folds
|
int
|
The number of folds. |
1
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the number of input units is negative. |
ValueError
|
If the number of output units is not positive. |
ValueError
|
If the arity is not positive. |
Source code in cirkit/backend/torch/layers/base.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | |
extra_repr()
¤
Source code in cirkit/backend/torch/layers/base.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |