In [1]:
import numpy as np
from pycalphad import Model, Database, calculate, equilibrium
import pycalphad.variables as v

#dbf = Database('2016-08-10-AlGdMgand18RLPSO-for 3d plot.tdb')
dbf = Database('alfe_sei.TDB')
models = {key: Model(dbf, ['AL', 'FE', 'VA'], key) for key in dbf.phases.keys()}

In [2]:
#Set compiler directives (cf. http://docs.cython.org/src/reference/compilation.html)
%load_ext cython
from Cython.Compiler.Options import _directive_defaults

_directive_defaults['linetrace'] = True
_directive_defaults['binding'] = True


/home/rotis/anaconda/envs/calphadpy3/lib/python3.5/site-packages/Cython/Distutils/old_build_ext.py:30: UserWarning: Cython.Distutils.old_build_ext does not properly handle dependencies and is deprecated.
  "Cython.Distutils.old_build_ext does not properly handle dependencies "

In [29]:
%%cython -a -f --compile-args=-DCYTHON_TRACE=1
cimport numpy as np
import numpy as np
from collections import defaultdict, OrderedDict
import copy
import itertools
import scipy.spatial
from pycalphad.core.sympydiff_utils import build_functions as compiled_build_functions
from pycalphad.core.constants import MIN_SITE_FRACTION, COMP_DIFFERENCE_TOL
from pycalphad.core.phase_rec cimport PhaseRecord, obj, grad, hess, mass_obj, mass_grad, mass_hess
from pycalphad.core.cache import cacheit
import pycalphad.variables as v
from pycalphad.core.eqsolver import _compute_phase_dof
cimport cython

@cython.boundscheck(False)
@cython.wraparound(False)
def _compute_constraints(object dbf, object comps, object phases,
                         object cur_conds, np.ndarray[dtype=np.float64_t, ndim=1] site_fracs,
                         np.ndarray[dtype=np.float64_t, ndim=1] phase_fracs, object phase_records):
    """
    Compute the constraint vector and constraint Jacobian matrix.
    """
    cdef int num_sitefrac_bals = sum([len(dbf.phases[i].sublattices) for i in phases])
    cdef int num_mass_bals = len([i for i in cur_conds.keys() if i.startswith('X_')]) + 1
    cdef double indep_sum = sum([float(val) for i, val in cur_conds.items() if i.startswith('X_')])
    cdef double[::1] comp_obj_value = np.atleast_1d(np.zeros(1))
    cdef object dependent_comp = set(comps) - set([i[2:] for i in cur_conds.keys() if i.startswith('X_')]) - {'VA'}
    dependent_comp = list(dependent_comp)[0]
    cdef int num_constraints = num_sitefrac_bals + num_mass_bals
    cdef int num_phases = len(phases)
    cdef int num_vars = len(site_fracs) + num_phases
    cdef np.ndarray[ndim=1, dtype=np.int_t] phase_dof = _compute_phase_dof(dbf, comps, phases)
    cdef np.ndarray[ndim=1, dtype=np.float64_t] l_constraints = np.zeros(num_constraints)
    cdef np.ndarray[ndim=2, dtype=np.float64_t] constraint_jac = np.zeros((num_constraints, num_vars))
    cdef np.ndarray[ndim=3, dtype=np.float64_t] constraint_hess = np.zeros((num_constraints, num_vars, num_vars), order='F')
    cdef double[::1] sfview
    cdef double[::1] comp_grad_value
    cdef double[::1,:] comp_hess_value
    cdef int phase_idx, var_offset, constraint_offset, var_idx, iter_idx, grad_idx, hess_idx, comp_idx, idx
    cdef PhaseRecord prn
    cdef double phase_frac

    # Ordering of constraints by row: sitefrac bal of each phase, then component mass balance
    # Ordering of constraints by column: site fractions of each phase, then phase fractions
    # First: Site fraction balance constraints
    var_idx = 0
    constraint_offset = 0
    for phase_idx in range(num_phases):
        name = phases[phase_idx]
        for idx in range(len(dbf.phases[name].sublattices)):
            active_in_subl = set(dbf.phases[name].constituents[idx]).intersection(comps)
            ais_len = len(active_in_subl)
            constraint_jac[constraint_offset + idx,
            var_idx:var_idx + ais_len] = 1
            l_constraints[constraint_offset + idx] = \
                (sum(site_fracs[var_idx:var_idx + ais_len]) - 1)
            var_idx += ais_len
        constraint_offset += len(dbf.phases[name].sublattices)
    # Second: Mass balance of each component
    for comp_idx, comp in enumerate(comps):
        if comp == 'VA':
            continue
        var_offset = 0
        phase_idx = 0
        for phase_idx in range(num_phases):
            name = phases[phase_idx]
            prn = phase_records[name]
            phase_frac = phase_fracs[phase_idx]
            spidx = len(site_fracs) + phase_idx
            sfview = site_fracs[var_offset:var_offset + phase_dof[phase_idx]]
            comp_hess_value = np.zeros((phase_dof[phase_idx], phase_dof[phase_idx]), order='F')
            comp_grad_value = np.zeros(phase_dof[phase_idx])
            with nogil:
                mass_obj(prn, comp_obj_value, sfview, comp_idx)
                mass_grad(prn, comp_grad_value, sfview, comp_idx)
                mass_hess(prn, comp_hess_value, sfview, comp_idx)
                # current phase frac times the comp_grad
                for grad_idx in range(var_offset, var_offset + phase_dof[phase_idx]):
                    constraint_jac[constraint_offset, grad_idx] = \
                        phase_frac * comp_grad_value[grad_idx - var_offset]
                    constraint_hess[constraint_offset, spidx, grad_idx] = comp_grad_value[grad_idx - var_offset]
                    constraint_hess[constraint_offset, grad_idx, spidx] = comp_grad_value[grad_idx - var_offset]
                    for hess_idx in range(var_offset, var_offset + phase_dof[phase_idx]):
                        constraint_hess[constraint_offset, grad_idx, hess_idx] = phase_frac * comp_hess_value[grad_idx - var_offset, hess_idx - var_offset]
                l_constraints[constraint_offset] += phase_frac * comp_obj_value[0]
                constraint_jac[constraint_offset, spidx] += comp_obj_value[0]
                var_offset += phase_dof[phase_idx]
        if comp != dependent_comp:
            l_constraints[constraint_offset] -= float(cur_conds['X_' + comp])
        else:
            # TODO: Assuming N=1 (fixed for dependent component)
            l_constraints[constraint_offset] -= (1 - indep_sum)
        constraint_offset += 1
    return l_constraints, constraint_jac, constraint_hess


Out[29]:
Cython: _cython_magic_07b8d211ecceae831b3e5546c95de0f8.pyx

Generated by Cython 0.25.1

Yellow lines hint at Python interaction.
Click on a line that starts with a "+" to see the C code that Cython generated for it.

+01: cimport numpy as np
  __Pyx_TraceLine(1,0,__PYX_ERR(0, 1, __pyx_L1_error))
  __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_2) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+02: import numpy as np
  __Pyx_TraceLine(2,0,__PYX_ERR(0, 2, __pyx_L1_error))
  __pyx_t_2 = __Pyx_Import(__pyx_n_s_numpy, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_np, __pyx_t_2) < 0) __PYX_ERR(0, 2, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+03: from collections import defaultdict, OrderedDict
  __Pyx_TraceLine(3,0,__PYX_ERR(0, 3, __pyx_L1_error))
  __pyx_t_2 = PyList_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_n_s_defaultdict);
  __Pyx_GIVEREF(__pyx_n_s_defaultdict);
  PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_defaultdict);
  __Pyx_INCREF(__pyx_n_s_OrderedDict);
  __Pyx_GIVEREF(__pyx_n_s_OrderedDict);
  PyList_SET_ITEM(__pyx_t_2, 1, __pyx_n_s_OrderedDict);
  __pyx_t_3 = __Pyx_Import(__pyx_n_s_collections, __pyx_t_2, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_defaultdict); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_defaultdict, __pyx_t_2) < 0) __PYX_ERR(0, 3, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_OrderedDict); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_OrderedDict, __pyx_t_2) < 0) __PYX_ERR(0, 3, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+04: import copy
  __Pyx_TraceLine(4,0,__PYX_ERR(0, 4, __pyx_L1_error))
  __pyx_t_3 = __Pyx_Import(__pyx_n_s_copy, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_copy, __pyx_t_3) < 0) __PYX_ERR(0, 4, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+05: import itertools
  __Pyx_TraceLine(5,0,__PYX_ERR(0, 5, __pyx_L1_error))
  __pyx_t_3 = __Pyx_Import(__pyx_n_s_itertools, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_itertools, __pyx_t_3) < 0) __PYX_ERR(0, 5, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+06: import scipy.spatial
  __Pyx_TraceLine(6,0,__PYX_ERR(0, 6, __pyx_L1_error))
  __pyx_t_3 = __Pyx_Import(__pyx_n_s_scipy_spatial, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 6, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_scipy, __pyx_t_3) < 0) __PYX_ERR(0, 6, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+07: from pycalphad.core.sympydiff_utils import build_functions as compiled_build_functions
  __Pyx_TraceLine(7,0,__PYX_ERR(0, 7, __pyx_L1_error))
  __pyx_t_3 = PyList_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 7, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_n_s_build_functions);
  __Pyx_GIVEREF(__pyx_n_s_build_functions);
  PyList_SET_ITEM(__pyx_t_3, 0, __pyx_n_s_build_functions);
  __pyx_t_2 = __Pyx_Import(__pyx_n_s_pycalphad_core_sympydiff_utils, __pyx_t_3, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 7, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_build_functions); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 7, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_compiled_build_functions, __pyx_t_3) < 0) __PYX_ERR(0, 7, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+08: from pycalphad.core.constants import MIN_SITE_FRACTION, COMP_DIFFERENCE_TOL
  __Pyx_TraceLine(8,0,__PYX_ERR(0, 8, __pyx_L1_error))
  __pyx_t_2 = PyList_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 8, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_n_s_MIN_SITE_FRACTION);
  __Pyx_GIVEREF(__pyx_n_s_MIN_SITE_FRACTION);
  PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_MIN_SITE_FRACTION);
  __Pyx_INCREF(__pyx_n_s_COMP_DIFFERENCE_TOL);
  __Pyx_GIVEREF(__pyx_n_s_COMP_DIFFERENCE_TOL);
  PyList_SET_ITEM(__pyx_t_2, 1, __pyx_n_s_COMP_DIFFERENCE_TOL);
  __pyx_t_3 = __Pyx_Import(__pyx_n_s_pycalphad_core_constants, __pyx_t_2, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 8, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_MIN_SITE_FRACTION); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 8, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_MIN_SITE_FRACTION, __pyx_t_2) < 0) __PYX_ERR(0, 8, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_COMP_DIFFERENCE_TOL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 8, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_COMP_DIFFERENCE_TOL, __pyx_t_2) < 0) __PYX_ERR(0, 8, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
 09: from pycalphad.core.phase_rec cimport PhaseRecord, obj, grad, hess, mass_obj, mass_grad, mass_hess
+10: from pycalphad.core.cache import cacheit
  __Pyx_TraceLine(10,0,__PYX_ERR(0, 10, __pyx_L1_error))
  __pyx_t_3 = PyList_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 10, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_n_s_cacheit);
  __Pyx_GIVEREF(__pyx_n_s_cacheit);
  PyList_SET_ITEM(__pyx_t_3, 0, __pyx_n_s_cacheit);
  __pyx_t_2 = __Pyx_Import(__pyx_n_s_pycalphad_core_cache, __pyx_t_3, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 10, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_cacheit); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 10, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_cacheit, __pyx_t_3) < 0) __PYX_ERR(0, 10, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+11: import pycalphad.variables as v
  __Pyx_TraceLine(11,0,__PYX_ERR(0, 11, __pyx_L1_error))
  __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 11, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_n_s__33);
  __Pyx_GIVEREF(__pyx_n_s__33);
  PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s__33);
  __pyx_t_3 = __Pyx_Import(__pyx_n_s_pycalphad_variables, __pyx_t_2, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 11, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_v, __pyx_t_3) < 0) __PYX_ERR(0, 11, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+12: from pycalphad.core.eqsolver import _compute_phase_dof
  __Pyx_TraceLine(12,0,__PYX_ERR(0, 12, __pyx_L1_error))
  __pyx_t_3 = PyList_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 12, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_n_s_compute_phase_dof);
  __Pyx_GIVEREF(__pyx_n_s_compute_phase_dof);
  PyList_SET_ITEM(__pyx_t_3, 0, __pyx_n_s_compute_phase_dof);
  __pyx_t_2 = __Pyx_Import(__pyx_n_s_pycalphad_core_eqsolver, __pyx_t_3, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 12, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_compute_phase_dof); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 12, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_compute_phase_dof, __pyx_t_3) < 0) __PYX_ERR(0, 12, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 13: cimport cython
 14: 
 15: @cython.boundscheck(False)
 16: @cython.wraparound(False)
+17: def _compute_constraints(object dbf, object comps, object phases,
/* Python wrapper */
static PyObject *__pyx_pw_46_cython_magic_07b8d211ecceae831b3e5546c95de0f8_1_compute_constraints(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_46_cython_magic_07b8d211ecceae831b3e5546c95de0f8__compute_constraints[] = "\n    Compute the constraint vector and constraint Jacobian matrix.\n    ";
static PyMethodDef __pyx_mdef_46_cython_magic_07b8d211ecceae831b3e5546c95de0f8_1_compute_constraints = {"_compute_constraints", (PyCFunction)__pyx_pw_46_cython_magic_07b8d211ecceae831b3e5546c95de0f8_1_compute_constraints, METH_VARARGS|METH_KEYWORDS, __pyx_doc_46_cython_magic_07b8d211ecceae831b3e5546c95de0f8__compute_constraints};
static PyObject *__pyx_pw_46_cython_magic_07b8d211ecceae831b3e5546c95de0f8_1_compute_constraints(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_dbf = 0;
  PyObject *__pyx_v_comps = 0;
  PyObject *__pyx_v_phases = 0;
  PyObject *__pyx_v_cur_conds = 0;
  PyArrayObject *__pyx_v_site_fracs = 0;
  PyArrayObject *__pyx_v_phase_fracs = 0;
  PyObject *__pyx_v_phase_records = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_compute_constraints (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_dbf,&__pyx_n_s_comps,&__pyx_n_s_phases,&__pyx_n_s_cur_conds,&__pyx_n_s_site_fracs,&__pyx_n_s_phase_fracs,&__pyx_n_s_phase_records,0};
    PyObject* values[7] = {0,0,0,0,0,0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_dbf)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_comps)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_compute_constraints", 1, 7, 7, 1); __PYX_ERR(0, 17, __pyx_L3_error)
        }
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_phases)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_compute_constraints", 1, 7, 7, 2); __PYX_ERR(0, 17, __pyx_L3_error)
        }
        case  3:
        if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_cur_conds)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_compute_constraints", 1, 7, 7, 3); __PYX_ERR(0, 17, __pyx_L3_error)
        }
        case  4:
        if (likely((values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_site_fracs)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_compute_constraints", 1, 7, 7, 4); __PYX_ERR(0, 17, __pyx_L3_error)
        }
        case  5:
        if (likely((values[5] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_phase_fracs)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_compute_constraints", 1, 7, 7, 5); __PYX_ERR(0, 17, __pyx_L3_error)
        }
        case  6:
        if (likely((values[6] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_phase_records)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_compute_constraints", 1, 7, 7, 6); __PYX_ERR(0, 17, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_compute_constraints") < 0)) __PYX_ERR(0, 17, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 7) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
      values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
      values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
      values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
    }
    __pyx_v_dbf = values[0];
    __pyx_v_comps = values[1];
    __pyx_v_phases = values[2];
    __pyx_v_cur_conds = values[3];
    __pyx_v_site_fracs = ((PyArrayObject *)values[4]);
    __pyx_v_phase_fracs = ((PyArrayObject *)values[5]);
    __pyx_v_phase_records = values[6];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("_compute_constraints", 1, 7, 7, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 17, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("_cython_magic_07b8d211ecceae831b3e5546c95de0f8._compute_constraints", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_site_fracs), __pyx_ptype_5numpy_ndarray, 1, "site_fracs", 0))) __PYX_ERR(0, 18, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_phase_fracs), __pyx_ptype_5numpy_ndarray, 1, "phase_fracs", 0))) __PYX_ERR(0, 19, __pyx_L1_error)
  __pyx_r = __pyx_pf_46_cython_magic_07b8d211ecceae831b3e5546c95de0f8__compute_constraints(__pyx_self, __pyx_v_dbf, __pyx_v_comps, __pyx_v_phases, __pyx_v_cur_conds, __pyx_v_site_fracs, __pyx_v_phase_fracs, __pyx_v_phase_records);

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_46_cython_magic_07b8d211ecceae831b3e5546c95de0f8__compute_constraints(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_dbf, PyObject *__pyx_v_comps, PyObject *__pyx_v_phases, PyObject *__pyx_v_cur_conds, PyArrayObject *__pyx_v_site_fracs, PyArrayObject *__pyx_v_phase_fracs, PyObject *__pyx_v_phase_records) {
  int __pyx_v_num_sitefrac_bals;
  int __pyx_v_num_mass_bals;
  double __pyx_v_indep_sum;
  __Pyx_memviewslice __pyx_v_comp_obj_value = { 0, 0, { 0 }, { 0 }, { 0 } };
  PyObject *__pyx_v_dependent_comp = 0;
  int __pyx_v_num_constraints;
  int __pyx_v_num_phases;
  int __pyx_v_num_vars;
  PyArrayObject *__pyx_v_phase_dof = 0;
  PyArrayObject *__pyx_v_l_constraints = 0;
  PyArrayObject *__pyx_v_constraint_jac = 0;
  PyArrayObject *__pyx_v_constraint_hess = 0;
  __Pyx_memviewslice __pyx_v_sfview = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_comp_grad_value = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_comp_hess_value = { 0, 0, { 0 }, { 0 }, { 0 } };
  int __pyx_v_phase_idx;
  int __pyx_v_var_offset;
  int __pyx_v_constraint_offset;
  int __pyx_v_var_idx;
  int __pyx_v_grad_idx;
  int __pyx_v_hess_idx;
  int __pyx_v_comp_idx;
  int __pyx_v_idx;
  struct PhaseRecordObject *__pyx_v_prn = 0;
  double __pyx_v_phase_frac;
  PyObject *__pyx_v_name = NULL;
  PyObject *__pyx_v_active_in_subl = NULL;
  PyObject *__pyx_v_ais_len = NULL;
  PyObject *__pyx_v_comp = NULL;
  Py_ssize_t __pyx_v_spidx;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_constraint_hess;
  __Pyx_Buffer __pyx_pybuffer_constraint_hess;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_constraint_jac;
  __Pyx_Buffer __pyx_pybuffer_constraint_jac;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_l_constraints;
  __Pyx_Buffer __pyx_pybuffer_l_constraints;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_phase_dof;
  __Pyx_Buffer __pyx_pybuffer_phase_dof;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_phase_fracs;
  __Pyx_Buffer __pyx_pybuffer_phase_fracs;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_site_fracs;
  __Pyx_Buffer __pyx_pybuffer_site_fracs;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_TraceFrameInit(__pyx_codeobj_)
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_compute_constraints", 0);
  __Pyx_TraceCall("_compute_constraints", __pyx_f[0], 17, 0, __PYX_ERR(0, 17, __pyx_L1_error));
  __pyx_pybuffer_phase_dof.pybuffer.buf = NULL;
  __pyx_pybuffer_phase_dof.refcount = 0;
  __pyx_pybuffernd_phase_dof.data = NULL;
  __pyx_pybuffernd_phase_dof.rcbuffer = &__pyx_pybuffer_phase_dof;
  __pyx_pybuffer_l_constraints.pybuffer.buf = NULL;
  __pyx_pybuffer_l_constraints.refcount = 0;
  __pyx_pybuffernd_l_constraints.data = NULL;
  __pyx_pybuffernd_l_constraints.rcbuffer = &__pyx_pybuffer_l_constraints;
  __pyx_pybuffer_constraint_jac.pybuffer.buf = NULL;
  __pyx_pybuffer_constraint_jac.refcount = 0;
  __pyx_pybuffernd_constraint_jac.data = NULL;
  __pyx_pybuffernd_constraint_jac.rcbuffer = &__pyx_pybuffer_constraint_jac;
  __pyx_pybuffer_constraint_hess.pybuffer.buf = NULL;
  __pyx_pybuffer_constraint_hess.refcount = 0;
  __pyx_pybuffernd_constraint_hess.data = NULL;
  __pyx_pybuffernd_constraint_hess.rcbuffer = &__pyx_pybuffer_constraint_hess;
  __pyx_pybuffer_site_fracs.pybuffer.buf = NULL;
  __pyx_pybuffer_site_fracs.refcount = 0;
  __pyx_pybuffernd_site_fracs.data = NULL;
  __pyx_pybuffernd_site_fracs.rcbuffer = &__pyx_pybuffer_site_fracs;
  __pyx_pybuffer_phase_fracs.pybuffer.buf = NULL;
  __pyx_pybuffer_phase_fracs.refcount = 0;
  __pyx_pybuffernd_phase_fracs.data = NULL;
  __pyx_pybuffernd_phase_fracs.rcbuffer = &__pyx_pybuffer_phase_fracs;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_site_fracs.rcbuffer->pybuffer, (PyObject*)__pyx_v_site_fracs, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 17, __pyx_L1_error)
  }
  __pyx_pybuffernd_site_fracs.diminfo[0].strides = __pyx_pybuffernd_site_fracs.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_site_fracs.diminfo[0].shape = __pyx_pybuffernd_site_fracs.rcbuffer->pybuffer.shape[0];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_phase_fracs.rcbuffer->pybuffer, (PyObject*)__pyx_v_phase_fracs, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 17, __pyx_L1_error)
  }
  __pyx_pybuffernd_phase_fracs.diminfo[0].strides = __pyx_pybuffernd_phase_fracs.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_phase_fracs.diminfo[0].shape = __pyx_pybuffernd_phase_fracs.rcbuffer->pybuffer.shape[0];
/* … */
  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_12);
  __PYX_XDEC_MEMVIEW(&__pyx_t_13, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_26, 1);
  __Pyx_XDECREF(__pyx_t_28);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_constraint_hess.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_constraint_jac.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_l_constraints.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_phase_dof.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_phase_fracs.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_site_fracs.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("_cython_magic_07b8d211ecceae831b3e5546c95de0f8._compute_constraints", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_constraint_hess.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_constraint_jac.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_l_constraints.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_phase_dof.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_phase_fracs.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_site_fracs.rcbuffer->pybuffer);
  __pyx_L2:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_comp_obj_value, 1);
  __Pyx_XDECREF(__pyx_v_dependent_comp);
  __Pyx_XDECREF((PyObject *)__pyx_v_phase_dof);
  __Pyx_XDECREF((PyObject *)__pyx_v_l_constraints);
  __Pyx_XDECREF((PyObject *)__pyx_v_constraint_jac);
  __Pyx_XDECREF((PyObject *)__pyx_v_constraint_hess);
  __PYX_XDEC_MEMVIEW(&__pyx_v_sfview, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_comp_grad_value, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_comp_hess_value, 1);
  __Pyx_XDECREF((PyObject *)__pyx_v_prn);
  __Pyx_XDECREF(__pyx_v_name);
  __Pyx_XDECREF(__pyx_v_active_in_subl);
  __Pyx_XDECREF(__pyx_v_ais_len);
  __Pyx_XDECREF(__pyx_v_comp);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
/* … */
  __pyx_tuple__34 = PyTuple_Pack(38, __pyx_n_s_dbf, __pyx_n_s_comps, __pyx_n_s_phases, __pyx_n_s_cur_conds, __pyx_n_s_site_fracs, __pyx_n_s_phase_fracs, __pyx_n_s_phase_records, __pyx_n_s_num_sitefrac_bals, __pyx_n_s_num_mass_bals, __pyx_n_s_indep_sum, __pyx_n_s_comp_obj_value, __pyx_n_s_dependent_comp, __pyx_n_s_num_constraints, __pyx_n_s_num_phases, __pyx_n_s_num_vars, __pyx_n_s_phase_dof, __pyx_n_s_l_constraints, __pyx_n_s_constraint_jac, __pyx_n_s_constraint_hess, __pyx_n_s_sfview, __pyx_n_s_comp_grad_value, __pyx_n_s_comp_hess_value, __pyx_n_s_phase_idx, __pyx_n_s_var_offset, __pyx_n_s_constraint_offset, __pyx_n_s_var_idx, __pyx_n_s_iter_idx, __pyx_n_s_grad_idx, __pyx_n_s_hess_idx, __pyx_n_s_comp_idx, __pyx_n_s_idx, __pyx_n_s_prn, __pyx_n_s_phase_frac, __pyx_n_s_name, __pyx_n_s_active_in_subl, __pyx_n_s_ais_len, __pyx_n_s_comp, __pyx_n_s_spidx); if (unlikely(!__pyx_tuple__34)) __PYX_ERR(0, 17, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__34);
  __Pyx_GIVEREF(__pyx_tuple__34);
/* … */
  __Pyx_TraceLine(17,0,__PYX_ERR(0, 17, __pyx_L1_error))
  __pyx_t_2 = __Pyx_CyFunction_NewEx(&__pyx_mdef_46_cython_magic_07b8d211ecceae831b3e5546c95de0f8_1_compute_constraints, 0, __pyx_n_s_compute_constraints, NULL, __pyx_n_s_cython_magic_07b8d211ecceae831b, __pyx_d, ((PyObject *)__pyx_codeobj_)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 17, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_compute_constraints, __pyx_t_2) < 0) __PYX_ERR(0, 17, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_codeobj_ = (PyObject*)__Pyx_PyCode_New(7, 0, 38, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__34, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_rotis_cache_ipython_cython, __pyx_n_s_compute_constraints, 17, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj_)) __PYX_ERR(0, 17, __pyx_L1_error)
 18:                          object cur_conds, np.ndarray[dtype=np.float64_t, ndim=1] site_fracs,
 19:                          np.ndarray[dtype=np.float64_t, ndim=1] phase_fracs, object phase_records):
 20:     """
 21:     Compute the constraint vector and constraint Jacobian matrix.
 22:     """
+23:     cdef int num_sitefrac_bals = sum([len(dbf.phases[i].sublattices) for i in phases])
  __Pyx_TraceLine(23,0,__PYX_ERR(0, 23, __pyx_L1_error))
  { /* enter inner scope */
    PyObject *__pyx_7genexpr__pyx_v_i = NULL;
    __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 23, __pyx_L5_error)
    __Pyx_GOTREF(__pyx_t_1);
    if (likely(PyList_CheckExact(__pyx_v_phases)) || PyTuple_CheckExact(__pyx_v_phases)) {
      __pyx_t_2 = __pyx_v_phases; __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = 0;
      __pyx_t_4 = NULL;
    } else {
      __pyx_t_3 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_phases); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 23, __pyx_L5_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_4 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 23, __pyx_L5_error)
    }
    for (;;) {
      if (likely(!__pyx_t_4)) {
        if (likely(PyList_CheckExact(__pyx_t_2))) {
          if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_2)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_5 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_5); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 23, __pyx_L5_error)
          #else
          __pyx_t_5 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 23, __pyx_L5_error)
          __Pyx_GOTREF(__pyx_t_5);
          #endif
        } else {
          if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_5); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 23, __pyx_L5_error)
          #else
          __pyx_t_5 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 23, __pyx_L5_error)
          __Pyx_GOTREF(__pyx_t_5);
          #endif
        }
      } else {
        __pyx_t_5 = __pyx_t_4(__pyx_t_2);
        if (unlikely(!__pyx_t_5)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else __PYX_ERR(0, 23, __pyx_L5_error)
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_5);
      }
      __Pyx_XDECREF_SET(__pyx_7genexpr__pyx_v_i, __pyx_t_5);
      __pyx_t_5 = 0;
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_dbf, __pyx_n_s_phases); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 23, __pyx_L5_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_6 = PyObject_GetItem(__pyx_t_5, __pyx_7genexpr__pyx_v_i); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 23, __pyx_L5_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_sublattices); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 23, __pyx_L5_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_7 = PyObject_Length(__pyx_t_5); if (unlikely(__pyx_t_7 == -1)) __PYX_ERR(0, 23, __pyx_L5_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_5 = PyInt_FromSsize_t(__pyx_t_7); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 23, __pyx_L5_error)
      __Pyx_GOTREF(__pyx_t_5);
      if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_5))) __PYX_ERR(0, 23, __pyx_L5_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_XDECREF(__pyx_7genexpr__pyx_v_i);
    goto __pyx_L8_exit_scope;
    __pyx_L5_error:;
    __Pyx_XDECREF(__pyx_7genexpr__pyx_v_i);
    goto __pyx_L1_error;
    __pyx_L8_exit_scope:;
  } /* exit inner scope */
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 23, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_sum, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 23, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_8 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 23, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_num_sitefrac_bals = __pyx_t_8;
+24:     cdef int num_mass_bals = len([i for i in cur_conds.keys() if i.startswith('X_')]) + 1
  __Pyx_TraceLine(24,0,__PYX_ERR(0, 24, __pyx_L1_error))
  { /* enter inner scope */
    PyObject *__pyx_8genexpr1__pyx_v_i = NULL;
    __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 24, __pyx_L11_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = 0;
    if (unlikely(__pyx_v_cur_conds == Py_None)) {
      PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%s'", "keys");
      __PYX_ERR(0, 24, __pyx_L11_error)
    }
    __pyx_t_5 = __Pyx_dict_iterator(__pyx_v_cur_conds, 0, __pyx_n_s_keys, (&__pyx_t_7), (&__pyx_t_8)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 24, __pyx_L11_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_XDECREF(__pyx_t_2);
    __pyx_t_2 = __pyx_t_5;
    __pyx_t_5 = 0;
    while (1) {
      __pyx_t_9 = __Pyx_dict_iter_next(__pyx_t_2, __pyx_t_7, &__pyx_t_3, &__pyx_t_5, NULL, NULL, __pyx_t_8);
      if (unlikely(__pyx_t_9 == 0)) break;
      if (unlikely(__pyx_t_9 == -1)) __PYX_ERR(0, 24, __pyx_L11_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_XDECREF_SET(__pyx_8genexpr1__pyx_v_i, __pyx_t_5);
      __pyx_t_5 = 0;
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_8genexpr1__pyx_v_i, __pyx_n_s_startswith); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 24, __pyx_L11_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_tuple__2, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 24, __pyx_L11_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 24, __pyx_L11_error)
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      if (__pyx_t_10) {
        if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_8genexpr1__pyx_v_i))) __PYX_ERR(0, 24, __pyx_L11_error)
      }
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_XDECREF(__pyx_8genexpr1__pyx_v_i);
    goto __pyx_L15_exit_scope;
    __pyx_L11_error:;
    __Pyx_XDECREF(__pyx_8genexpr1__pyx_v_i);
    goto __pyx_L1_error;
    __pyx_L15_exit_scope:;
  } /* exit inner scope */
  __pyx_t_7 = PyList_GET_SIZE(__pyx_t_1); if (unlikely(__pyx_t_7 == -1)) __PYX_ERR(0, 24, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_num_mass_bals = (__pyx_t_7 + 1);
/* … */
  __pyx_tuple__2 = PyTuple_Pack(1, __pyx_n_u_X); if (unlikely(!__pyx_tuple__2)) __PYX_ERR(0, 24, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__2);
  __Pyx_GIVEREF(__pyx_tuple__2);
+25:     cdef double indep_sum = sum([float(val) for i, val in cur_conds.items() if i.startswith('X_')])
  __Pyx_TraceLine(25,0,__PYX_ERR(0, 25, __pyx_L1_error))
  { /* enter inner scope */
    PyObject *__pyx_8genexpr2__pyx_v_i = NULL;
    PyObject *__pyx_8genexpr2__pyx_v_val = NULL;
    __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 25, __pyx_L18_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_7 = 0;
    if (unlikely(__pyx_v_cur_conds == Py_None)) {
      PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%s'", "items");
      __PYX_ERR(0, 25, __pyx_L18_error)
    }
    __pyx_t_6 = __Pyx_dict_iterator(__pyx_v_cur_conds, 0, __pyx_n_s_items, (&__pyx_t_3), (&__pyx_t_8)); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 25, __pyx_L18_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_XDECREF(__pyx_t_2);
    __pyx_t_2 = __pyx_t_6;
    __pyx_t_6 = 0;
    while (1) {
      __pyx_t_9 = __Pyx_dict_iter_next(__pyx_t_2, __pyx_t_3, &__pyx_t_7, &__pyx_t_6, &__pyx_t_5, NULL, __pyx_t_8);
      if (unlikely(__pyx_t_9 == 0)) break;
      if (unlikely(__pyx_t_9 == -1)) __PYX_ERR(0, 25, __pyx_L18_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_XDECREF_SET(__pyx_8genexpr2__pyx_v_i, __pyx_t_6);
      __pyx_t_6 = 0;
      __Pyx_XDECREF_SET(__pyx_8genexpr2__pyx_v_val, __pyx_t_5);
      __pyx_t_5 = 0;
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_8genexpr2__pyx_v_i, __pyx_n_s_startswith); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 25, __pyx_L18_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_tuple__3, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 25, __pyx_L18_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 25, __pyx_L18_error)
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      if (__pyx_t_10) {
        __pyx_t_6 = __Pyx_PyNumber_Float(__pyx_8genexpr2__pyx_v_val); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 25, __pyx_L18_error)
        __Pyx_GOTREF(__pyx_t_6);
        if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_6))) __PYX_ERR(0, 25, __pyx_L18_error)
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      }
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_XDECREF(__pyx_8genexpr2__pyx_v_i);
    __Pyx_XDECREF(__pyx_8genexpr2__pyx_v_val);
    goto __pyx_L22_exit_scope;
    __pyx_L18_error:;
    __Pyx_XDECREF(__pyx_8genexpr2__pyx_v_i);
    __Pyx_XDECREF(__pyx_8genexpr2__pyx_v_val);
    goto __pyx_L1_error;
    __pyx_L22_exit_scope:;
  } /* exit inner scope */
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 25, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_sum, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 25, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_11 = __pyx_PyFloat_AsDouble(__pyx_t_1); if (unlikely((__pyx_t_11 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 25, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_indep_sum = __pyx_t_11;
/* … */
  __pyx_tuple__3 = PyTuple_Pack(1, __pyx_n_u_X); if (unlikely(!__pyx_tuple__3)) __PYX_ERR(0, 25, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__3);
  __Pyx_GIVEREF(__pyx_tuple__3);
+26:     cdef double[::1] comp_obj_value = np.atleast_1d(np.zeros(1))
  __Pyx_TraceLine(26,0,__PYX_ERR(0, 26, __pyx_L1_error))
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 26, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_atleast_1d); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 26, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 26, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_zeros); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 26, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_tuple__4, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 26, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_6, function);
    }
  }
  if (!__pyx_t_5) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 26, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_6)) {
      PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_2};
      __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 26, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) {
      PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_2};
      __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 26, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    } else
    #endif
    {
      __pyx_t_12 = PyTuple_New(1+1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 26, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_12);
      __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_5); __pyx_t_5 = NULL;
      __Pyx_GIVEREF(__pyx_t_2);
      PyTuple_SET_ITEM(__pyx_t_12, 0+1, __pyx_t_2);
      __pyx_t_2 = 0;
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_12, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 26, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_13 = __Pyx_PyObject_to_MemoryviewSlice_dc_double(__pyx_t_1);
  if (unlikely(!__pyx_t_13.memview)) __PYX_ERR(0, 26, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_comp_obj_value = __pyx_t_13;
  __pyx_t_13.memview = NULL;
  __pyx_t_13.data = NULL;
/* … */
  __pyx_tuple__4 = PyTuple_Pack(1, __pyx_int_1); if (unlikely(!__pyx_tuple__4)) __PYX_ERR(0, 26, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__4);
  __Pyx_GIVEREF(__pyx_tuple__4);
+27:     cdef object dependent_comp = set(comps) - set([i[2:] for i in cur_conds.keys() if i.startswith('X_')]) - {'VA'}
  __Pyx_TraceLine(27,0,__PYX_ERR(0, 27, __pyx_L1_error))
  __pyx_t_1 = PySet_New(__pyx_v_comps); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 27, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  { /* enter inner scope */
    PyObject *__pyx_8genexpr3__pyx_v_i = NULL;
    __pyx_t_6 = PyList_New(0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 27, __pyx_L25_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_3 = 0;
    if (unlikely(__pyx_v_cur_conds == Py_None)) {
      PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%s'", "keys");
      __PYX_ERR(0, 27, __pyx_L25_error)
    }
    __pyx_t_2 = __Pyx_dict_iterator(__pyx_v_cur_conds, 0, __pyx_n_s_keys, (&__pyx_t_7), (&__pyx_t_8)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 27, __pyx_L25_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_XDECREF(__pyx_t_12);
    __pyx_t_12 = __pyx_t_2;
    __pyx_t_2 = 0;
    while (1) {
      __pyx_t_9 = __Pyx_dict_iter_next(__pyx_t_12, __pyx_t_7, &__pyx_t_3, &__pyx_t_2, NULL, NULL, __pyx_t_8);
      if (unlikely(__pyx_t_9 == 0)) break;
      if (unlikely(__pyx_t_9 == -1)) __PYX_ERR(0, 27, __pyx_L25_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_XDECREF_SET(__pyx_8genexpr3__pyx_v_i, __pyx_t_2);
      __pyx_t_2 = 0;
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_8genexpr3__pyx_v_i, __pyx_n_s_startswith); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 27, __pyx_L25_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__5, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 27, __pyx_L25_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 27, __pyx_L25_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (__pyx_t_10) {
/* … */
  __pyx_tuple__5 = PyTuple_Pack(1, __pyx_n_u_X); if (unlikely(!__pyx_tuple__5)) __PYX_ERR(0, 27, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__5);
  __Pyx_GIVEREF(__pyx_tuple__5);
        __pyx_t_5 = __Pyx_PyObject_GetSlice(__pyx_8genexpr3__pyx_v_i, 2, 0, NULL, NULL, &__pyx_slice__6, 1, 0, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 27, __pyx_L25_error)
        __Pyx_GOTREF(__pyx_t_5);
        if (unlikely(__Pyx_ListComp_Append(__pyx_t_6, (PyObject*)__pyx_t_5))) __PYX_ERR(0, 27, __pyx_L25_error)
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      }
    }
    __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    __Pyx_XDECREF(__pyx_8genexpr3__pyx_v_i);
    goto __pyx_L29_exit_scope;
    __pyx_L25_error:;
    __Pyx_XDECREF(__pyx_8genexpr3__pyx_v_i);
    goto __pyx_L1_error;
    __pyx_L29_exit_scope:;
  } /* exit inner scope */
  __pyx_t_12 = PySet_New(__pyx_t_6); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 27, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_12);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = PyNumber_Subtract(__pyx_t_1, __pyx_t_12); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 27, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
  __pyx_t_12 = PySet_New(0); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 27, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_12);
  if (PySet_Add(__pyx_t_12, __pyx_n_u_VA) < 0) __PYX_ERR(0, 27, __pyx_L1_error)
  __pyx_t_1 = PyNumber_Subtract(__pyx_t_6, __pyx_t_12); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 27, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
  __pyx_v_dependent_comp = __pyx_t_1;
  __pyx_t_1 = 0;
  __pyx_slice__6 = PySlice_New(__pyx_int_2, Py_None, Py_None); if (unlikely(!__pyx_slice__6)) __PYX_ERR(0, 27, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_slice__6);
  __Pyx_GIVEREF(__pyx_slice__6);
+28:     dependent_comp = list(dependent_comp)[0]
  __Pyx_TraceLine(28,0,__PYX_ERR(0, 28, __pyx_L1_error))
  __pyx_t_1 = PySequence_List(__pyx_v_dependent_comp); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 28, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_12 = PyList_GET_ITEM(__pyx_t_1, 0);
  __Pyx_INCREF(__pyx_t_12);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF_SET(__pyx_v_dependent_comp, __pyx_t_12);
  __pyx_t_12 = 0;
+29:     cdef int num_constraints = num_sitefrac_bals + num_mass_bals
  __Pyx_TraceLine(29,0,__PYX_ERR(0, 29, __pyx_L1_error))
  __pyx_v_num_constraints = (__pyx_v_num_sitefrac_bals + __pyx_v_num_mass_bals);
+30:     cdef int num_phases = len(phases)
  __Pyx_TraceLine(30,0,__PYX_ERR(0, 30, __pyx_L1_error))
  __pyx_t_7 = PyObject_Length(__pyx_v_phases); if (unlikely(__pyx_t_7 == -1)) __PYX_ERR(0, 30, __pyx_L1_error)
  __pyx_v_num_phases = __pyx_t_7;
+31:     cdef int num_vars = len(site_fracs) + num_phases
  __Pyx_TraceLine(31,0,__PYX_ERR(0, 31, __pyx_L1_error))
  __pyx_t_7 = PyObject_Length(((PyObject *)__pyx_v_site_fracs)); if (unlikely(__pyx_t_7 == -1)) __PYX_ERR(0, 31, __pyx_L1_error)
  __pyx_v_num_vars = (__pyx_t_7 + __pyx_v_num_phases);
+32:     cdef np.ndarray[ndim=1, dtype=np.int_t] phase_dof = _compute_phase_dof(dbf, comps, phases)
  __Pyx_TraceLine(32,0,__PYX_ERR(0, 32, __pyx_L1_error))
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_compute_phase_dof); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 32, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_6 = NULL;
  __pyx_t_8 = 0;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
    __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_1);
    if (likely(__pyx_t_6)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_6);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_1, function);
      __pyx_t_8 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_1)) {
    PyObject *__pyx_temp[4] = {__pyx_t_6, __pyx_v_dbf, __pyx_v_comps, __pyx_v_phases};
    __pyx_t_12 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_8, 3+__pyx_t_8); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 32, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_GOTREF(__pyx_t_12);
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
    PyObject *__pyx_temp[4] = {__pyx_t_6, __pyx_v_dbf, __pyx_v_comps, __pyx_v_phases};
    __pyx_t_12 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_8, 3+__pyx_t_8); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 32, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_GOTREF(__pyx_t_12);
  } else
  #endif
  {
    __pyx_t_5 = PyTuple_New(3+__pyx_t_8); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 32, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    if (__pyx_t_6) {
      __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_6); __pyx_t_6 = NULL;
    }
    __Pyx_INCREF(__pyx_v_dbf);
    __Pyx_GIVEREF(__pyx_v_dbf);
    PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_8, __pyx_v_dbf);
    __Pyx_INCREF(__pyx_v_comps);
    __Pyx_GIVEREF(__pyx_v_comps);
    PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_8, __pyx_v_comps);
    __Pyx_INCREF(__pyx_v_phases);
    __Pyx_GIVEREF(__pyx_v_phases);
    PyTuple_SET_ITEM(__pyx_t_5, 2+__pyx_t_8, __pyx_v_phases);
    __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_5, NULL); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 32, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_12);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (!(likely(((__pyx_t_12) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_12, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 32, __pyx_L1_error)
  __pyx_t_14 = ((PyArrayObject *)__pyx_t_12);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_phase_dof.rcbuffer->pybuffer, (PyObject*)__pyx_t_14, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
      __pyx_v_phase_dof = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_phase_dof.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 32, __pyx_L1_error)
    } else {__pyx_pybuffernd_phase_dof.diminfo[0].strides = __pyx_pybuffernd_phase_dof.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_phase_dof.diminfo[0].shape = __pyx_pybuffernd_phase_dof.rcbuffer->pybuffer.shape[0];
    }
  }
  __pyx_t_14 = 0;
  __pyx_v_phase_dof = ((PyArrayObject *)__pyx_t_12);
  __pyx_t_12 = 0;
+33:     cdef np.ndarray[ndim=1, dtype=np.float64_t] l_constraints = np.zeros(num_constraints)
  __Pyx_TraceLine(33,0,__PYX_ERR(0, 33, __pyx_L1_error))
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 33, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_zeros); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 33, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_num_constraints); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 33, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_6 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
    __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
    if (likely(__pyx_t_6)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_6);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_5, function);
    }
  }
  if (!__pyx_t_6) {
    __pyx_t_12 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 33, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_GOTREF(__pyx_t_12);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_5)) {
      PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_t_1};
      __pyx_t_12 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 33, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_GOTREF(__pyx_t_12);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) {
      PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_t_1};
      __pyx_t_12 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 33, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_GOTREF(__pyx_t_12);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    } else
    #endif
    {
      __pyx_t_2 = PyTuple_New(1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 33, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_6); __pyx_t_6 = NULL;
      __Pyx_GIVEREF(__pyx_t_1);
      PyTuple_SET_ITEM(__pyx_t_2, 0+1, __pyx_t_1);
      __pyx_t_1 = 0;
      __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_2, NULL); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 33, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_12);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (!(likely(((__pyx_t_12) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_12, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 33, __pyx_L1_error)
  __pyx_t_15 = ((PyArrayObject *)__pyx_t_12);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_l_constraints.rcbuffer->pybuffer, (PyObject*)__pyx_t_15, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) {
      __pyx_v_l_constraints = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_l_constraints.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 33, __pyx_L1_error)
    } else {__pyx_pybuffernd_l_constraints.diminfo[0].strides = __pyx_pybuffernd_l_constraints.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_l_constraints.diminfo[0].shape = __pyx_pybuffernd_l_constraints.rcbuffer->pybuffer.shape[0];
    }
  }
  __pyx_t_15 = 0;
  __pyx_v_l_constraints = ((PyArrayObject *)__pyx_t_12);
  __pyx_t_12 = 0;
+34:     cdef np.ndarray[ndim=2, dtype=np.float64_t] constraint_jac = np.zeros((num_constraints, num_vars))
  __Pyx_TraceLine(34,0,__PYX_ERR(0, 34, __pyx_L1_error))
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 34, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_zeros); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 34, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_num_constraints); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 34, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_num_vars); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 34, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 34, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_1);
  __pyx_t_5 = 0;
  __pyx_t_1 = 0;
  __pyx_t_1 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_1)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  if (!__pyx_t_1) {
    __pyx_t_12 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_6); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 34, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_GOTREF(__pyx_t_12);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_t_6};
      __pyx_t_12 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 34, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_GOTREF(__pyx_t_12);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_t_6};
      __pyx_t_12 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 34, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_GOTREF(__pyx_t_12);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    } else
    #endif
    {
      __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 34, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_1); __pyx_t_1 = NULL;
      __Pyx_GIVEREF(__pyx_t_6);
      PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_t_6);
      __pyx_t_6 = 0;
      __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 34, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_12);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (!(likely(((__pyx_t_12) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_12, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 34, __pyx_L1_error)
  __pyx_t_16 = ((PyArrayObject *)__pyx_t_12);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_constraint_jac.rcbuffer->pybuffer, (PyObject*)__pyx_t_16, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) {
      __pyx_v_constraint_jac = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_constraint_jac.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 34, __pyx_L1_error)
    } else {__pyx_pybuffernd_constraint_jac.diminfo[0].strides = __pyx_pybuffernd_constraint_jac.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_constraint_jac.diminfo[0].shape = __pyx_pybuffernd_constraint_jac.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_constraint_jac.diminfo[1].strides = __pyx_pybuffernd_constraint_jac.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_constraint_jac.diminfo[1].shape = __pyx_pybuffernd_constraint_jac.rcbuffer->pybuffer.shape[1];
    }
  }
  __pyx_t_16 = 0;
  __pyx_v_constraint_jac = ((PyArrayObject *)__pyx_t_12);
  __pyx_t_12 = 0;
+35:     cdef np.ndarray[ndim=3, dtype=np.float64_t] constraint_hess = np.zeros((num_constraints, num_vars, num_vars), order='F')
  __Pyx_TraceLine(35,0,__PYX_ERR(0, 35, __pyx_L1_error))
  __pyx_t_12 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_12);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_n_s_zeros); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
  __pyx_t_12 = __Pyx_PyInt_From_int(__pyx_v_num_constraints); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_12);
  __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_num_vars); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_num_vars); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_12);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_12);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_t_6);
  __pyx_t_12 = 0;
  __pyx_t_5 = 0;
  __pyx_t_6 = 0;
  __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_order, __pyx_n_u_F) < 0) __PYX_ERR(0, 35, __pyx_L1_error)
  __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_6, __pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 35, __pyx_L1_error)
  __pyx_t_17 = ((PyArrayObject *)__pyx_t_5);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_constraint_hess.rcbuffer->pybuffer, (PyObject*)__pyx_t_17, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 3, 0, __pyx_stack) == -1)) {
      __pyx_v_constraint_hess = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_constraint_hess.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 35, __pyx_L1_error)
    } else {__pyx_pybuffernd_constraint_hess.diminfo[0].strides = __pyx_pybuffernd_constraint_hess.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_constraint_hess.diminfo[0].shape = __pyx_pybuffernd_constraint_hess.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_constraint_hess.diminfo[1].strides = __pyx_pybuffernd_constraint_hess.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_constraint_hess.diminfo[1].shape = __pyx_pybuffernd_constraint_hess.rcbuffer->pybuffer.shape[1]; __pyx_pybuffernd_constraint_hess.diminfo[2].strides = __pyx_pybuffernd_constraint_hess.rcbuffer->pybuffer.strides[2]; __pyx_pybuffernd_constraint_hess.diminfo[2].shape = __pyx_pybuffernd_constraint_hess.rcbuffer->pybuffer.shape[2];
    }
  }
  __pyx_t_17 = 0;
  __pyx_v_constraint_hess = ((PyArrayObject *)__pyx_t_5);
  __pyx_t_5 = 0;
 36:     cdef double[::1] sfview
 37:     cdef double[::1] comp_grad_value
 38:     cdef double[::1,:] comp_hess_value
 39:     cdef int phase_idx, var_offset, constraint_offset, var_idx, iter_idx, grad_idx, hess_idx, comp_idx, idx
 40:     cdef PhaseRecord prn
 41:     cdef double phase_frac
 42: 
 43:     # Ordering of constraints by row: sitefrac bal of each phase, then component mass balance
 44:     # Ordering of constraints by column: site fractions of each phase, then phase fractions
 45:     # First: Site fraction balance constraints
+46:     var_idx = 0
  __Pyx_TraceLine(46,0,__PYX_ERR(0, 46, __pyx_L1_error))
  __pyx_v_var_idx = 0;
+47:     constraint_offset = 0
  __Pyx_TraceLine(47,0,__PYX_ERR(0, 47, __pyx_L1_error))
  __pyx_v_constraint_offset = 0;
+48:     for phase_idx in range(num_phases):
  __Pyx_TraceLine(48,0,__PYX_ERR(0, 48, __pyx_L1_error))
  __pyx_t_8 = __pyx_v_num_phases;
  for (__pyx_t_9 = 0; __pyx_t_9 < __pyx_t_8; __pyx_t_9+=1) {
    __pyx_v_phase_idx = __pyx_t_9;
+49:         name = phases[phase_idx]
    __Pyx_TraceLine(49,0,__PYX_ERR(0, 49, __pyx_L1_error))
    __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_phases, __pyx_v_phase_idx, int, 1, __Pyx_PyInt_From_int, 0, 0, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 49, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_XDECREF_SET(__pyx_v_name, __pyx_t_5);
    __pyx_t_5 = 0;
+50:         for idx in range(len(dbf.phases[name].sublattices)):
    __Pyx_TraceLine(50,0,__PYX_ERR(0, 50, __pyx_L1_error))
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_dbf, __pyx_n_s_phases); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 50, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_1 = PyObject_GetItem(__pyx_t_5, __pyx_v_name); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 50, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_sublattices); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 50, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_7 = PyObject_Length(__pyx_t_5); if (unlikely(__pyx_t_7 == -1)) __PYX_ERR(0, 50, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    for (__pyx_t_18 = 0; __pyx_t_18 < __pyx_t_7; __pyx_t_18+=1) {
      __pyx_v_idx = __pyx_t_18;
+51:             active_in_subl = set(dbf.phases[name].constituents[idx]).intersection(comps)
      __Pyx_TraceLine(51,0,__PYX_ERR(0, 51, __pyx_L1_error))
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_dbf, __pyx_n_s_phases); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 51, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_6 = PyObject_GetItem(__pyx_t_1, __pyx_v_name); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 51, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_constituents); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 51, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = __Pyx_GetItemInt(__pyx_t_1, __pyx_v_idx, int, 1, __Pyx_PyInt_From_int, 0, 0, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 51, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = PySet_New(__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 51, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_intersection); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 51, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
        __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_6);
        if (likely(__pyx_t_1)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
          __Pyx_INCREF(__pyx_t_1);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_6, function);
        }
      }
      if (!__pyx_t_1) {
        __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_v_comps); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 51, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
      } else {
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_6)) {
          PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_v_comps};
          __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 51, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
          __Pyx_GOTREF(__pyx_t_5);
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) {
          PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_v_comps};
          __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 51, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
          __Pyx_GOTREF(__pyx_t_5);
        } else
        #endif
        {
          __pyx_t_2 = PyTuple_New(1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 51, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1); __pyx_t_1 = NULL;
          __Pyx_INCREF(__pyx_v_comps);
          __Pyx_GIVEREF(__pyx_v_comps);
          PyTuple_SET_ITEM(__pyx_t_2, 0+1, __pyx_v_comps);
          __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_2, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 51, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_5);
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        }
      }
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_XDECREF_SET(__pyx_v_active_in_subl, __pyx_t_5);
      __pyx_t_5 = 0;
+52:             ais_len = len(active_in_subl)
      __Pyx_TraceLine(52,0,__PYX_ERR(0, 52, __pyx_L1_error))
      __pyx_t_3 = PyObject_Length(__pyx_v_active_in_subl); if (unlikely(__pyx_t_3 == -1)) __PYX_ERR(0, 52, __pyx_L1_error)
      __pyx_t_5 = PyInt_FromSsize_t(__pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 52, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_XDECREF_SET(__pyx_v_ais_len, __pyx_t_5);
      __pyx_t_5 = 0;
+53:             constraint_jac[constraint_offset + idx,
      __Pyx_TraceLine(53,0,__PYX_ERR(0, 53, __pyx_L1_error))
      __pyx_t_5 = __Pyx_PyInt_From_int((__pyx_v_constraint_offset + __pyx_v_idx)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 53, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
/* … */
      __Pyx_TraceLine(53,0,__PYX_ERR(0, 53, __pyx_L1_error))
      __pyx_t_2 = PySlice_New(__pyx_t_6, __pyx_t_1, Py_None); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 53, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 53, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_GIVEREF(__pyx_t_5);
      PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_5);
      __Pyx_GIVEREF(__pyx_t_2);
      PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_2);
      __pyx_t_5 = 0;
      __pyx_t_2 = 0;
      if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_constraint_jac), __pyx_t_1, __pyx_int_1) < 0)) __PYX_ERR(0, 53, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+54:             var_idx:var_idx + ais_len] = 1
      __Pyx_TraceLine(54,0,__PYX_ERR(0, 54, __pyx_L1_error))
      __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_var_idx); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 54, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_var_idx); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 54, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_1 = PyNumber_Add(__pyx_t_2, __pyx_v_ais_len); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 54, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+55:             l_constraints[constraint_offset + idx] = \
      __Pyx_TraceLine(55,0,__PYX_ERR(0, 55, __pyx_L1_error))
      __pyx_t_20 = (__pyx_v_constraint_offset + __pyx_v_idx);
      *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_pybuffernd_l_constraints.rcbuffer->pybuffer.buf, __pyx_t_20, __pyx_pybuffernd_l_constraints.diminfo[0].strides) = __pyx_t_19;
+56:                 (sum(site_fracs[var_idx:var_idx + ais_len]) - 1)
      __Pyx_TraceLine(56,0,__PYX_ERR(0, 56, __pyx_L1_error))
      __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_var_idx); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 56, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_2 = PyNumber_Add(__pyx_t_1, __pyx_v_ais_len); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 56, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = __Pyx_PyObject_GetSlice(((PyObject *)__pyx_v_site_fracs), __pyx_v_var_idx, 0, NULL, &__pyx_t_2, NULL, 1, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 56, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 56, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_1);
      PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
      __pyx_t_1 = 0;
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_sum, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 56, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = __Pyx_PyInt_SubtractObjC(__pyx_t_1, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 56, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_19 = __pyx_PyFloat_AsDouble(__pyx_t_2); if (unlikely((__pyx_t_19 == ((npy_float64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 56, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+57:             var_idx += ais_len
      __Pyx_TraceLine(57,0,__PYX_ERR(0, 57, __pyx_L1_error))
      __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_var_idx); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 57, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_1 = PyNumber_InPlaceAdd(__pyx_t_2, __pyx_v_ais_len); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 57, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_21 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_21 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 57, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_v_var_idx = __pyx_t_21;
    }
+58:         constraint_offset += len(dbf.phases[name].sublattices)
    __Pyx_TraceLine(58,0,__PYX_ERR(0, 58, __pyx_L1_error))
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_dbf, __pyx_n_s_phases); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 58, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = PyObject_GetItem(__pyx_t_1, __pyx_v_name); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 58, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_sublattices); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 58, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_7 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_7 == -1)) __PYX_ERR(0, 58, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_constraint_offset = (__pyx_v_constraint_offset + __pyx_t_7);
  }
 59:     # Second: Mass balance of each component
+60:     for comp_idx, comp in enumerate(comps):
  __Pyx_TraceLine(60,0,__PYX_ERR(0, 60, __pyx_L1_error))
  __pyx_t_8 = 0;
  if (likely(PyList_CheckExact(__pyx_v_comps)) || PyTuple_CheckExact(__pyx_v_comps)) {
    __pyx_t_1 = __pyx_v_comps; __Pyx_INCREF(__pyx_t_1); __pyx_t_7 = 0;
    __pyx_t_4 = NULL;
  } else {
    __pyx_t_7 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_comps); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 60, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 60, __pyx_L1_error)
  }
  for (;;) {
    if (likely(!__pyx_t_4)) {
      if (likely(PyList_CheckExact(__pyx_t_1))) {
        if (__pyx_t_7 >= PyList_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_7); __Pyx_INCREF(__pyx_t_2); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(0, 60, __pyx_L1_error)
        #else
        __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 60, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        #endif
      } else {
        if (__pyx_t_7 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_7); __Pyx_INCREF(__pyx_t_2); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(0, 60, __pyx_L1_error)
        #else
        __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 60, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        #endif
      }
    } else {
      __pyx_t_2 = __pyx_t_4(__pyx_t_1);
      if (unlikely(!__pyx_t_2)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 60, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_2);
    }
    __Pyx_XDECREF_SET(__pyx_v_comp, __pyx_t_2);
    __pyx_t_2 = 0;
    __pyx_v_comp_idx = __pyx_t_8;
    __pyx_t_8 = (__pyx_t_8 + 1);
/* … */
    __Pyx_TraceLine(60,0,__PYX_ERR(0, 60, __pyx_L1_error))
    __pyx_L34_continue:;
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+61:         if comp == 'VA':
    __Pyx_TraceLine(61,0,__PYX_ERR(0, 61, __pyx_L1_error))
    __pyx_t_10 = (__Pyx_PyUnicode_Equals(__pyx_v_comp, __pyx_n_u_VA, Py_EQ)); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 61, __pyx_L1_error)
    if (__pyx_t_10) {
/* … */
    }
+62:             continue
      __Pyx_TraceLine(62,0,__PYX_ERR(0, 62, __pyx_L1_error))
      goto __pyx_L34_continue;
+63:         var_offset = 0
    __Pyx_TraceLine(63,0,__PYX_ERR(0, 63, __pyx_L1_error))
    __pyx_v_var_offset = 0;
+64:         phase_idx = 0
    __Pyx_TraceLine(64,0,__PYX_ERR(0, 64, __pyx_L1_error))
    __pyx_v_phase_idx = 0;
+65:         for phase_idx in range(num_phases):
    __Pyx_TraceLine(65,0,__PYX_ERR(0, 65, __pyx_L1_error))
    __pyx_t_9 = __pyx_v_num_phases;
    for (__pyx_t_18 = 0; __pyx_t_18 < __pyx_t_9; __pyx_t_18+=1) {
      __pyx_v_phase_idx = __pyx_t_18;
+66:             name = phases[phase_idx]
      __Pyx_TraceLine(66,0,__PYX_ERR(0, 66, __pyx_L1_error))
      __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_phases, __pyx_v_phase_idx, int, 1, __Pyx_PyInt_From_int, 0, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 66, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_XDECREF_SET(__pyx_v_name, __pyx_t_2);
      __pyx_t_2 = 0;
+67:             prn = phase_records[name]
      __Pyx_TraceLine(67,0,__PYX_ERR(0, 67, __pyx_L1_error))
      __pyx_t_2 = PyObject_GetItem(__pyx_v_phase_records, __pyx_v_name); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 67, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_9pycalphad_4core_9phase_rec_PhaseRecord))))) __PYX_ERR(0, 67, __pyx_L1_error)
      __Pyx_XDECREF_SET(__pyx_v_prn, ((struct PhaseRecordObject *)__pyx_t_2));
      __pyx_t_2 = 0;
+68:             phase_frac = phase_fracs[phase_idx]
      __Pyx_TraceLine(68,0,__PYX_ERR(0, 68, __pyx_L1_error))
      __pyx_t_22 = __pyx_v_phase_idx;
      __pyx_v_phase_frac = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_pybuffernd_phase_fracs.rcbuffer->pybuffer.buf, __pyx_t_22, __pyx_pybuffernd_phase_fracs.diminfo[0].strides));
+69:             spidx = len(site_fracs) + phase_idx
      __Pyx_TraceLine(69,0,__PYX_ERR(0, 69, __pyx_L1_error))
      __pyx_t_3 = PyObject_Length(((PyObject *)__pyx_v_site_fracs)); if (unlikely(__pyx_t_3 == -1)) __PYX_ERR(0, 69, __pyx_L1_error)
      __pyx_v_spidx = (__pyx_t_3 + __pyx_v_phase_idx);
+70:             sfview = site_fracs[var_offset:var_offset + phase_dof[phase_idx]]
      __Pyx_TraceLine(70,0,__PYX_ERR(0, 70, __pyx_L1_error))
      __pyx_t_23 = __pyx_v_phase_idx;
      __pyx_t_2 = __Pyx_PyObject_GetSlice(((PyObject *)__pyx_v_site_fracs), __pyx_v_var_offset, (__pyx_v_var_offset + (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int_t *, __pyx_pybuffernd_phase_dof.rcbuffer->pybuffer.buf, __pyx_t_23, __pyx_pybuffernd_phase_dof.diminfo[0].strides))), NULL, NULL, NULL, 1, 1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 70, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_13 = __Pyx_PyObject_to_MemoryviewSlice_dc_double(__pyx_t_2);
      if (unlikely(!__pyx_t_13.memview)) __PYX_ERR(0, 70, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __PYX_XDEC_MEMVIEW(&__pyx_v_sfview, 1);
      __pyx_v_sfview = __pyx_t_13;
      __pyx_t_13.memview = NULL;
      __pyx_t_13.data = NULL;
+71:             comp_hess_value = np.zeros((phase_dof[phase_idx], phase_dof[phase_idx]), order='F')
      __Pyx_TraceLine(71,0,__PYX_ERR(0, 71, __pyx_L1_error))
      __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 71, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_zeros); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 71, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_24 = __pyx_v_phase_idx;
      __pyx_t_2 = __Pyx_PyInt_From_npy_long((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int_t *, __pyx_pybuffernd_phase_dof.rcbuffer->pybuffer.buf, __pyx_t_24, __pyx_pybuffernd_phase_dof.diminfo[0].strides))); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 71, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_25 = __pyx_v_phase_idx;
      __pyx_t_6 = __Pyx_PyInt_From_npy_long((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int_t *, __pyx_pybuffernd_phase_dof.rcbuffer->pybuffer.buf, __pyx_t_25, __pyx_pybuffernd_phase_dof.diminfo[0].strides))); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 71, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_12 = PyTuple_New(2); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 71, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_12);
      __Pyx_GIVEREF(__pyx_t_2);
      PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_6);
      PyTuple_SET_ITEM(__pyx_t_12, 1, __pyx_t_6);
      __pyx_t_2 = 0;
      __pyx_t_6 = 0;
      __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 71, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_GIVEREF(__pyx_t_12);
      PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_12);
      __pyx_t_12 = 0;
      __pyx_t_12 = PyDict_New(); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 71, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_12);
      if (PyDict_SetItem(__pyx_t_12, __pyx_n_s_order, __pyx_n_u_F) < 0) __PYX_ERR(0, 71, __pyx_L1_error)
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_6, __pyx_t_12); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 71, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
      __pyx_t_26 = __Pyx_PyObject_to_MemoryviewSlice_dcd__double(__pyx_t_2);
      if (unlikely(!__pyx_t_26.memview)) __PYX_ERR(0, 71, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __PYX_XDEC_MEMVIEW(&__pyx_v_comp_hess_value, 1);
      __pyx_v_comp_hess_value = __pyx_t_26;
      __pyx_t_26.memview = NULL;
      __pyx_t_26.data = NULL;
+72:             comp_grad_value = np.zeros(phase_dof[phase_idx])
      __Pyx_TraceLine(72,0,__PYX_ERR(0, 72, __pyx_L1_error))
      __pyx_t_12 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 72, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_12);
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_n_s_zeros); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 72, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
      __pyx_t_27 = __pyx_v_phase_idx;
      __pyx_t_12 = __Pyx_PyInt_From_npy_long((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int_t *, __pyx_pybuffernd_phase_dof.rcbuffer->pybuffer.buf, __pyx_t_27, __pyx_pybuffernd_phase_dof.diminfo[0].strides))); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 72, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_12);
      __pyx_t_5 = NULL;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) {
        __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6);
        if (likely(__pyx_t_5)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
          __Pyx_INCREF(__pyx_t_5);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_6, function);
        }
      }
      if (!__pyx_t_5) {
        __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_12); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 72, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
        __Pyx_GOTREF(__pyx_t_2);
      } else {
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_6)) {
          PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_12};
          __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 72, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) {
          PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_12};
          __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 72, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
        } else
        #endif
        {
          __pyx_t_28 = PyTuple_New(1+1); if (unlikely(!__pyx_t_28)) __PYX_ERR(0, 72, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_28);
          __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_28, 0, __pyx_t_5); __pyx_t_5 = NULL;
          __Pyx_GIVEREF(__pyx_t_12);
          PyTuple_SET_ITEM(__pyx_t_28, 0+1, __pyx_t_12);
          __pyx_t_12 = 0;
          __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_28, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 72, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_28); __pyx_t_28 = 0;
        }
      }
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_13 = __Pyx_PyObject_to_MemoryviewSlice_dc_double(__pyx_t_2);
      if (unlikely(!__pyx_t_13.memview)) __PYX_ERR(0, 72, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __PYX_XDEC_MEMVIEW(&__pyx_v_comp_grad_value, 1);
      __pyx_v_comp_grad_value = __pyx_t_13;
      __pyx_t_13.memview = NULL;
      __pyx_t_13.data = NULL;
+73:             with nogil:
      __Pyx_TraceLine(73,0,__PYX_ERR(0, 73, __pyx_L1_error))
      {
          #ifdef WITH_THREAD
          PyThreadState *_save;
          Py_UNBLOCK_THREADS
          #endif
          /*try:*/ {
/* … */
          __Pyx_TraceLine(73,1,__PYX_ERR(0, 73, __pyx_L1_error))
          /*finally:*/ {
            /*normal exit:*/{
              #ifdef WITH_THREAD
              Py_BLOCK_THREADS
              #endif
              goto __pyx_L43;
            }
            __pyx_L42_error: {
              #ifdef WITH_THREAD
              Py_BLOCK_THREADS
              #endif
              goto __pyx_L1_error;
            }
            __pyx_L43:;
          }
      }
    }
+74:                 mass_obj(prn, comp_obj_value, sfview, comp_idx)
            __Pyx_TraceLine(74,1,__PYX_ERR(0, 74, __pyx_L42_error))
            __pyx_f_9pycalphad_4core_9phase_rec_mass_obj(__pyx_v_prn, __pyx_v_comp_obj_value, __pyx_v_sfview, __pyx_v_comp_idx);
+75:                 mass_grad(prn, comp_grad_value, sfview, comp_idx)
            __Pyx_TraceLine(75,1,__PYX_ERR(0, 75, __pyx_L42_error))
            __pyx_f_9pycalphad_4core_9phase_rec_mass_grad(__pyx_v_prn, __pyx_v_comp_grad_value, __pyx_v_sfview, __pyx_v_comp_idx);
+76:                 mass_hess(prn, comp_hess_value, sfview, comp_idx)
            __Pyx_TraceLine(76,1,__PYX_ERR(0, 76, __pyx_L42_error))
            __pyx_f_9pycalphad_4core_9phase_rec_mass_hess(__pyx_v_prn, __pyx_v_comp_hess_value, __pyx_v_sfview, __pyx_v_comp_idx);
 77:                 # current phase frac times the comp_grad
+78:                 for grad_idx in range(var_offset, var_offset + phase_dof[phase_idx]):
            __Pyx_TraceLine(78,1,__PYX_ERR(0, 78, __pyx_L42_error))
            __pyx_t_29 = __pyx_v_phase_idx;
            __pyx_t_30 = (__pyx_v_var_offset + (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int_t *, __pyx_pybuffernd_phase_dof.rcbuffer->pybuffer.buf, __pyx_t_29, __pyx_pybuffernd_phase_dof.diminfo[0].strides)));
            for (__pyx_t_21 = __pyx_v_var_offset; __pyx_t_21 < __pyx_t_30; __pyx_t_21+=1) {
              __pyx_v_grad_idx = __pyx_t_21;
+79:                     constraint_jac[constraint_offset, grad_idx] = \
              __Pyx_TraceLine(79,1,__PYX_ERR(0, 79, __pyx_L42_error))
              __pyx_t_32 = __pyx_v_constraint_offset;
              __pyx_t_33 = __pyx_v_grad_idx;
              *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_pybuffernd_constraint_jac.rcbuffer->pybuffer.buf, __pyx_t_32, __pyx_pybuffernd_constraint_jac.diminfo[0].strides, __pyx_t_33, __pyx_pybuffernd_constraint_jac.diminfo[1].strides) = (__pyx_v_phase_frac * (*((double *) ( /* dim=0 */ ((char *) (((double *) __pyx_v_comp_grad_value.data) + __pyx_t_31)) ))));
+80:                         phase_frac * comp_grad_value[grad_idx - var_offset]
              __Pyx_TraceLine(80,1,__PYX_ERR(0, 80, __pyx_L42_error))
              __pyx_t_31 = (__pyx_v_grad_idx - __pyx_v_var_offset);
+81:                     constraint_hess[constraint_offset, spidx, grad_idx] = comp_grad_value[grad_idx - var_offset]
              __Pyx_TraceLine(81,1,__PYX_ERR(0, 81, __pyx_L42_error))
              __pyx_t_34 = (__pyx_v_grad_idx - __pyx_v_var_offset);
              __pyx_t_35 = __pyx_v_constraint_offset;
              __pyx_t_36 = __pyx_v_spidx;
              __pyx_t_37 = __pyx_v_grad_idx;
              *__Pyx_BufPtrStrided3d(__pyx_t_5numpy_float64_t *, __pyx_pybuffernd_constraint_hess.rcbuffer->pybuffer.buf, __pyx_t_35, __pyx_pybuffernd_constraint_hess.diminfo[0].strides, __pyx_t_36, __pyx_pybuffernd_constraint_hess.diminfo[1].strides, __pyx_t_37, __pyx_pybuffernd_constraint_hess.diminfo[2].strides) = (*((double *) ( /* dim=0 */ ((char *) (((double *) __pyx_v_comp_grad_value.data) + __pyx_t_34)) )));
+82:                     constraint_hess[constraint_offset, grad_idx, spidx] = comp_grad_value[grad_idx - var_offset]
              __Pyx_TraceLine(82,1,__PYX_ERR(0, 82, __pyx_L42_error))
              __pyx_t_38 = (__pyx_v_grad_idx - __pyx_v_var_offset);
              __pyx_t_39 = __pyx_v_constraint_offset;
              __pyx_t_40 = __pyx_v_grad_idx;
              __pyx_t_41 = __pyx_v_spidx;
              *__Pyx_BufPtrStrided3d(__pyx_t_5numpy_float64_t *, __pyx_pybuffernd_constraint_hess.rcbuffer->pybuffer.buf, __pyx_t_39, __pyx_pybuffernd_constraint_hess.diminfo[0].strides, __pyx_t_40, __pyx_pybuffernd_constraint_hess.diminfo[1].strides, __pyx_t_41, __pyx_pybuffernd_constraint_hess.diminfo[2].strides) = (*((double *) ( /* dim=0 */ ((char *) (((double *) __pyx_v_comp_grad_value.data) + __pyx_t_38)) )));
+83:                     for hess_idx in range(var_offset, var_offset + phase_dof[phase_idx]):
              __Pyx_TraceLine(83,1,__PYX_ERR(0, 83, __pyx_L42_error))
              __pyx_t_42 = __pyx_v_phase_idx;
              __pyx_t_43 = (__pyx_v_var_offset + (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int_t *, __pyx_pybuffernd_phase_dof.rcbuffer->pybuffer.buf, __pyx_t_42, __pyx_pybuffernd_phase_dof.diminfo[0].strides)));
              for (__pyx_t_44 = __pyx_v_var_offset; __pyx_t_44 < __pyx_t_43; __pyx_t_44+=1) {
                __pyx_v_hess_idx = __pyx_t_44;
+84:                         constraint_hess[constraint_offset, grad_idx, hess_idx] = phase_frac * comp_hess_value[grad_idx - var_offset, hess_idx - var_offset]
                __Pyx_TraceLine(84,1,__PYX_ERR(0, 84, __pyx_L42_error))
                __pyx_t_45 = (__pyx_v_grad_idx - __pyx_v_var_offset);
                __pyx_t_46 = (__pyx_v_hess_idx - __pyx_v_var_offset);
                __pyx_t_47 = __pyx_v_constraint_offset;
                __pyx_t_48 = __pyx_v_grad_idx;
                __pyx_t_49 = __pyx_v_hess_idx;
                *__Pyx_BufPtrStrided3d(__pyx_t_5numpy_float64_t *, __pyx_pybuffernd_constraint_hess.rcbuffer->pybuffer.buf, __pyx_t_47, __pyx_pybuffernd_constraint_hess.diminfo[0].strides, __pyx_t_48, __pyx_pybuffernd_constraint_hess.diminfo[1].strides, __pyx_t_49, __pyx_pybuffernd_constraint_hess.diminfo[2].strides) = (__pyx_v_phase_frac * (*((double *) ( /* dim=1 */ (( /* dim=0 */ ((char *) (((double *) __pyx_v_comp_hess_value.data) + __pyx_t_45)) ) + __pyx_t_46 * __pyx_v_comp_hess_value.strides[1]) ))));
              }
            }
+85:                 l_constraints[constraint_offset] += phase_frac * comp_obj_value[0]
            __Pyx_TraceLine(85,1,__PYX_ERR(0, 85, __pyx_L42_error))
            __pyx_t_50 = 0;
            __pyx_t_51 = __pyx_v_constraint_offset;
            *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_pybuffernd_l_constraints.rcbuffer->pybuffer.buf, __pyx_t_51, __pyx_pybuffernd_l_constraints.diminfo[0].strides) += (__pyx_v_phase_frac * (*((double *) ( /* dim=0 */ ((char *) (((double *) __pyx_v_comp_obj_value.data) + __pyx_t_50)) ))));
+86:                 constraint_jac[constraint_offset, spidx] += comp_obj_value[0]
            __Pyx_TraceLine(86,1,__PYX_ERR(0, 86, __pyx_L42_error))
            __pyx_t_52 = 0;
            __pyx_t_53 = __pyx_v_constraint_offset;
            __pyx_t_54 = __pyx_v_spidx;
            *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_pybuffernd_constraint_jac.rcbuffer->pybuffer.buf, __pyx_t_53, __pyx_pybuffernd_constraint_jac.diminfo[0].strides, __pyx_t_54, __pyx_pybuffernd_constraint_jac.diminfo[1].strides) += (*((double *) ( /* dim=0 */ ((char *) (((double *) __pyx_v_comp_obj_value.data) + __pyx_t_52)) )));
+87:                 var_offset += phase_dof[phase_idx]
            __Pyx_TraceLine(87,1,__PYX_ERR(0, 87, __pyx_L42_error))
            __pyx_t_55 = __pyx_v_phase_idx;
            __pyx_v_var_offset = (__pyx_v_var_offset + (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int_t *, __pyx_pybuffernd_phase_dof.rcbuffer->pybuffer.buf, __pyx_t_55, __pyx_pybuffernd_phase_dof.diminfo[0].strides)));
          }
+88:         if comp != dependent_comp:
    __Pyx_TraceLine(88,0,__PYX_ERR(0, 88, __pyx_L1_error))
    __pyx_t_2 = PyObject_RichCompare(__pyx_v_comp, __pyx_v_dependent_comp, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 88, __pyx_L1_error)
    __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 88, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (__pyx_t_10) {
/* … */
      goto __pyx_L48;
    }
+89:             l_constraints[constraint_offset] -= float(cur_conds['X_' + comp])
      __Pyx_TraceLine(89,0,__PYX_ERR(0, 89, __pyx_L1_error))
      __pyx_t_2 = PyNumber_Add(__pyx_n_u_X, __pyx_v_comp); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 89, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_6 = PyObject_GetItem(__pyx_v_cur_conds, __pyx_t_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 89, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_11 = __Pyx_PyObject_AsDouble(__pyx_t_6); if (unlikely(__pyx_t_11 == ((double)-1) && PyErr_Occurred())) __PYX_ERR(0, 89, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_56 = __pyx_v_constraint_offset;
      *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_pybuffernd_l_constraints.rcbuffer->pybuffer.buf, __pyx_t_56, __pyx_pybuffernd_l_constraints.diminfo[0].strides) -= __pyx_t_11;
 90:         else:
 91:             # TODO: Assuming N=1 (fixed for dependent component)
+92:             l_constraints[constraint_offset] -= (1 - indep_sum)
    __Pyx_TraceLine(92,0,__PYX_ERR(0, 92, __pyx_L1_error))
    /*else*/ {
      __pyx_t_57 = __pyx_v_constraint_offset;
      *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_pybuffernd_l_constraints.rcbuffer->pybuffer.buf, __pyx_t_57, __pyx_pybuffernd_l_constraints.diminfo[0].strides) -= (1.0 - __pyx_v_indep_sum);
    }
    __pyx_L48:;
+93:         constraint_offset += 1
    __Pyx_TraceLine(93,0,__PYX_ERR(0, 93, __pyx_L1_error))
    __pyx_v_constraint_offset = (__pyx_v_constraint_offset + 1);
+94:     return l_constraints, constraint_jac, constraint_hess
  __Pyx_TraceLine(94,0,__PYX_ERR(0, 94, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 94, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(((PyObject *)__pyx_v_l_constraints));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_l_constraints));
  PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_l_constraints));
  __Pyx_INCREF(((PyObject *)__pyx_v_constraint_jac));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_constraint_jac));
  PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_v_constraint_jac));
  __Pyx_INCREF(((PyObject *)__pyx_v_constraint_hess));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_constraint_hess));
  PyTuple_SET_ITEM(__pyx_t_1, 2, ((PyObject *)__pyx_v_constraint_hess));
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

In [30]:
%load_ext line_profiler
%lprun -f _compute_constraints equilibrium(dbf, ['AL', 'FE', 'VA'], ['B2_BCC', 'AL13FE4'], {v.T: 700, v.X('AL'): (0,1,0.02), v.P: 101325}, model=models, compute_constraints=_compute_constraints)


The line_profiler extension is already loaded. To reload it, use:
  %reload_ext line_profiler

In [ ]: