code: def constrained(
      ave=None, var=None, ave_err=None, var_err=None, idx=0, debug=False
  ):
      "check mean and variance on the selected measure are properly constrained"
      if ave is None:
          ave = float("nan")
      if var is None:
          var = float("nan")
      if ave_err is None:
          ave_err = 0
      if var_err is None:
          var_err = 0
  
      def func(c):
          E = float(c[idx].mean)
          if E > (ave + ave_err) or E < (ave - ave_err):
              if debug:
                  print("skipping mean: %s" % E)
              return False
          E = float(c[idx].var)
          if E > (var + var_err) or E < (var - var_err):
              if debug:
                  print("skipping var: %s" % E)
              return False
          return True
  
      return func
  
file_path: mystic/examples3/misc4.py
imports: from mystic.solvers import DifferentialEvolutionSolver2, LatticeSolver, NelderMeadSimplexSolver
  from mystic.termination import ChangeOverGeneration
  from mystic.monitors import Monitor, VerboseMonitor, LoggingMonitor, VerboseLoggingMonitor
  from mystic.bounds import Bounds, MeasureBounds
  from mystic.math.discrete import product_measure
  from mystic.math import almostEqual
  from mystic.constraints import and_, integers
  from mystic.coupler import outer, additive
  from emulators import cost4, x4, bounds4, error4, wR
  from mystic import suppressed
  from ouq_models import WrapModel
label_desc: Use image node_id 6 for calling a global function with example usage: constrained(ave, var, ave_err, var_err, idx, debug) and returns: func, True, False, False