qrunch.chemistry.problem_builders.ground_state_problem.modifier_applicator

Module containing the GroundStateProblemModifierApplicator for applying problem modifiers.

Classes

GroundStateProblemModifierApplicator

Encapsulates the logic for applying problem modifiers to a ground state problem.

class GroundStateProblemModifierApplicator

Bases: object

Encapsulates the logic for applying problem modifiers to a ground state problem.

This class handles the common patterns of: - Trying to load a fully or partially modified problem from persistence - Applying modifiers sequentially, saving after each - Splitting modifiers at the active space boundary

The class works with both restricted and unrestricted problems through generic callables.

__init__(problem_modifiers: list[GroundStateProblemModifier] | None, problem_label: str) None

Initialize the modifier applicator.

Parameters:
  • problem_modifiers (list[GroundStateProblemModifier] | None) – The list of problem modifiers to apply.

  • problem_label (str) – A human-readable label for the problem type, used in log messages (e.g. “ground state” or “projective embedding”).

Return type:

None

apply_all_modifiers(problem: ProblemT, save_callable: Callable[[ProblemT, list[GroundStateProblemModifier]], None] | None = None) ProblemT

Apply all configured modifiers to the problem, optionally saving after each.

Parameters:
  • problem (ProblemT) – The ground state problem to modify.

  • save_callable (Callable[[ProblemT, list[GroundStateProblemModifier]], None] | None) – An optional callable to persist the problem after each modifier is applied. Takes the modified problem and the list of modifiers applied so far.

Return type:

ProblemT

apply_post_active_space_modifiers(problem: ProblemT) ProblemT

Apply modifiers that follow the active space modifier.

Parameters:

problem (ProblemT) – The ground state problem with active space already applied.

Return type:

ProblemT

apply_pre_active_space_modifiers(problem: ProblemT) ProblemT

Apply modifiers that precede the active space modifier.

Parameters:

problem (ProblemT) – The ground state problem to modify.

Return type:

ProblemT

get_post_active_space_modifiers() list[GroundStateProblemModifier]

Return the modifiers that follow the active space modifier.

Return type:

list[GroundStateProblemModifier]

property problem_modifiers: list[GroundStateProblemModifier] | None

Configured problem modifiers.

try_load_modified_problem(load_callable: Callable[[list[GroundStateProblemModifier]], ProblemT | None], save_callable: Callable[[ProblemT, list[GroundStateProblemModifier]], None]) ProblemT | None

Attempt to load a fully or partially modified problem from persistence.

First tries to load the problem with all modifiers applied. If that fails, progressively tries loading with fewer modifiers and applies the remaining ones.

Parameters:
  • load_callable (Callable[[list[GroundStateProblemModifier]], ProblemT | None]) – A callable that takes a list of applied modifiers and returns the problem or None.

  • save_callable (Callable[[ProblemT, list[GroundStateProblemModifier]], None]) – A callable that takes a problem and a list of applied modifiers and persists it.

Return type:

ProblemT | None