Odd results from MATLAB function called in python
So turns out, that on occasion the code will run if some variables aren't specified as double, and in other cases it integer division or what not, results false results. I have no idea how this correlates to the input as it really shouldn't but I just went and specified all variables in the relevant section of code to be doubles and that fixed it. So 
tl;dr: Even if it runs, just enforce all variables are doubles and the problem is solved. 
Really something Mathworks should fix in their python api
So I have a rather comlicated matlab function (it calls a simulation that in turn calls an external optimisation suite (cplex or gurobi)).  And for certain settings and inputs the MATLAB function and the python function called from Matlab give the same result but for others they differ (correct answer is ~4500) python sometimes returns 0.015... or 162381, so widely varying results I can't spot a pattern or correlation for. 
my guess would be either something with int/ float / double variable conversions, or some form of memory problem. The result comes straight from CPLEX so I'm  little confused as to why it changes. 
On a side note, if I return a structure that contains a structure of arrays, that kills the python kernel. That makes debugging from python a little harder (I have pymatbridge and metakernel installed)
Has anyone, had similar issues of unreliable matlab functions in python? Solution ideas other than, executing matlab from the console and reading in a results file?