Spaces:
Running
on
Zero
Running
on
Zero
limited character output of circuit to not crash the app
Browse files- 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.
|
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"
|