added time warning about simulation run time
Browse files- quantum_utils.py +7 -14
- visualization.py +4 -0
quantum_utils.py
CHANGED
@@ -90,7 +90,6 @@ def vqe_callback(xk):
|
|
90 |
logging.error(f"Error in VQE callback: {str(e)}")
|
91 |
return False
|
92 |
|
93 |
-
@spaces.GPU
|
94 |
def validate_ansatz(kernel_generator, init_params, qubit_num, electron_num):
|
95 |
"""Validate the ansatz kernel before VQE."""
|
96 |
try:
|
@@ -117,7 +116,6 @@ def validate_ansatz(kernel_generator, init_params, qubit_num, electron_num):
|
|
117 |
# ----------------------------------------------------------
|
118 |
# New or updated utility function for generating a Hamiltonian
|
119 |
# ----------------------------------------------------------
|
120 |
-
@spaces.GPU
|
121 |
def create_molecular_hamiltonian(geometry: list[tuple[str, tuple[float, float, float]]],
|
122 |
basis: str,
|
123 |
multiplicity: int,
|
@@ -165,7 +163,7 @@ def create_molecular_hamiltonian(geometry: list[tuple[str, tuple[float, float, f
|
|
165 |
# ----------------------------------------------------------
|
166 |
# New or updated function for generating a UCCSD ansatz kernel
|
167 |
# ----------------------------------------------------------
|
168 |
-
@cudaq.kernel
|
169 |
def kernel(qubit_num: int, electron_num: int, thetas: list[float]):
|
170 |
"""
|
171 |
Generate a UCCSD ansatz kernel given the number of qubits and electrons.
|
@@ -225,7 +223,7 @@ def expand_geometry(geometry_template: List[List[Any]], scale_factor: float) ->
|
|
225 |
|
226 |
return scaled_geometry
|
227 |
|
228 |
-
|
229 |
def generate_hamiltonian(molecule_data: Dict[str, Any],
|
230 |
scale_factor: float) -> Dict[str, Any]:
|
231 |
"""
|
@@ -253,8 +251,6 @@ def generate_hamiltonian(molecule_data: Dict[str, Any],
|
|
253 |
gpu_time = molecule_data.get('GPU_time', 60)
|
254 |
logger.info(f"Generating Hamiltonian with GPU time: {gpu_time}")
|
255 |
|
256 |
-
# Decorate the function with the correct GPU time
|
257 |
-
# @spaces.GPU(duration=gpu_time)
|
258 |
def _generate_hamiltonian_inner():
|
259 |
logging.info(f"Generating Hamiltonian for {molecule_data['name']} with scale factor {scale_factor}")
|
260 |
|
@@ -316,7 +312,6 @@ def generate_hamiltonian(molecule_data: Dict[str, Any],
|
|
316 |
|
317 |
return _generate_hamiltonian_inner()
|
318 |
|
319 |
-
@spaces.GPU
|
320 |
def run_vqe_simulation(molecule_data: Dict[str, Any],
|
321 |
scale_factor: float,
|
322 |
hamiltonian_only: bool = False) -> Dict[str, Any]:
|
@@ -337,16 +332,14 @@ def run_vqe_simulation(molecule_data: Dict[str, Any],
|
|
337 |
Dict[str, Any]
|
338 |
The dictionary containing either just Hamiltonian info or full VQE results
|
339 |
"""
|
340 |
-
# Get GPU time
|
341 |
-
logger.info(f"Running VQE simulation with GPU time")
|
342 |
gpu_time = molecule_data.get('GPU_time', 60)
|
343 |
-
logger.info(f"GPU time: {gpu_time}")
|
344 |
-
# Decorate the function with the correct GPU time
|
345 |
-
logger.info(f"Adding GPU time decorator: {gpu_time}")
|
346 |
-
|
347 |
-
setup_target()
|
348 |
|
|
|
349 |
def _run_vqe_simulation_inner():
|
|
|
|
|
350 |
# Generate Hamiltonian and get system parameters
|
351 |
logger.info("Generating Hamiltonian")
|
352 |
ham_info = generate_hamiltonian(molecule_data, scale_factor)
|
|
|
90 |
logging.error(f"Error in VQE callback: {str(e)}")
|
91 |
return False
|
92 |
|
|
|
93 |
def validate_ansatz(kernel_generator, init_params, qubit_num, electron_num):
|
94 |
"""Validate the ansatz kernel before VQE."""
|
95 |
try:
|
|
|
116 |
# ----------------------------------------------------------
|
117 |
# New or updated utility function for generating a Hamiltonian
|
118 |
# ----------------------------------------------------------
|
|
|
119 |
def create_molecular_hamiltonian(geometry: list[tuple[str, tuple[float, float, float]]],
|
120 |
basis: str,
|
121 |
multiplicity: int,
|
|
|
163 |
# ----------------------------------------------------------
|
164 |
# New or updated function for generating a UCCSD ansatz kernel
|
165 |
# ----------------------------------------------------------
|
166 |
+
@cudaq.kernel #required to create the kernel object for Nvidia
|
167 |
def kernel(qubit_num: int, electron_num: int, thetas: list[float]):
|
168 |
"""
|
169 |
Generate a UCCSD ansatz kernel given the number of qubits and electrons.
|
|
|
223 |
|
224 |
return scaled_geometry
|
225 |
|
226 |
+
|
227 |
def generate_hamiltonian(molecule_data: Dict[str, Any],
|
228 |
scale_factor: float) -> Dict[str, Any]:
|
229 |
"""
|
|
|
251 |
gpu_time = molecule_data.get('GPU_time', 60)
|
252 |
logger.info(f"Generating Hamiltonian with GPU time: {gpu_time}")
|
253 |
|
|
|
|
|
254 |
def _generate_hamiltonian_inner():
|
255 |
logging.info(f"Generating Hamiltonian for {molecule_data['name']} with scale factor {scale_factor}")
|
256 |
|
|
|
312 |
|
313 |
return _generate_hamiltonian_inner()
|
314 |
|
|
|
315 |
def run_vqe_simulation(molecule_data: Dict[str, Any],
|
316 |
scale_factor: float,
|
317 |
hamiltonian_only: bool = False) -> Dict[str, Any]:
|
|
|
332 |
Dict[str, Any]
|
333 |
The dictionary containing either just Hamiltonian info or full VQE results
|
334 |
"""
|
335 |
+
# Get GPU time from molecule data or use default
|
|
|
336 |
gpu_time = molecule_data.get('GPU_time', 60)
|
337 |
+
logger.info(f"Running VQE simulation with GPU time: {gpu_time}")
|
|
|
|
|
|
|
|
|
338 |
|
339 |
+
@spaces.GPU(duration=gpu_time)
|
340 |
def _run_vqe_simulation_inner():
|
341 |
+
setup_target()
|
342 |
+
|
343 |
# Generate Hamiltonian and get system parameters
|
344 |
logger.info("Generating Hamiltonian")
|
345 |
ham_info = generate_hamiltonian(molecule_data, scale_factor)
|
visualization.py
CHANGED
@@ -35,6 +35,9 @@ def format_molecule_params(molecule_data: dict) -> str:
|
|
35 |
HTML formatted string of parameters
|
36 |
"""
|
37 |
try:
|
|
|
|
|
|
|
38 |
# Create a formatted HTML string with molecule parameters
|
39 |
params_html = f"""
|
40 |
<div style='font-family: monospace; padding: 10px;'>
|
@@ -44,6 +47,7 @@ def format_molecule_params(molecule_data: dict) -> str:
|
|
44 |
<li><b>Electrons:</b> {molecule_data.get('electron_count', 'N/A')}</li>
|
45 |
<li><b>Basis:</b> {molecule_data.get('basis', 'N/A')}, <b>Spatial Orbitals:</b> {molecule_data.get('spatial_orbitals', 'N/A')}</li>
|
46 |
<li><b>Charge:</b> {molecule_data.get('charge', 'N/A')}</li>
|
|
|
47 |
</ul>
|
48 |
</div>
|
49 |
"""
|
|
|
35 |
HTML formatted string of parameters
|
36 |
"""
|
37 |
try:
|
38 |
+
# Get GPU time in minutes
|
39 |
+
gpu_minutes = molecule_data.get('GPU_time', 60) / 60
|
40 |
+
|
41 |
# Create a formatted HTML string with molecule parameters
|
42 |
params_html = f"""
|
43 |
<div style='font-family: monospace; padding: 10px;'>
|
|
|
47 |
<li><b>Electrons:</b> {molecule_data.get('electron_count', 'N/A')}</li>
|
48 |
<li><b>Basis:</b> {molecule_data.get('basis', 'N/A')}, <b>Spatial Orbitals:</b> {molecule_data.get('spatial_orbitals', 'N/A')}</li>
|
49 |
<li><b>Charge:</b> {molecule_data.get('charge', 'N/A')}</li>
|
50 |
+
<li><b>Simulation time: up to {gpu_minutes:.1f} minutes</b></li>
|
51 |
</ul>
|
52 |
</div>
|
53 |
"""
|