added logging for gradio demo loading and molecule geometry creation
Browse files- app.py +15 -4
- history.md +3 -0
- quantum_utils.py +11 -0
app.py
CHANGED
@@ -209,12 +209,22 @@ def create_interface():
|
|
209 |
|
210 |
def set_client_for_session(request: gr.Request):
|
211 |
"""Initialize client with user's IP token to handle rate limiting."""
|
|
|
212 |
try:
|
213 |
-
|
214 |
-
|
|
|
|
|
215 |
except Exception as e:
|
216 |
-
logger.error(f"Error setting client: {e}")
|
217 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
218 |
|
219 |
# Load available molecules
|
220 |
molecules = load_molecules()
|
@@ -505,6 +515,7 @@ def create_interface():
|
|
505 |
)
|
506 |
|
507 |
# Add load event to set client
|
|
|
508 |
demo.load(set_client_for_session, None, client)
|
509 |
|
510 |
return demo
|
|
|
209 |
|
210 |
def set_client_for_session(request: gr.Request):
|
211 |
"""Initialize client with user's IP token to handle rate limiting."""
|
212 |
+
logger.info(f"Setting client for session with request: {request}")
|
213 |
try:
|
214 |
+
# Try to initialize client with HF token from environment variable
|
215 |
+
client = Client("A19grey/Cuda-Quantum-Molecular-Playground", hf_token=os.getenv("HF_TOKEN"))
|
216 |
+
logger.info(f"Client initialized with A19grey HF token")
|
217 |
+
return client
|
218 |
except Exception as e:
|
219 |
+
logger.error(f"Error setting client with HF token: {e}")
|
220 |
+
try:
|
221 |
+
# Fallback to using x-ip-token from request headers
|
222 |
+
x_ip_token = request.headers['x-ip-token']
|
223 |
+
logger.info(f"Client initialized with x-ip-token from request headers")
|
224 |
+
return Client("A19grey/Cuda-Quantum-Molecular-Playground", headers={"x-ip-token": x_ip_token})
|
225 |
+
except Exception as e:
|
226 |
+
logger.error(f"Error setting client with x-ip-token: {e}")
|
227 |
+
return None
|
228 |
|
229 |
# Load available molecules
|
230 |
molecules = load_molecules()
|
|
|
515 |
)
|
516 |
|
517 |
# Add load event to set client
|
518 |
+
logger.info("Adding load event to set client")
|
519 |
demo.load(set_client_for_session, None, client)
|
520 |
|
521 |
return demo
|
history.md
CHANGED
@@ -247,3 +247,6 @@ Steps tried so far:
|
|
247 |
* Fixed potential issues with implicit hydrogens
|
248 |
|
249 |
## 2023-10-14: Removed the 'Optimization Status' line from VQE optimization results in app.py. The output now only shows Final Energy, Parameter Count, Hamiltonian Terms, Iterations, and Scale Factor, along with any message output, making it clear if the simulation succeeded or failed without confusion.
|
|
|
|
|
|
|
|
247 |
* Fixed potential issues with implicit hydrogens
|
248 |
|
249 |
## 2023-10-14: Removed the 'Optimization Status' line from VQE optimization results in app.py. The output now only shows Final Energy, Parameter Count, Hamiltonian Terms, Iterations, and Scale Factor, along with any message output, making it clear if the simulation succeeded or failed without confusion.
|
250 |
+
|
251 |
+
## 2023-10-07: Added detailed debug logging to expand_geometry in quantum_utils.py.
|
252 |
+
- Added logging.debug statements to trace the input geometry, computed coordinates, center of mass, vector from center for each atom, and the final scaled coordinates output.
|
quantum_utils.py
CHANGED
@@ -207,20 +207,31 @@ def expand_geometry(geometry_template: List[List[Any]], scale_factor: float) ->
|
|
207 |
List of (atom_symbol, (x, y, z)) tuples with scaled coordinates
|
208 |
"""
|
209 |
scaled_geometry = []
|
|
|
|
|
|
|
210 |
# Find the center of mass (assuming equal weights for simplicity)
|
211 |
coords = np.array([coord for _, coord in geometry_template])
|
|
|
212 |
center = np.mean(coords, axis=0)
|
|
|
213 |
|
214 |
for atom_symbol, coord in geometry_template:
|
215 |
# Convert coord to numpy array for vector operations
|
216 |
coord = np.array(coord)
|
|
|
|
|
217 |
# Calculate vector from center
|
218 |
vec = coord - center
|
|
|
|
|
219 |
# Scale the vector and add back to center
|
220 |
scaled_coord = center + vec * scale_factor
|
|
|
221 |
# Convert back to tuple
|
222 |
scaled_geometry.append((atom_symbol, tuple(scaled_coord)))
|
223 |
|
|
|
224 |
return scaled_geometry
|
225 |
|
226 |
|
|
|
207 |
List of (atom_symbol, (x, y, z)) tuples with scaled coordinates
|
208 |
"""
|
209 |
scaled_geometry = []
|
210 |
+
logging.debug("expand_geometry: Starting with scale_factor=%f", scale_factor)
|
211 |
+
logging.debug("expand_geometry: Input geometry_template=%s", geometry_template)
|
212 |
+
|
213 |
# Find the center of mass (assuming equal weights for simplicity)
|
214 |
coords = np.array([coord for _, coord in geometry_template])
|
215 |
+
logging.debug("expand_geometry: Computed coordinates array: %s", coords)
|
216 |
center = np.mean(coords, axis=0)
|
217 |
+
logging.debug("expand_geometry: Computed center of mass: %s", center)
|
218 |
|
219 |
for atom_symbol, coord in geometry_template:
|
220 |
# Convert coord to numpy array for vector operations
|
221 |
coord = np.array(coord)
|
222 |
+
logging.debug("expand_geometry: Processing atom: %s", atom_symbol)
|
223 |
+
logging.debug("expand_geometry: Original coordinate: %s", coord)
|
224 |
# Calculate vector from center
|
225 |
vec = coord - center
|
226 |
+
logging.debug("expand_geometry: Computed vector from center: %s", vec)
|
227 |
+
|
228 |
# Scale the vector and add back to center
|
229 |
scaled_coord = center + vec * scale_factor
|
230 |
+
logging.debug("expand_geometry: Scaled coordinate: %s", scaled_coord)
|
231 |
# Convert back to tuple
|
232 |
scaled_geometry.append((atom_symbol, tuple(scaled_coord)))
|
233 |
|
234 |
+
logging.debug("expand_geometry: Final scaled geometry: %s", scaled_geometry)
|
235 |
return scaled_geometry
|
236 |
|
237 |
|