Skip to content

Commit

Permalink
I think we can
Browse files Browse the repository at this point in the history
  • Loading branch information
mldiego committed Jul 11, 2024
1 parent 18a8c98 commit 508bb64
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 35 deletions.
23 changes: 2 additions & 21 deletions code/nnv/examples/Submission/VNN_COMP2024/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,9 @@ def prepare_instance(category: str, onnx: str, vnnlib: str) -> None:
onnx (str): the path to the .onnx file
vnnlib (str): the path to the .vnnlib file
"""
# start matlab engine as a shared engine
eng = matlab.engine.start_matlab(background=True, option='-r "matlab.engine.shareEngine"')
#matlab.engine.shareEngine('vnncomp', background=True)
print('Engine starting...')

# keep MATLAB engine open until manually killed
# while True:
# time.sleep(0.5)
# print("We should not be here...")
#print("This is the last line of the prepare instance")
print("We should not be here...")


def run_instance(category, onnx, vnnlib, timeout, outputlocation) -> None:
"""Run an instance based on parameters defined in .csv file.
Expand All @@ -43,26 +36,14 @@ def run_instance(category, onnx, vnnlib, timeout, outputlocation) -> None:
timeout (int): the time (in ms) to wait before proceeding to the next instance
"""

print("Begin run instance, try to connect to matlab engine")
# eng = matlab.engine.start_matlab()
print("Looking for connections")
matlab.engine.find_matlab()
eng = matlab.engine.connect_matlab()
#print(eng_name)
# eng = matlab.engine.connect_matlab(name=eng_name)
# eng = matlab.engine.connect_matlab('vnncomp')

print("Is it connected?")
# print(f'Successfully connected to engine: {eng_name}.')

eng.addpath(os.getcwd())
eng.addpath(eng.genpath('/home/ubuntu/toolkit/code/nnv/'))
# eng.addpath(eng.genpath('/root/Documents/MATLAB/SupportPackages/R2024a')) # This is where the support packages get installed from mpm

print("If connected, we added some paths")
status = 2 #initialize with an 'Unknown' status
#toc = time.perf_counter()
print("doing matlab.engine.runCode")
future = eng.run_vnncomp2024_instance(category, onnx, vnnlib, outputlocation, nargout = 2, background=True)

try:
Expand Down
17 changes: 3 additions & 14 deletions code/nnv/examples/Submission/VNN_COMP2024/prepare_instance.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,12 @@ echo "Preparing $TOOL_NAME for benchmark instance in category '$CATEGORY' with o
# kill any zombie processes
killall -q python3
# killall -q python
killall -q matlab
pkill -f matlab

# WAIT_FOR_CONNECTION_TO_CLOSE='import matlab.engine\nimport time\nwhile matlab.engine.find_matlab(): time.sleep(1)'
# python3 -c "exec('$WAIT_FOR_CONNECTION_TO_CLOSE')"
# python -c "exec('$WAIT_FOR_CONNECTION_TO_CLOSE')"
WAIT_FOR_CONNECTION_TO_OPEN='import matlab.engine\nimport time\nwhile not matlab.engine.find_matlab(): time.sleep(1)'

# start the matlab engine in background and keep the connection open
# python3 /home/ubuntu/toolkit/code/nnv/examples/Submission/VNN_COMP2024/execute.py 'prepare_instance' $CATEGORY $ONNX_FILE $VNNLIB_FILE &
# python execute.py 'prepare_instance' $CATEGORY $ONNX_FILE $VNNLIB_FILE &
matlab -batch "p = parpool; p.IdleTimeout = 120; matlab.engine.shareEngine;" &

# WAIT_FOR_CONNECTION_TO_OPEN='import matlab.engine\nimport time\nwhile not matlab.engine.find_matlab(): time.sleep(1) \nprint(eng)'
# python3 -c "exec('$WAIT_FOR_CONNECTION_TO_OPEN')"
# python -c "exec('$WAIT_FOR_CONNECTION_TO_OPEN')"

nohup matlab -nosplash -nodisplay -nodesktop -batch "p = parpool; p.IdleTimeout = 120; matlab.engine.shareEngine;" &

WAIT_FOR_CONNECTION_TO_OPEN='import matlab.engine\nimport time\nwhile not matlab.engine.find_matlab(): time.sleep(1) \nprint(eng)'
python3 -c "exec('$WAIT_FOR_CONNECTION_TO_OPEN')"

exit 0

0 comments on commit 508bb64

Please sign in to comment.