<commit_before>from __future__ import print_function
from . import Utils
from . import Props
from . import DataMisfit
from . import Regularization
from . import ObjectiveFunction

import properties
import numpy as np
import scipy.sparse as sp
import gc


class BaseInvProblem(Props.BaseSimPEG):
    """BaseInvProblem(dmisfit, reg, opt)"""

    #: Trade-off parameter
    beta = 1.0

    #: Print debugging information
    debug = False

    #: Set this to a SimPEG.Utils.Counter() if you want to count things
    counter = None

    #: DataMisfit
    dmisfit = None

    #: Regularization
    reg = None

    #: Optimization program
    opt = None

    #: List of strings, e.g. ['_MeSigma', '_MeSigmaI']
    deleteTheseOnModelUpdate = []

    model = Props.Model("Inversion model.")

    @properties.observer('model')
    def _on_model_update(self, value):
        """
            Sets the current model, and removes dependent properties
        """
        for prop in self.deleteTheseOnModelUpdate:
            if hasattr(self, prop):
                delattr(self, prop)

    def __init__(self, dmisfit, reg, opt, **kwargs):
        super(BaseInvProblem, self).__init__(**kwargs)
        assert (
            isinstance(dmisfit, DataMisfit.BaseDataMisfit)),
            ('dmisfit must be a DataMisfit class.'
        )
        assert (
            isinstance(reg, Regularization.BaseRegularization) or
            isinstance(reg, ObjectiveFunction.BaseObjectiveFunction)), (
            'reg must be a Regularization or Objective Function class.'
        )
        self.dmisfit = dmisfit
        self.reg = reg
        self.opt = opt
        self.prob, self.survey = dmisfit.prob, dmisfit.survey
        # TODO: Remove: (and make iteration printers better!)
        self.opt.parent = self
        self.reg.parent = self
        self.dmisfit.parent = self

    @Utils.callHooks('startup')
    def startup(self, m0):
        """startup(m0)

            Called when inversion is first starting.
        """
        if self.debug:
            print('Calling InvProblem.startup')

        if self.reg.mref is None:<commit_msg>fix assert statements in InvProblem<commit_after>from __future__ import print_function
from . import Utils
from . import Props
from . import DataMisfit
from . import Regularization
from . import ObjectiveFunction

import properties
import numpy as np
import scipy.sparse as sp
import gc


class BaseInvProblem(Props.BaseSimPEG):
    """BaseInvProblem(dmisfit, reg, opt)"""

    #: Trade-off parameter
    beta = 1.0

    #: Print debugging information
    debug = False

    #: Set this to a SimPEG.Utils.Counter() if you want to count things
    counter = None

    #: DataMisfit
    dmisfit = None

    #: Regularization
    reg = None

    #: Optimization program
    opt = None

    #: List of strings, e.g. ['_MeSigma', '_MeSigmaI']
    deleteTheseOnModelUpdate = []

    model = Props.Model("Inversion model.")

    @properties.observer('model')
    def _on_model_update(self, value):
        """
            Sets the current model, and removes dependent properties
        """
        for prop in self.deleteTheseOnModelUpdate:
            if hasattr(self, prop):
                delattr(self, prop)

    def __init__(self, dmisfit, reg, opt, **kwargs):
        super(BaseInvProblem, self).__init__(**kwargs)
        assert(
            isinstance(dmisfit, DataMisfit.BaseDataMisfit)
        ), 'dmisfit must be a DataMisfit class.'
        assert(
            isinstance(reg, Regularization.BaseRegularization) or
            isinstance(reg, ObjectiveFunction.BaseObjectiveFunction)
        ), 'reg must be a Regularization or Objective Function class.'
        self.dmisfit = dmisfit
        self.reg = reg
        self.opt = opt
        self.prob, self.survey = dmisfit.prob, dmisfit.survey
        # TODO: Remove: (and make iteration printers better!)
        self.opt.parent = self
        self.reg.parent = self
        self.dmisfit.parent = self

    @Utils.callHooks('startup')
    def startup(self, m0):
        """startup(m0)

            Called when inversion is first starting.
        """
        if self.debug:
            print('Calling InvProblem.startup')

        if self.reg.mref is None:
{'fraction_non_alphanumeric': 0.09204625914562191, 'fraction_numerical': 0.0018881283927307056, 'mean_word_length': 2.3958333333333335, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1637051', 'n_tokens_mistral': 1268, 'n_tokens_neox': 1190, 'n_words': 349}