Skip to content

parameter

parameter ¤

ParameterAddressBook ¤

Bases: AddressBook[TorchParameterNode]

The address book data structure for the parameter computational graphs. See TorchParameter. The address book stores a list of AddressBookEntry, where each entry stores the information needed to gather the inputs to each (possibly folded) node in the parameter computational graph.

Source code in cirkit/backend/torch/parameters/parameter.py
 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
class ParameterAddressBook(AddressBook[TorchParameterNode]):
    """The address book data structure for the parameter computational graphs.
    See [TorchParameter][cirkit.backend.torch.parameters.parameter.TorchParameter].
    The address book stores a list of
    [AddressBookEntry][cirkit.backend.torch.graph.modules.AddressBookEntry],
    where each entry stores the information needed to gather the inputs to each (possibly folded)
    node in the parameter computational graph.
    """

    def lookup(
        self, module_outputs: list[Tensor], *, in_graph: Tensor | None = None
    ) -> Iterator[tuple[TorchParameterNode | None, tuple]]:
        def _select_index(mids: list[int], idx: Tensor | tuple[slice | None, ...]) -> Tensor:
            # A useful function combining the modules outputs, and then possibly applying an index
            if len(mids) == 1:
                t = module_outputs[mids[0]]
            else:
                t = torch.cat([module_outputs[mid] for mid in mids], dim=0)
            return t[idx]

        # Loop through the entries and yield inputs
        for entry in self:
            node = entry.module
            in_node_ids = entry.in_module_ids
            in_fold_idx = entry.in_fold_idx
            # Catch the case there are some inputs coming from other modules
            if in_node_ids:
                x = tuple(
                    _select_index(mids, in_idx) for mids, in_idx in zip(in_node_ids, in_fold_idx)
                )
                yield node, x
                continue

            # Catch the case there are no inputs coming from other modules
            yield node, ()

    @classmethod
    def from_index_info(
        cls, fold_idx_info: FoldIndexInfo[TorchParameterNode]
    ) -> "ParameterAddressBook":
        """Constructs the parameter nodes address book using fold index information.

        Args:
            fold_idx_info: The fold index information.

        Returns:
            A parameter nodes address book.
        """
        # The address book entries being built
        entries: list[AddressBookEntry[TorchParameterNode]] = []

        # A useful dictionary mapping module ids to their number of folds
        num_folds: dict[int, int] = {}

        # Build the bookkeeping data structure by following the topological ordering
        for mid, m in enumerate(fold_idx_info.ordering):
            # Retrieve the index information of the input modules
            in_modules_fold_idx = fold_idx_info.in_fold_idx[mid]

            # Catch the case of a folded module having the input of the network as input
            if in_modules_fold_idx:
                entry = build_address_book_entry(m, in_modules_fold_idx, num_folds=num_folds)
            # Catch the case of a folded module without inputs
            else:
                entry = AddressBookEntry(m, [], [])

            num_folds[mid] = m.num_folds
            entries.append(entry)

        # Append the last bookkeeping entry with the information to compute the output tensor
        entry = build_address_book_stacked_entry(
            None, [fold_idx_info.out_fold_idx], num_folds=num_folds, output=True
        )
        entries.append(entry)

        return ParameterAddressBook(entries)

from_index_info(fold_idx_info) classmethod ¤

Constructs the parameter nodes address book using fold index information.

Parameters:

Name Type Description Default
fold_idx_info FoldIndexInfo[TorchParameterNode]

The fold index information.

required

Returns:

Type Description
ParameterAddressBook

A parameter nodes address book.

Source code in cirkit/backend/torch/parameters/parameter.py
 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
@classmethod
def from_index_info(
    cls, fold_idx_info: FoldIndexInfo[TorchParameterNode]
) -> "ParameterAddressBook":
    """Constructs the parameter nodes address book using fold index information.

    Args:
        fold_idx_info: The fold index information.

    Returns:
        A parameter nodes address book.
    """
    # The address book entries being built
    entries: list[AddressBookEntry[TorchParameterNode]] = []

    # A useful dictionary mapping module ids to their number of folds
    num_folds: dict[int, int] = {}

    # Build the bookkeeping data structure by following the topological ordering
    for mid, m in enumerate(fold_idx_info.ordering):
        # Retrieve the index information of the input modules
        in_modules_fold_idx = fold_idx_info.in_fold_idx[mid]

        # Catch the case of a folded module having the input of the network as input
        if in_modules_fold_idx:
            entry = build_address_book_entry(m, in_modules_fold_idx, num_folds=num_folds)
        # Catch the case of a folded module without inputs
        else:
            entry = AddressBookEntry(m, [], [])

        num_folds[mid] = m.num_folds
        entries.append(entry)

    # Append the last bookkeeping entry with the information to compute the output tensor
    entry = build_address_book_stacked_entry(
        None, [fold_idx_info.out_fold_idx], num_folds=num_folds, output=True
    )
    entries.append(entry)

    return ParameterAddressBook(entries)

lookup(module_outputs, *, in_graph=None) ¤

Source code in cirkit/backend/torch/parameters/parameter.py
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
def lookup(
    self, module_outputs: list[Tensor], *, in_graph: Tensor | None = None
) -> Iterator[tuple[TorchParameterNode | None, tuple]]:
    def _select_index(mids: list[int], idx: Tensor | tuple[slice | None, ...]) -> Tensor:
        # A useful function combining the modules outputs, and then possibly applying an index
        if len(mids) == 1:
            t = module_outputs[mids[0]]
        else:
            t = torch.cat([module_outputs[mid] for mid in mids], dim=0)
        return t[idx]

    # Loop through the entries and yield inputs
    for entry in self:
        node = entry.module
        in_node_ids = entry.in_module_ids
        in_fold_idx = entry.in_fold_idx
        # Catch the case there are some inputs coming from other modules
        if in_node_ids:
            x = tuple(
                _select_index(mids, in_idx) for mids, in_idx in zip(in_node_ids, in_fold_idx)
            )
            yield node, x
            continue

        # Catch the case there are no inputs coming from other modules
        yield node, ()

TorchParameter ¤

Bases: TorchDiAcyclicGraph[TorchParameterNode]

A torch parameter is a computational graph consisting of computational nodes, and computing a tensor parameter that is then used by a circuit layer. That is, given F the number of folds, and (K_1,\ldots,K_n) the shape of each parameter fold, a torch parameter computes a tensor of shape (F,K_1,\ldots,K_n). Note that a torch parameter does not take any tensor as input.

Source code in cirkit/backend/torch/parameters/parameter.py
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
class TorchParameter(TorchDiAcyclicGraph[TorchParameterNode]):
    r"""A torch parameter is a computational graph consisting of computational nodes,
    and computing a tensor parameter that is then used by a circuit layer. That is,
    given F the number of folds, and (K_1,\ldots,K_n) the shape of each parameter fold, a
    torch parameter computes a tensor of shape (F,K_1,\ldots,K_n).
    Note that a torch parameter does not take any tensor as input.
    """

    def __init__(
        self,
        modules: Sequence[TorchParameterNode],
        in_modules: Mapping[TorchParameterNode, Sequence[TorchParameterNode]],
        outputs: Sequence[TorchParameterNode],
        *,
        fold_idx_info: FoldIndexInfo[TorchParameterNode] | None = None,
    ):
        """Initialize a torch parameter computational graph.

        Args:
            modules: The parameter computational nodes.
            in_modules: A dictionary mapping nodes to their input nodes, if any.
            outputs: A list of nodes that are the output nodes in the computational graph.
            fold_idx_info: The folding index information.
                It can be None if the Torch graph is not folded.
        """
        super().__init__(modules, in_modules, outputs, fold_idx_info=fold_idx_info)

    @property
    def device(self) -> torch.device:
        """Retrieve the device of the parameter computational graph.
        Currently, it assumes all [torch.nn.parameter.Parameter][torch.nn.parameter.Parameter]
        it contains are stored in the same device.

        Returns:
            torch.device: The device.
        """
        # TODO: Obtaining the device in this way is only needed because
        #  the integrate() method in layers can output constant tensors that
        #  would be allocated on the CPU by default (e.g., log_partition_function()).
        #  Since having a device flag in nn.Module is malpractice (tensors are stored
        #  on devices but NOT modules), is there a better way to do this?
        return next(self.parameters()).device

    @property
    def num_folds(self) -> int:
        """The number of folds of the computed tensor parameter.

        Returns:
            The number of folds.
        """
        return self._address_book.num_outputs

    @property
    def shape(self) -> tuple[int, ...]:
        r"""The shape of the computed tensor parameter, without considering
        the number of folds. That is, if the number of folds
        (see [TorchParameter.num_folds]
        [cirkit.backend.torch.parameters.parameter.TorchParameter.num_folds])
        is F and the shape is (K_1,\ldots,K_n), it means the torch parameter
        computes a tensor of shape (F, K_1,\ldots,K_n).

        Returns:
            The shape of the computed tensor parameter, without considering the number of folds.
        """
        return self.outputs[0].shape

    def reset_parameters(self) -> None:
        """Reset the parameters of the parameter computational graph."""
        for p in self.nodes:
            p.reset_parameters()

    def __call__(self) -> Tensor:
        return super().__call__()

    def forward(self) -> Tensor:
        r"""Evaluate the parameter computational graph.

        Returns:
            Tensor: The output parameter tensor, having shape (F, K_1,\ldots K_n),
                where F is the number of folds, and (K_1,\ldots,K_n) is the shape
                of each parameter tensor slice.
        """
        return self.evaluate()

    def _build_unfold_index_info(self) -> FoldIndexInfo[TorchParameterNode]:
        return build_unfold_index_info(
            self.topological_ordering(), outputs=self.outputs, incomings_fn=self.node_inputs
        )

    def _build_address_book(
        self, fold_idx_info: FoldIndexInfo[TorchParameterNode]
    ) -> ParameterAddressBook:
        return ParameterAddressBook.from_index_info(fold_idx_info)

    def extra_repr(self) -> str:
        return f"shape: {(self.num_folds, *self.shape)}"

    @classmethod
    def from_input(cls, p: TorchParameterInput) -> "TorchParameter":
        """Constructs a parameter from a leaf symbolic node only.

        Args:
            p: The parameter input.

        Returns:
            A parameter containing only the given parameter input.
        """
        return TorchParameter([p], {}, outputs=[p])

    @classmethod
    def from_sequence(
        cls, p: Union[TorchParameterInput, "TorchParameter"], *ns: TorchParameterOp
    ) -> "TorchParameter":
        """Constructs a parameter from a composition of parameter nodes.

        Args:
            p: The entry point of the sequence, which can be either a parameter
                input or another parameter.
            *ns: A sequence of parameter nodes.

        Returns:
            A parameter that encodes the composition of the parameter nodes,
                starting from the given entry point of the sequence.
        """
        assert p.num_folds == 1
        if isinstance(p, TorchParameterInput):
            p = TorchParameter.from_input(p)
        nodes = list(p.nodes) + list(ns)
        in_nodes = dict(p.nodes_inputs)
        for i, n in enumerate(ns):
            in_nodes[n] = [ns[i - 1]] if i - 1 >= 0 else [p.outputs[0]]
        return TorchParameter(nodes, in_nodes, [ns[-1]])

    @classmethod
    def from_nary(
        cls, n: TorchParameterOp, *ps: Union[TorchParameterInput, "TorchParameter"]
    ) -> "TorchParameter":
        """Constructs a parameter by using a parameter operation node and by specifying its inputs.

        Args:
            n: The parameter operation node.
            *ps: A sequence of parameter input nodes or parameters.

        Returns:
            A parameter that encodes the application of the given parameter operation node
                to the outputs given by the parameter input nodes or parameters.
        """
        assert n.num_folds == 1
        p_graphs = tuple(
            TorchParameter.from_input(p) if isinstance(p, TorchParameterInput) else p for p in ps
        )
        assert all(len(p.outputs) == 1 for p in p_graphs)
        p_nodes = list(chain.from_iterable(p.nodes for p in p_graphs)) + [n]
        in_nodes: dict[TorchParameterNode, Sequence[TorchParameterNode]] = dict(
            (k, v) for g in p_graphs for (k, v) in g.nodes_inputs.items()
        )
        in_nodes[n] = list(p.outputs[0] for p in p_graphs)
        return TorchParameter(p_nodes, in_nodes, [n])

    @classmethod
    def from_unary(
        cls, n: TorchUnaryParameterOp, p: Union[TorchParameterInput, "TorchParameter"]
    ) -> "TorchParameter":
        """Constructs a parameter by using a unary parameter operation node and by specifying its
        inputs.

        Args:
            n: The unary parameter operation node.
            p: The parameter input node, or another parameter.

        Returns:
            A parameter that encodes the application of the given parameter operation
                node to the output given by the parameter input node or parameter.
        """
        assert n.num_folds == 1 and p.num_folds == 1
        return TorchParameter.from_sequence(p, n)

    @classmethod
    def from_binary(
        cls,
        n: TorchBinaryParameterOp,
        p1: Union[TorchParameterInput, "TorchParameter"],
        p2: Union[TorchParameterInput, "TorchParameter"],
    ) -> "TorchParameter":
        """Constructs a parameter by using a binary parameter operation node and by specifying
        its inputs.

        Args:
            n: The binary parameter operation node.
            p1: The first parameter input node, or another parameter.
            p2: The second parameter input node, or another parameter.

        Returns:
            A parameter that encodes the application of the given parameter operation
                node to the two outputs given by the parameter inputs or parameters.
        """
        assert n.num_folds == 1 and p1.num_folds == 1 and p2.num_folds == 1
        return TorchParameter.from_nary(n, p1, p2)

device property ¤

Retrieve the device of the parameter computational graph. Currently, it assumes all torch.nn.parameter.Parameter it contains are stored in the same device.

Returns:

Type Description
device

torch.device: The device.

num_folds property ¤

The number of folds of the computed tensor parameter.

Returns:

Type Description
int

The number of folds.

shape property ¤

The shape of the computed tensor parameter, without considering the number of folds. That is, if the number of folds (see TorchParameter.num_folds) is F and the shape is (K_1,\ldots,K_n), it means the torch parameter computes a tensor of shape (F, K_1,\ldots,K_n).

Returns:

Type Description
tuple[int, ...]

The shape of the computed tensor parameter, without considering the number of folds.

__call__() ¤

Source code in cirkit/backend/torch/parameters/parameter.py
177
178
def __call__(self) -> Tensor:
    return super().__call__()

__init__(modules, in_modules, outputs, *, fold_idx_info=None) ¤

Initialize a torch parameter computational graph.

Parameters:

Name Type Description Default
modules Sequence[TorchParameterNode]

The parameter computational nodes.

required
in_modules Mapping[TorchParameterNode, Sequence[TorchParameterNode]]

A dictionary mapping nodes to their input nodes, if any.

required
outputs Sequence[TorchParameterNode]

A list of nodes that are the output nodes in the computational graph.

required
fold_idx_info FoldIndexInfo[TorchParameterNode] | None

The folding index information. It can be None if the Torch graph is not folded.

None
Source code in cirkit/backend/torch/parameters/parameter.py
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
def __init__(
    self,
    modules: Sequence[TorchParameterNode],
    in_modules: Mapping[TorchParameterNode, Sequence[TorchParameterNode]],
    outputs: Sequence[TorchParameterNode],
    *,
    fold_idx_info: FoldIndexInfo[TorchParameterNode] | None = None,
):
    """Initialize a torch parameter computational graph.

    Args:
        modules: The parameter computational nodes.
        in_modules: A dictionary mapping nodes to their input nodes, if any.
        outputs: A list of nodes that are the output nodes in the computational graph.
        fold_idx_info: The folding index information.
            It can be None if the Torch graph is not folded.
    """
    super().__init__(modules, in_modules, outputs, fold_idx_info=fold_idx_info)

extra_repr() ¤

Source code in cirkit/backend/torch/parameters/parameter.py
200
201
def extra_repr(self) -> str:
    return f"shape: {(self.num_folds, *self.shape)}"

forward() ¤

Evaluate the parameter computational graph.

Returns:

Name Type Description
Tensor Tensor

The output parameter tensor, having shape (F, K_1,\ldots K_n), where F is the number of folds, and (K_1,\ldots,K_n) is the shape of each parameter tensor slice.

Source code in cirkit/backend/torch/parameters/parameter.py
180
181
182
183
184
185
186
187
188
def forward(self) -> Tensor:
    r"""Evaluate the parameter computational graph.

    Returns:
        Tensor: The output parameter tensor, having shape (F, K_1,\ldots K_n),
            where F is the number of folds, and (K_1,\ldots,K_n) is the shape
            of each parameter tensor slice.
    """
    return self.evaluate()

from_binary(n, p1, p2) classmethod ¤

Constructs a parameter by using a binary parameter operation node and by specifying its inputs.

Parameters:

Name Type Description Default
n TorchBinaryParameterOp

The binary parameter operation node.

required
p1 Union[TorchParameterInput, TorchParameter]

The first parameter input node, or another parameter.

required
p2 Union[TorchParameterInput, TorchParameter]

The second parameter input node, or another parameter.

required

Returns:

Type Description
TorchParameter

A parameter that encodes the application of the given parameter operation node to the two outputs given by the parameter inputs or parameters.

Source code in cirkit/backend/torch/parameters/parameter.py
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
@classmethod
def from_binary(
    cls,
    n: TorchBinaryParameterOp,
    p1: Union[TorchParameterInput, "TorchParameter"],
    p2: Union[TorchParameterInput, "TorchParameter"],
) -> "TorchParameter":
    """Constructs a parameter by using a binary parameter operation node and by specifying
    its inputs.

    Args:
        n: The binary parameter operation node.
        p1: The first parameter input node, or another parameter.
        p2: The second parameter input node, or another parameter.

    Returns:
        A parameter that encodes the application of the given parameter operation
            node to the two outputs given by the parameter inputs or parameters.
    """
    assert n.num_folds == 1 and p1.num_folds == 1 and p2.num_folds == 1
    return TorchParameter.from_nary(n, p1, p2)

from_input(p) classmethod ¤

Constructs a parameter from a leaf symbolic node only.

Parameters:

Name Type Description Default
p TorchParameterInput

The parameter input.

required

Returns:

Type Description
TorchParameter

A parameter containing only the given parameter input.

Source code in cirkit/backend/torch/parameters/parameter.py
203
204
205
206
207
208
209
210
211
212
213
@classmethod
def from_input(cls, p: TorchParameterInput) -> "TorchParameter":
    """Constructs a parameter from a leaf symbolic node only.

    Args:
        p: The parameter input.

    Returns:
        A parameter containing only the given parameter input.
    """
    return TorchParameter([p], {}, outputs=[p])

from_nary(n, *ps) classmethod ¤

Constructs a parameter by using a parameter operation node and by specifying its inputs.

Parameters:

Name Type Description Default
n TorchParameterOp

The parameter operation node.

required
*ps Union[TorchParameterInput, TorchParameter]

A sequence of parameter input nodes or parameters.

()

Returns:

Type Description
TorchParameter

A parameter that encodes the application of the given parameter operation node to the outputs given by the parameter input nodes or parameters.

Source code in cirkit/backend/torch/parameters/parameter.py
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
@classmethod
def from_nary(
    cls, n: TorchParameterOp, *ps: Union[TorchParameterInput, "TorchParameter"]
) -> "TorchParameter":
    """Constructs a parameter by using a parameter operation node and by specifying its inputs.

    Args:
        n: The parameter operation node.
        *ps: A sequence of parameter input nodes or parameters.

    Returns:
        A parameter that encodes the application of the given parameter operation node
            to the outputs given by the parameter input nodes or parameters.
    """
    assert n.num_folds == 1
    p_graphs = tuple(
        TorchParameter.from_input(p) if isinstance(p, TorchParameterInput) else p for p in ps
    )
    assert all(len(p.outputs) == 1 for p in p_graphs)
    p_nodes = list(chain.from_iterable(p.nodes for p in p_graphs)) + [n]
    in_nodes: dict[TorchParameterNode, Sequence[TorchParameterNode]] = dict(
        (k, v) for g in p_graphs for (k, v) in g.nodes_inputs.items()
    )
    in_nodes[n] = list(p.outputs[0] for p in p_graphs)
    return TorchParameter(p_nodes, in_nodes, [n])

from_sequence(p, *ns) classmethod ¤

Constructs a parameter from a composition of parameter nodes.

Parameters:

Name Type Description Default
p Union[TorchParameterInput, TorchParameter]

The entry point of the sequence, which can be either a parameter input or another parameter.

required
*ns TorchParameterOp

A sequence of parameter nodes.

()

Returns:

Type Description
TorchParameter

A parameter that encodes the composition of the parameter nodes, starting from the given entry point of the sequence.

Source code in cirkit/backend/torch/parameters/parameter.py
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
@classmethod
def from_sequence(
    cls, p: Union[TorchParameterInput, "TorchParameter"], *ns: TorchParameterOp
) -> "TorchParameter":
    """Constructs a parameter from a composition of parameter nodes.

    Args:
        p: The entry point of the sequence, which can be either a parameter
            input or another parameter.
        *ns: A sequence of parameter nodes.

    Returns:
        A parameter that encodes the composition of the parameter nodes,
            starting from the given entry point of the sequence.
    """
    assert p.num_folds == 1
    if isinstance(p, TorchParameterInput):
        p = TorchParameter.from_input(p)
    nodes = list(p.nodes) + list(ns)
    in_nodes = dict(p.nodes_inputs)
    for i, n in enumerate(ns):
        in_nodes[n] = [ns[i - 1]] if i - 1 >= 0 else [p.outputs[0]]
    return TorchParameter(nodes, in_nodes, [ns[-1]])

from_unary(n, p) classmethod ¤

Constructs a parameter by using a unary parameter operation node and by specifying its inputs.

Parameters:

Name Type Description Default
n TorchUnaryParameterOp

The unary parameter operation node.

required
p Union[TorchParameterInput, TorchParameter]

The parameter input node, or another parameter.

required

Returns:

Type Description
TorchParameter

A parameter that encodes the application of the given parameter operation node to the output given by the parameter input node or parameter.

Source code in cirkit/backend/torch/parameters/parameter.py
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
@classmethod
def from_unary(
    cls, n: TorchUnaryParameterOp, p: Union[TorchParameterInput, "TorchParameter"]
) -> "TorchParameter":
    """Constructs a parameter by using a unary parameter operation node and by specifying its
    inputs.

    Args:
        n: The unary parameter operation node.
        p: The parameter input node, or another parameter.

    Returns:
        A parameter that encodes the application of the given parameter operation
            node to the output given by the parameter input node or parameter.
    """
    assert n.num_folds == 1 and p.num_folds == 1
    return TorchParameter.from_sequence(p, n)

reset_parameters() ¤

Reset the parameters of the parameter computational graph.

Source code in cirkit/backend/torch/parameters/parameter.py
172
173
174
175
def reset_parameters(self) -> None:
    """Reset the parameters of the parameter computational graph."""
    for p in self.nodes:
        p.reset_parameters()