bartorch.nlop.FromTorchSim#

class bartorch.nlop.FromTorchSim(model, shape=(), contrasts=None)#

A TorchSim signal model as a BART nonlinear operator.

The operator maps parameter maps to one image per contrast. What it does at each point is TorchSim’s: A() for the value, A_jvp for the derivative and A_vjp for its adjoint, none of which builds a Jacobian – the model is voxel-diagonal, so one forward-mode pass gives the whole volume’s derivative whatever the parameter count.

Parameters:
  • model (torchsim.recon.ModelOperator) – The signal model, with its unknowns, bounds and scales already set.

  • shape (tuple of int) – The voxel shape, C order – (y, x), (z, y, x), whatever the maps are. The operator’s domain is (channels, *shape) and its codomain (contrasts, *shape).

  • contrasts (int, optional) – How many images the model returns. Measured from the model when it is not given.

channels#

Map channels the domain carries, in TorchSim’s order.

Type:

int

names#

What each channel is.

Type:

tuple of str

Examples

>>> from torchsim.recon import ModelOperator
>>> from torchsim.simulators import MultiEchoSimulator
>>> model = ModelOperator(
...     MultiEchoSimulator(TE=echo_times), "T2", bounds={"T2": (10.0, 300.0)}
... )
>>> M = FromTorchSim(model, (128, 128))
>>> M.ishape, M.oshape
((3, 128, 128), (8, 128, 128))
>>> images = M(M.initial(T2=80.0))

Under an encoding, which is the whole point:

>>> F = nlop.chain(M, encoding.to_nonlinear())
>>> maps = optim.IRGNM()(kspace, F, x0=M.initial(T2=80.0))
>>> M.split(maps)["T2"]
__init__(model, shape=(), contrasts=None)#

Methods

__init__(model[, shape, contrasts])

adjoint(dy)

DF(x)^H dy at the last evaluated point, for one input and one output.

chain(other, *[, output, input])

Output output of self into input input of other.

combine(other)

self and other side by side, sharing nothing.

del_out([output])

Drop an output, and everything computed only for it.

derivative(dx)

DF(x) dx at the last evaluated point, for one input and one output.

dup([a, b])

Make two inputs of the same shape one input, kept at a.

flatten([inputs_only])

Every input as one flat vector, and every output as another.

forward(*xs)

F(x), which also fixes where every derivative is taken.

initial(**values)

Maps to start from, in this operator's layout.

jacobian([output, input])

DF/dx_input of one output, as a LinearOperator.

linearize(*xs)

The derivative at x, as a LinearOperator.

link([output, input])

Tie an output back into an input; both arguments go away.

permute_inputs(perm)

Reorder the inputs: the new input i is the old perm[i].

permute_outputs(perm)

Reorder the outputs: the new output o is the old perm[o].

pin(input, value)

Fix one input to value; the input goes away.

reshape_input(input, shape)

This operator with one input's shape written differently.

reshape_output(output, shape)

This operator with one output's shape written differently.

shift_input(new, old)

Move one input to another position, the rest closing up behind it.

shift_output(new, old)

Move one output to another position, the rest closing up behind it.

split(x)

The named maps x stands for, in their own units.

stack_inputs(a, b, axis)

Make two inputs one, concatenated along a C-order axis.

stack_outputs(a, b, axis)

Make two outputs one, concatenated along a C-order axis.

Attributes

device

ishape

The domain, for an operator with one input.

ishapes

The shape of each argument, outputs and inputs kept apart.

names

What each channel of the domain is, in order.

oshape

The codomain, for an operator with one output.

oshapes