Skip to content

Commit

Permalink
Merge branch 'more-docs' of github.com:april-tools/cirkit into more-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
loreloc committed Dec 4, 2024
2 parents 7e180c0 + bba525c commit 757f9ee
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 142 deletions.
16 changes: 8 additions & 8 deletions cirkit/backend/torch/circuits.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,13 +270,13 @@ def forward(self, x: Tensor) -> Tensor:
following the topological ordering.
Args:
x: The tensor input of the circuit, with shape (B, C, D), where B is the batch size,
C is the number of channels, and D is the number of variables.
x: The tensor input of the circuit, with shape $(B, C, D)$, where B is the batch size,
$C$ is the number of channels, and $D$ is the number of variables.
Returns:
Tensor: The tensor output of the circuit, with shape (B, O, K),
where O is the number of vectorized outputs (i.e., the number of output layers),
and K is the number of scalars in each output (e.g., the number of classes).
Tensor: The tensor output of the circuit, with shape $(B, O, K)$,
where $O$ is the number of vectorized outputs (i.e., the number of output layers),
and $K$ is the number of scalars in each output (e.g., the number of classes).
"""
return self._evaluate_layers(x)

Expand All @@ -298,9 +298,9 @@ def forward(self) -> Tensor:
following the topological ordering.
Returns:
Tensor: The tensor output of the circuit, with shape (B, O, K),
where O is the number of vectorized outputs (i.e., the number of output layers),
and K is the number of scalars in each output (e.g., the number of classes).
Tensor: The tensor output of the circuit, with shape $(B, O, K)$,
where $O$ is the number of vectorized outputs (i.e., the number of output layers),
and $K$ is the number of scalars in each output (e.g., the number of classes).
"""
# Evaluate the layers using some dummy input
x = torch.empty(size=(1, self.num_channels, self.num_variables), device=self.device)
Expand Down
4 changes: 2 additions & 2 deletions cirkit/backend/torch/layers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ def __init__(
Args:
num_input_units: The number of input units.
num_output_units: The number of output units.
arity: The arity of the layer. Defaults to 1.
arity: The arity of the layer.
semiring: The evaluation semiring.
Defaults to [SumProductSemiring][cirkit.backend.torch.semiring.SumProductSemiring].
num_folds: The number of folds. Defaults to 1.
num_folds: The number of folds.
Raises:
ValueError: If the number of input units is negative.
Expand Down
38 changes: 19 additions & 19 deletions cirkit/backend/torch/layers/inner.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ def __init__(
Args:
num_input_units: The number of input units.
num_output_units: The number of output units.
arity: The arity of the layer. Defaults to 2.
arity: The arity of the layer.
semiring: The evaluation semiring.
Defaults to [SumProductSemiring][cirkit.backend.torch.semiring.SumProductSemiring].
num_folds: The number of channels. Defaults to 1.
num_folds: The number of channels.
"""
super().__init__(
num_input_units, num_output_units, arity=arity, semiring=semiring, num_folds=num_folds
Expand All @@ -46,12 +46,12 @@ def forward(self, x: Tensor) -> Tensor:
"""Invoke the forward function.
Args:
x: The tensor input to this layer, having shape (F, H, B, Ki), where F
is the number of folds, H is the arity, B is the batch size, and
Ki is the number of input units.
x: The tensor input to this layer, having shape $(F, H, B, K_i)$, where $F$
is the number of folds, $H$ is the arity, $B$ is the batch size, and
$K_i$ is the number of input units.
Returns:
Tensor: The tensor output of this layer, having shape (F, B, Ko), where Ko
Tensor: The tensor output of this layer, having shape $(F, B, K_o)$, where $K_o$
is the number of output units.
"""

Expand All @@ -60,9 +60,9 @@ def sample(self, x: Tensor) -> tuple[Tensor, Tensor | None]:
Args:
x: A tensor representing the input variable assignments, having shape
(F, H, C, K, N, D), where F is the number of folds, H is the arity,
C is the number of channels, K is the numbe rof input units, N is the number
of samples, D is the number of variables.
$(F, H, C, K, N, D)$, where $F$ is the number of folds, $H$ is the arity,
$C$ is the number of channels, $K$ is the numbe rof input units, $N$ is the number
of samples, $D$ is the number of variables.
Returns:
Tensor: A new tensor representing the new variable assignements the layers gives
Expand Down Expand Up @@ -93,10 +93,10 @@ def __init__(
Args:
num_input_units: The number of input units, which is equal to the number of
output units.
arity: The arity of the layer. Defaults to 2.
arity: The arity of the layer.
semiring: The evaluation semiring.
Defaults to [SumProductSemiring][cirkit.backend.torch.semiring.SumProductSemiring].
num_folds: The number of channels. Defaults to 1.
num_folds: The number of channels.
Raises:
ValueError: If the arity is not at least 2.
Expand Down Expand Up @@ -147,7 +147,7 @@ def __init__(
arity: The arity of the layer. Defaults to 2 (which is the only supported arity).
semiring: The evaluation semiring.
Defaults to [SumProductSemiring][cirkit.backend.torch.semiring.SumProductSemiring].
num_folds: The number of channels. Defaults to 1.
num_folds: The number of channels.
Raises:
ValueError: If the arity is not at least 2.
Expand Down Expand Up @@ -206,13 +206,13 @@ def __init__(
Args:
num_input_units: The number of input units.
num_output_units: The number of output units.
arity: The arity of the layer. Defaults to 2.
weight: The weight parameter, which must have shape (F, Ko, Ki\cdot H),
where F is the number of folds, Ko is the number of output units,
Ki is the number of input units, and H is the arity.
arity: The arity of the layer.
weight: The weight parameter, which must have shape $(F, K_o, K_i\cdot H)$,
where $F$ is the number of folds, $K_o$ is the number of output units,
$K_i$ is the number of input units, and $H$ is the arity.
semiring: The evaluation semiring.
Defaults to [SumProductSemiring][cirkit.backend.torch.semiring.SumProductSemiring].
num_folds: The number of channels. Defaults to 1.
num_folds: The number of channels.
Raises:
ValueError: If the arity is not a positive integer.
Expand Down Expand Up @@ -254,12 +254,12 @@ def params(self) -> Mapping[str, TorchParameter]:

def forward(self, x: Tensor) -> Tensor:
# x: (F, H, B, Ki) -> (F, B, H * Ki)
# weight: (F, Ko, H * Ki)
# weight: (F, Ko,$H$* Ki)
x = x.permute(0, 2, 1, 3).flatten(start_dim=2)
weight = self.weight()
return self.semiring.einsum(
"fbi,foi->fbo", inputs=(x,), operands=(weight,), dim=-1, keepdim=True
) # shape (F, B, Ko).
) # shape $(F, B, K_o)$.

def sample(self, x: Tensor) -> tuple[Tensor, Tensor]:
weight = self.weight()
Expand Down
Loading

0 comments on commit 757f9ee

Please sign in to comment.