55import os
66import sys
77import time
8+ import json
9+ import base64
10+ import dill # type: ignore
811from . import Axiomatic
912
1013
@@ -92,14 +95,6 @@ def ax_tool(self, tool, cell):
9295
9396 This cell won't run as Python code; instead, the text will be sent to the tool_schedule method
9497 of the Axiomatic client.
95-
96- Available Tools:
97- - fdtd
98- - femwell
99- - jaxfem
100- - optiland
101- - pyspice
102- - sax-gdsfactory
10398 """
10499 if not tool .strip ():
105100 print ("Please provider a tool name when calling this magic like: %%tool_schedule [optional_tool_name]" )
@@ -126,14 +121,33 @@ def ax_tool(self, tool, cell):
126121 else :
127122 if result .status == "SUCCEEDED" :
128123 os .environ ["TOOL_RESULT" ] = result .output
129- get_ipython ().user_ns ["tool_result" ] = result .output
130- print (result .output )
124+ output = json .loads (result .output )
125+ if not output ['objects' ]:
126+ get_ipython ().user_ns ["tool_result" ] = output
127+ else :
128+ get_ipython ().user_ns ["tool_result" ] = {
129+ "messages" : output ['messages' ],
130+ "objects" : self ._load_objects_from_base64 (output ['objects' ])
131+ }
132+ print ("SUCCEEDED: access the execution result with tool_result variable." )
131133 else :
132134 print (result .error_trace )
133135 break
134136 else :
135137 print (output .error_trace )
136138
139+ def _load_objects_from_base64 (self , encoded_dict ):
140+ loaded_objects = {}
141+ for key , encoded_str in encoded_dict .items ():
142+ try :
143+ decoded_bytes = base64 .b64decode (encoded_str )
144+ loaded_obj = dill .loads (decoded_bytes )
145+ loaded_objects [key ] = loaded_obj
146+ except Exception as e :
147+ print (f"Error loading object for key '{ key } ': { e } " )
148+ loaded_objects [key ] = None
149+ return loaded_objects
150+
137151
138152def ax_help (value : str ):
139153 print (
0 commit comments