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[0].grad)

The gradient is the derivative of the sum of squared output values with respect to the selected parameter. Inputs are ordered contiguous CPU tensor leaves, with the native signature shape and float64 or complex128 dtype. 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 inputs(self) -> tuple[DifferentiableValueSignature, ...]: ...
@property
def outputs(self) -> tuple[DifferentiableValueSignature, ...]: ...
def __call__(self, parameters: tuple[torch.Tensor, ...] | list[torch.Tensor]) -> tuple[torch.Tensor, ...]: ...

Register a program as a PyTorch operator in this process.

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