code: def main(args):
      """
      Reference for the n-step sequential model used here:
  
      Aaron L. Lucius et al (2003).
      "General Methods for Analysis of Sequential ‘‘n-step’’ Kinetic Mechanisms:
      Application to Single Turnover Kinetics of Helicase-Catalyzed DNA Unwinding"
      https://www.sciencedirect.com/science/article/pii/S0006349503746487
      """
  
      funsor.set_backend("torch")
  
      # Problem definition.
      true_rate = 20
      true_nsteps = 4
      rate = Variable("rate", Real)
      nsteps = Variable("nsteps", Real)
      s = Variable("s", Real)
      time = Tensor(torch.arange(0.04, 1.04, 0.04))["timepoint"]
      noise = (
          Tensor(torch.randn(time.inputs["timepoint"].size))[
              "timepoint"
          ]
          / 500
      )
      data = (
          Tensor(
              1
              - torch.igammac(
                  torch.tensor(true_nsteps), true_rate * time.data
              )
          )["timepoint"]
          + noise
      )
      F = rate**nsteps / (s * (rate + s) ** nsteps)
      # Inverse Laplace.
      pred = InverseLaplace(F, time, "s")
  
      # Loss function.
      loss = (pred - data).abs().reduce(ops.add, "timepoint")
      init_params = {
          "rate": Tensor(torch.tensor(5.0, requires_grad=True)),
          "nsteps": Tensor(torch.tensor(2.0, requires_grad=True)),
      }
  
      with Talbot(num_steps=args.talbot_num_steps):
          # Fit the data
          with Adam(
              args.num_steps,
              lr=args.learning_rate,
              log_every=args.log_every,
              params=init_params,
          ) as optim:
              loss.reduce(ops.min, {"rate", "nsteps"})
          # Fitted curve.
          fitted_curve = pred(
              rate=optim.param("rate"), nsteps=optim.param("nsteps")
          )
  
      print(f"Data\n{data}")
      print(f"Fit curve\n{fitted_curve}")
      print(f"True rate\n{true_rate}")
      print("Learned rate\n{}".format(optim.param("rate").item()))
      print(f"True number of steps\n{true_nsteps}")
      print(
          "Learned number of steps\n{}".format(
              optim.param("nsteps").item()
          )
      )
  
file_path: funsor/examples/talbot.py
imports: import argparse
  import math
  import torch
  import funsor
  import funsor.ops
  from funsor.adam import Adam
  from funsor.domains import Real
  from funsor.factory import Bound, Fresh, Has, make_funsor
  from funsor.interpretations import StatefulInterpretation
  from funsor.tensor import Tensor
  from funsor.terms import Funsor, Variable
  from funsor.util import get_backend
label_desc: Use image node_id 3 for calling a global function with example usage: main(args) without return types