Skip to content

Commit 6462d05

Browse files
committed
Hybrid Setup
1 parent 75440b4 commit 6462d05

1 file changed

Lines changed: 7 additions & 9 deletions

File tree

mitsubishi/phase_3/code/euv_spectra.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@
4747
# %config InlineBackend.figure_format = 'retina'
4848

4949
import os
50-
os.environ["PYTORCH_CUDA_ALLOC_CONF"] = "expandable_segments:True"
50+
# Allow PyTorch MKL and PennyLane GCC OpenMP runtimes to coexist in the same process
51+
os.environ["KMP_DUPLICATE_LIBOK"] = "TRUE"
52+
# Cap OpenMP threads to prevent CPU thread-pool mutex thrashing
53+
os.environ["OMP_NUM_THREADS"] = "8"
54+
os.environ["MKL_NUM_THREADS"] = "8"
5155
import sys
5256
import pickle
5357
import matplotlib.pyplot as plt
@@ -1215,9 +1219,9 @@ def get_subsequence_energies(op_seq):
12151219
# Verify with a tiny sequence
12161220
# print(get_subsequence_energies([[op_pool[0], op_pool[1]]]))
12171221

1218-
# dev_eval = qml.device("lightning.qubit", wires=num_qubits)
1222+
dev_eval = qml.device("lightning.qubit", wires=num_qubits)
12191223

1220-
@qml.qnode(dev)
1224+
@qml.qnode(dev_eval)
12211225
def final_energy_circuit(gqe_ops):
12221226
"""Executes a sequence of GQE operators and measures final ground state energy directly on CPU (single pass, no GPU VRAM lock)."""
12231227
qml.BasisState(init_state, wires=range(num_qubits))
@@ -1670,16 +1674,10 @@ def generate(self, n_sequences, max_new_tokens, energies, temperature=1.0, devic
16701674
gen_token_seq, pred_Es = gpt.generate(**gen_kwargs)
16711675
pred_Es = pred_Es.cpu().numpy()
16721676

1673-
if device == "cuda":
1674-
torch.cuda.synchronize()
1675-
16761677
gen_inds = (gen_token_seq[:, 1:] - 1).cpu().numpy()
16771678
gen_op_seq = op_pool[gen_inds]
16781679
true_Es = get_final_energies(gen_op_seq)
16791680

1680-
if device == "cuda":
1681-
torch.cuda.synchronize()
1682-
16831681
mae = np.mean(np.abs(pred_Es - true_Es))
16841682
ave_E = np.mean(true_Es)
16851683

0 commit comments

Comments
 (0)