Base Solver#

Module for the base solver class.

class BaseSolver(problem, use_lt=True)[source]

Bases: SolverInterface

Base class for all solvers, implementing common functionality.

All solvers must inherit from this class and implement abstract methods defined in SolverInterface.

This class is not meant to be instantiated directly.

Initialization of the BaseSolver class.

Parameters:
  • problem (BaseProblem) – The problem to be solved.

  • use_lt (bool) – If True, the solver uses LabelTensors as input. Default is True.

Raises:
  • ValueError – If use_lt is not a boolean.

  • ValueError – If problem is not an instance of BaseProblem.

  • ValueError – If one or more problem conditions are not supported by the solver.

reset()[source]

Reset the internal solver state, clearing the stored problem, models, optimizers and schedulers.

training_step(batch, batch_idx)[source]

Solver training step.

Parameters:
  • batch (list[tuple[str, dict]]) – A batch of data. Each element is a tuple containing a condition name and a dictionary of points.

  • batch_idx (int) – The index of the current batch.

Returns:

The loss of the training step.

Return type:

torch.Tensor

validation_step(batch, batch_idx)[source]

Solver validation step.

Parameters:
  • batch (list[tuple[str, dict]]) – A batch of data. Each element is a tuple containing a condition name and a dictionary of points.

  • batch_idx (int) – The index of the current batch.

Returns:

The loss of the training step.

Return type:

torch.Tensor

test_step(batch, batch_idx)[source]

Solver test step.

Parameters:
  • batch (list[tuple[str, dict]]) – A batch of data. Each element is a tuple containing a condition name and a dictionary of points.

  • batch_idx (int) – The index of the current batch.

Returns:

The loss of the training step.

Return type:

torch.Tensor

static get_batch_size(batch)[source]

Get the batch size.

Parameters:

batch (list[tuple[str, dict]]) – A batch of data. Each element is a tuple containing a condition name and a dictionary of points.

Returns:

The size of the batch.

Return type:

int

property problem

The problem instance.

Returns:

The problem instance.

Return type:

BaseProblem

property use_lt

Using LabelTensors as input during training.

Returns:

The use_lt attribute.

Return type:

bool

property weighting

The weighting schema used by the solver.

Returns:

The weighting schema used by the solver.

Return type:

BaseWeighting

property loss

The element-wise loss module used by the solver.

Returns:

The element-wise loss module used by the solver.

Return type:

torch.nn.Module