@junpenglao I apologize for late reply, and appreciate your help. Please let me explain more:
It is how I define my external model:
#%% defining model
@th.compile.ops.as_op(itypes=[t.dscalar],otypes=[t.dscalar,t.dscalar])
def dismodel(E):
f = open("input.xxx", "w")#input for my external program
f.write("set ee "+str(E)+";\n")
f.close()
call("MyexternalProgram final.xxx")#run my external program via python
return np.loadtxt("enddisp.out"),np.loadtxt("ddmdisp.out")
#First output is the value for parameter E, and the second output is its gradient wtr E.
Now I do not know how to let NUTS that it is the gradient it should use in its algorithm. I can run the same model using Metropolis without gradient with no problem.