<commit_before>
from os.path import join
import sys
import numpy as np

from seisflows.tools import msg
from seisflows.tools import unix
from seisflows.tools.array import loadnpy, savenpy
from seisflows.tools.code import divides, exists
from seisflows.tools.config import SeisflowsParameters, SeisflowsPaths, \
    ParameterError

PAR = SeisflowsParameters()
PATH = SeisflowsPaths()

import system
import solver
import optimize
import preprocess
import postprocess


class thrifty_inversion(loadclass('workflow', 'inversion')):
    """ Thrifty inversion subclass

      Provides additional savings by avoiding redundant forward simulations
      associated with sufficient decrease and curvature tests in a safeguarded
      backtracking line search. Otherwise, the same as regular inversion
      workflow.

      For more readable but less efficient inversion workflow, feel free to
      revert to the parent class.
    """

    def solver_status(self, maxiter=1):
        """ Keeps track of whether a forward simulation would be redundant
        """
        if optimize.iter <= maxiter:
            # forward simulation not redundant because solver files do not exist
            # prior to first iteration
            return False

        elif optimize.iter == PAR.BEGIN:
            # forward simulation not redundant because solver files need to be
            # reinstated after possible multiscale transition
            return False

        elif PATH.LOCAL:
            # forward simulation not redundant because solver files need to be
            # reinstated on local filesystems
            return False

        elif PAR.LINESEARCH != 'Backtrack':
            # thrifty inversion only implemented for backtracking line search,
            # not bracketing line search
            return False

        elif optimize.restarted:
            # forward simulation not redundant following optimization algorithm
            # restart
            return False<commit_msg>improved description of thrifty_inversion workflow in docstrings<commit_after>
from os.path import join
import sys
import numpy as np

from seisflows.tools import msg
from seisflows.tools import unix
from seisflows.tools.array import loadnpy, savenpy
from seisflows.tools.code import divides, exists
from seisflows.tools.config import SeisflowsParameters, SeisflowsPaths, \
    ParameterError

PAR = SeisflowsParameters()
PATH = SeisflowsPaths()

import system
import solver
import optimize
import preprocess
import postprocess


class thrifty_inversion(loadclass('workflow', 'inversion')):
    """ Thrifty inversion subclass

      Provides savings over conventional inversion by avoiding redundant forward
      simulations associated with sufficient decrease and curvature tests in a 
      safeguarded backtracking line search.

      The results of 'inversion' and 'thrifty_inversion' should be exactly the
      same.  Users who value a simple, readable, easily extensible workflow 
      should choose 'inversion'. Users who value efficiency should choose 
      'thrifty_inversion.'
    """

    def solver_status(self, maxiter=1):
        """ Keeps track of whether a forward simulation would be redundant
        """
        if optimize.iter <= maxiter:
            # forward simulation not redundant because solver files do not exist
            # prior to first iteration
            return False

        elif optimize.iter == PAR.BEGIN:
            # forward simulation not redundant because solver files need to be
            # reinstated after possible multiscale transition
            return False

        elif PATH.LOCAL:
            # forward simulation not redundant because solver files need to be
            # reinstated on local filesystems
            return False

        elif PAR.LINESEARCH != 'Backtrack':
            # thrifty inversion only implemented for backtracking line search,
            # not bracketing line search
            return False

        elif optimize.restarted:
            # forward simulation not redundant following optimization algorithm
            # restart
            return False
{'fraction_non_alphanumeric': 0.043383422200678624, 'fraction_numerical': 0.0004847309743092584, 'mean_word_length': 2.7552320291173795, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4725830', 'n_tokens_mistral': 1030, 'n_tokens_neox': 936, 'n_words': 410}