code: def as_penalty(constraint, ptype=None, *args, **kwds):
      """Convert a constraints solver to a penalty function.
  
      Inputs:
          constraint -- a constraints solver
          ptype -- penalty function type [default: quadratic_equality]
  
      Additional Inputs:
          args -- arguments for the constraints solver [default: ()]
          kwds -- keyword arguments for the constraints solver [default: {}]
          k -- penalty multiplier
          h -- iterative multiplier
      """
  
      def rnorm(x, *argz, **kwdz):
          error = 0.0
          constrained = constraint(x, *argz, **kwdz)
          for i in range(len(x)):
              error += (
                  constrained[i] - x[i]
              ) ** 2  # XXX: better rnorm ?
          error = error**0.5
          return error
  
      if ptype is None:
          from mystic.penalty import quadratic_equality
  
          ptype = quadratic_equality
  
      @ptype(rnorm, *args, **kwds)  # XXX: yes to k,h... but otherwise?
      def penalty(x):
          return 0.0
  
      penalty.func = rnorm
      penalty.ptype = ptype.__name__
      return penalty
  
imports: from mystic.math.measures import *
  from mystic.math import almostEqual
  from numpy import sum
  from numpy import asfarray, asarray, choose, zeros, ones, ndarray
  from numpy import shape, broadcast, empty, atleast_1d
  from numpy import round, abs
  from random import randrange, shuffle
  from numpy import array, intersect1d, inf, isnan, where, choose, clip
  from numpy.random import uniform, choice
  from numpy import maximum, minimum
  from numpy import round, abs
  from mystic.tools import synchronized, connected
  from mystic.math.discrete import product_measure
label_desc: Use image node_id 12 for calling a global function with example usage: as_penalty(constraint, ptype) and returns: penalty, error, int