Skip to content
Get started

eqiora.torch

← Python API index

Use Eqiora differentiable programs with PyTorch autograd.

View source

Install the torch extra, then create program with the differentiation example:

python
import torch
from eqiora.torch import bind
operator = bind(program)
parameters = torch.tensor([1.5], dtype=torch.float64, requires_grad=True)
values = operator(parameters)
values.square().sum().backward()
print(parameters.grad)

The gradient is the derivative of the sum of squared output values with respect to the selected parameter. Inputs are contiguous, one-dimensional CPU float64 tensors. See framework adapters for installation and compiled execution.

Functional PyTorch view of one Eqiora program, valid in this process.

python
class TorchProgram:
def __init__(self, program: DifferentiableProgram) -> None: ...
@property
def program(self) -> DifferentiableProgram: ...
@property
def input_shape(self) -> tuple[int]: ...
@property
def output_shape(self) -> tuple[int]: ...
def __call__(self, parameters: torch.Tensor) -> torch.Tensor: ...

Register a program as a PyTorch operator in this process.

python
def bind(program: DifferentiableProgram) -> TorchProgram: ...