Skip to content

Commit b9623ca

Browse files
committed
debug losg
1 parent 5306ef6 commit b9623ca

2 files changed

Lines changed: 35 additions & 37 deletions

File tree

curationTool/reactions/utils/MatlabHTTPClient.py

Lines changed: 30 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ def __init__(self):
3737
self.base_url = f"http://{self.matlab_host}:{self.matlab_port}"
3838
self.timeout = 300 # 5 minutes timeout for MATLAB operations
3939

40+
print(f"[INFO MatlabHTTPClient] Initializing with host={self.matlab_host}, port={self.matlab_port}", flush=True)
41+
print(f"[INFO MatlabHTTPClient] Base URL: {self.base_url}", flush=True)
4042
logger.info(f"MATLAB HTTP Client initialized: {self.base_url}")
4143
self._initialized = True
4244

@@ -57,62 +59,53 @@ def health_check(self) -> bool:
5759
logger.error(f"MATLAB health check failed: {e}")
5860
return False
5961

60-
def execute(
61-
self,
62-
function: str,
63-
*args,
64-
nargout: int = 1,
65-
**kwargs
66-
) -> Dict[str, Any]:
62+
def execute(self, function_name: str, *args, **kwargs) -> Dict[str, Any]:
6763
"""
68-
Execute a MATLAB function.
64+
Execute a MATLAB function with arguments.
6965
7066
Args:
71-
function: Name of the MATLAB function to execute
72-
*args: Positional arguments to pass to the function
73-
nargout: Number of output arguments (default 1)
74-
**kwargs: Keyword arguments to pass to the function
67+
function_name: Name of the MATLAB function to execute
68+
*args: Positional arguments for the function
69+
**kwargs: Keyword arguments for the function
7570
7671
Returns:
77-
Dictionary with 'status' and either 'result' or 'message':
78-
- {'status': 'success', 'result': <return_value>}
79-
- {'status': 'error', 'message': <error_message>}
72+
Dict with 'status' ('success' or 'error'), 'result', and optional 'message'
8073
"""
74+
print(f"[DEBUG MatlabHTTPClient] Executing MATLAB function: {function_name}", flush=True)
75+
print(f"[DEBUG MatlabHTTPClient] Args: {args}, Kwargs: {kwargs}", flush=True)
76+
print(f"[DEBUG MatlabHTTPClient] Sending request to: {self.base_url}/execute", flush=True)
77+
8178
try:
82-
payload = {
83-
'function': function,
84-
'args': list(args),
85-
'kwargs': kwargs,
86-
'nargout': nargout
87-
}
88-
89-
logger.debug(f"Executing MATLAB function: {function}")
90-
9179
response = requests.post(
9280
f"{self.base_url}/execute",
93-
json=payload,
81+
json={
82+
'function': function_name,
83+
'args': list(args),
84+
'kwargs': kwargs
85+
},
9486
timeout=self.timeout
9587
)
88+
print(f"[DEBUG MatlabHTTPClient] Response status: {response.status_code}", flush=True)
89+
print(f"[DEBUG MatlabHTTPClient] Response body: {response.text[:200]}", flush=True)
9690

91+
response.raise_for_status()
9792
result = response.json()
93+
print(f"[DEBUG MatlabHTTPClient] Result: {result}", flush=True)
94+
return result
9895

99-
if response.status_code == 200:
100-
logger.debug(f"Function executed successfully: {function}")
101-
return result
102-
else:
103-
logger.error(f"Function execution failed: {result.get('message', 'Unknown error')}")
104-
return result
105-
106-
except requests.exceptions.Timeout:
107-
error_msg = f"MATLAB function {function} timed out after {self.timeout} seconds"
96+
except requests.exceptions.ConnectionError as e:
97+
error_msg = f"Cannot connect to MATLAB server at {self.base_url}: {e}"
98+
print(f"[ERROR MatlabHTTPClient] {error_msg}", flush=True)
10899
logger.error(error_msg)
109100
return {'status': 'error', 'message': error_msg}
110-
except requests.exceptions.ConnectionError as e:
111-
error_msg = f"Cannot connect to MATLAB server at {self.base_url}: {str(e)}"
101+
except requests.exceptions.Timeout as e:
102+
error_msg = f"Request to MATLAB server timed out after {self.timeout}s: {e}"
103+
print(f"[ERROR MatlabHTTPClient] {error_msg}", flush=True)
112104
logger.error(error_msg)
113105
return {'status': 'error', 'message': error_msg}
114106
except Exception as e:
115-
error_msg = f"Unexpected error executing {function}: {str(e)}"
107+
error_msg = f"Error executing MATLAB function '{function_name}': {e}"
108+
print(f"[ERROR MatlabHTTPClient] {error_msg}", flush=True)
116109
logger.error(error_msg)
117110
return {'status': 'error', 'message': error_msg}
118111

curationTool/reactions/utils/gen_vmh_abbrs.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,19 @@ def gen_metabolite_abbr(
6060
[metabolite], [mtype], None, side='substrates', nofile=True, return_abbr=True)
6161
found, abbr = found[0], abbr[0]
6262
if found:
63+
print(f"[DEBUG gen_vmh_abbrs] Metabolite '{metabolite_name}' found in VMH with abbr: {abbr}", flush=True)
6364
return abbr
6465
else:
66+
print(f"[DEBUG gen_vmh_abbrs] Metabolite '{metabolite_name}' NOT found in VMH, calling MATLAB...", flush=True)
6567
matlab_session = MatlabSessionManager()
68+
print(f"[DEBUG gen_vmh_abbrs] MatlabSessionManager created, calling generateVMHMetAbbr...", flush=True)
6669
result = matlab_session.execute('generateVMHMetAbbr', metabolite_name)
70+
print(f"[DEBUG gen_vmh_abbrs] MATLAB result: {result}", flush=True)
6771
abbr = result['result'] if result['status'] == 'success' else metabolite_name
6872
# abbr = abbr[-1] if isinstance(abbr, list) else abbr
6973
exists = check_met_abbr_exists(abbr)
7074
while exists:
7175
abbr = abbr + '_'
7276
exists = check_met_abbr_exists(abbr)
77+
print(f"[DEBUG gen_vmh_abbrs] Final abbreviation: {abbr}", flush=True)
7378
return abbr

0 commit comments

Comments
 (0)