# User define functions from Python and nonlinear constraint JuMP

**URL:** <https://discourse.julialang.org/t/user-define-functions-from-python-and-nonlinear-constraint-jump/5063>\
**Category:** Optimization (Mathematical)\
**Created:** [July 25, 2017, 6:49pm UTC](https://discourse.julialang.org/t/user-define-functions-from-python-and-nonlinear-constraint-jump/5063 "2017-07-25T18:49:22Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![pipete40](https://avatars.discourse-cdn.com/v4/letter/p/8edcca/32.png) [@pipete40](https://discourse.julialang.org/u/pipete40)\
**Post date:** [July 25, 2017, 6:49pm UTC](https://discourse.julialang.org/t/user-define-functions-from-python-and-nonlinear-constraint-jump/5063/1 "2017-07-25T18:49:22Z")

</div>

Hi JuMP Community,

I am working on a problem with a linear objective and one nonlinear constraint. Let mvncdf(x1, x2, x3,…) be the multivariate normal distribution; then, the nonlinear constraint is given by mvncdf(x1, x2, x3, …)\>=0.5.

I did not find any implementations in Julia to calculate the cdf of the multivariate normal distribution, but I found one in Python.I try using PyCall to define a user defined function. In the case of 3 variables, the function in Julia looks like

function mvncdf3(z1, z2, z3, rho)  
using PyCall  
@pyimport scipy.stats.mvn as mvn  
@pyimport numpy as np  
low = np.ones(3) \* -10  
mu = np.zeros(3)  
p, i = mvn.mvnun(low, z, mu, rho)  
return p  
end

Then, I tried to register it to JuMP and use it in @NLconstraint

using JuMP, Ipopt  
m = Model(solver = IpoptSolver())  
@variable(m, z[1:3] \>=0)  
JuMP.register(m : mvncdf3, 4, mvncdf3, Dmvncdf3)  
@NLconstraint(m, mvncdf3(z[1],z[2],z[3],rho) \>= 0.5)

But, I get the following error: "PyError (:PyObject\_Call) \<type ‘exceptions.TypeError’\> TyperError(‘float() argument must be a string or a number’,) "

I guess is because z is a JuMP variable that cannot be handled to by PyCall. Is there a workaround this?

Thank you,
