A19grey commited on
Commit
7189b3c
·
1 Parent(s): bd11228

limited character output of circuit to not crash the app

Browse files
Files changed (1) hide show
  1. quantum_utils.py +7 -1
quantum_utils.py CHANGED
@@ -278,8 +278,14 @@ def generate_hamiltonian(molecule_data: Dict[str, Any],
278
  thetas_draw = np.random.normal(0, 1, parameter_count)
279
  # Draw the circuit in fancy nice stuff
280
  circuit_latex = cudaq.draw(kernel, qubit_count, electron_count, thetas_draw)
 
 
 
 
 
 
281
  logging.info("Successfully generated circuit LaTeX representation")
282
- logging.info(circuit_latex)
283
  except Exception as e:
284
  logging.error(f"Failed to generate circuit LaTeX: {str(e)}")
285
  circuit_latex = "Error generating circuit visualization"
 
278
  thetas_draw = np.random.normal(0, 1, parameter_count)
279
  # Draw the circuit in fancy nice stuff
280
  circuit_latex = cudaq.draw(kernel, qubit_count, electron_count, thetas_draw)
281
+
282
+ # Limit circuit output size
283
+ MAX_CIRCUIT_LENGTH = 15000
284
+ if len(circuit_latex) > MAX_CIRCUIT_LENGTH:
285
+ circuit_latex = circuit_latex[:MAX_CIRCUIT_LENGTH] + "\n... (circuit visualization clipped for size)"
286
+
287
  logging.info("Successfully generated circuit LaTeX representation")
288
+ logging.debug(f"Circuit LaTeX length: {len(circuit_latex)} characters")
289
  except Exception as e:
290
  logging.error(f"Failed to generate circuit LaTeX: {str(e)}")
291
  circuit_latex = "Error generating circuit visualization"