Skip to content

Commit

Permalink
seems to work in Matlab now with subprocess
Browse files Browse the repository at this point in the history
  • Loading branch information
mccullerlp committed Jan 17, 2018
1 parent db0795e commit 202d7aa
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
7 changes: 5 additions & 2 deletions msurrogate/+msurrogate/py2mat.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@
end
arr = reshape(arr, shape);
varargout{1} = arr;

case 'py.str'
varargout{1} = char(object);
case 'py.unicode'
varargout{1} = char(object);
otherwise
if strcmp(cname(1:3), 'py.')
if strcmp(cname(1:9), 'py.Pyro4.') && strcmp(cname(end-4:end), 'Proxy')
if length(cname) >= 14 && strcmp(cname(1:9), 'py.Pyro4.') && strcmp(cname(end-4:end), 'Proxy')
%it may be a superproxy! so try it out
if py.hasattr(object, 'pyrosuper_getattr')
varargout{1} = pyrowrap(object, false);
Expand Down
2 changes: 2 additions & 0 deletions msurrogate/+msurrogate/tup2mat.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
switch ME.identifier
case 'MATLAB:cell2mat:MixedDataTypes'
varargout{1} = cellfun(@py2mat, ocells, 'UniformOutput', false);
case 'MATLAB:cell2mat:UnsupportedCellContent'
varargout{1} = cellfun(@py2mat, ocells, 'UniformOutput', false);
otherwise
ME.identifier
error(ME)
Expand Down
3 changes: 3 additions & 0 deletions msurrogate/subproc_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ def __init__(
if python_call is None:
python_call = sys.executable

if module_name is None:
raise RuntimeError("Must specify module_name")

self.proc = subprocess.Popen(
[python_call, '-m', module_name, '-S', '-', '-c', '-'] + args,
stdout = subprocess.PIPE,
Expand Down
26 changes: 26 additions & 0 deletions test/test.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
% Author : Lee McCuller
clear classes
addpath(char(py.msurrogate.matlabpath()));

call = msurrogate.pywrap(@py.msurrogate.subproc_server.ServerSubprocess);
proc = call('module_name', 'msurrogate.ping_test');

disp(proc.mysecret)
disp(proc.cookie_dict)

%import numpy_cast.*
%qb = py.iirrational.testing.iirrational_data('simple2');
%mqb = py2mat(qb);
%
%pyro_config = py2mat(py.Pyro4.config);
%pyro_config.SERIALIZER = 'dill';
%pyro_config.REQUIRE_EXPOSE = false;
%
%conftext = fileread('iirrational_pyro_con.json');
%conf = iirrational.json.jsondecode(conftext);
%
%factory = py2mat(py.Pyro4.Proxy(conf.v1));
%
%obj = factory.rationalize.async({mqb});
%disp(obj.fitter.xfer_fit)
%obj.pyrosuper_getattr({'fitter'}).pyrosuper_call({'optimize'})

0 comments on commit 202d7aa

Please sign in to comment.