|
47 | 47 | # %config InlineBackend.figure_format = 'retina' |
48 | 48 |
|
49 | 49 | 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" |
51 | 55 | import sys |
52 | 56 | import pickle |
53 | 57 | import matplotlib.pyplot as plt |
@@ -1215,9 +1219,9 @@ def get_subsequence_energies(op_seq): |
1215 | 1219 | # Verify with a tiny sequence |
1216 | 1220 | # print(get_subsequence_energies([[op_pool[0], op_pool[1]]])) |
1217 | 1221 |
|
1218 | | -# dev_eval = qml.device("lightning.qubit", wires=num_qubits) |
| 1222 | +dev_eval = qml.device("lightning.qubit", wires=num_qubits) |
1219 | 1223 |
|
1220 | | -@qml.qnode(dev) |
| 1224 | +@qml.qnode(dev_eval) |
1221 | 1225 | def final_energy_circuit(gqe_ops): |
1222 | 1226 | """Executes a sequence of GQE operators and measures final ground state energy directly on CPU (single pass, no GPU VRAM lock).""" |
1223 | 1227 | 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 |
1670 | 1674 | gen_token_seq, pred_Es = gpt.generate(**gen_kwargs) |
1671 | 1675 | pred_Es = pred_Es.cpu().numpy() |
1672 | 1676 |
|
1673 | | - if device == "cuda": |
1674 | | - torch.cuda.synchronize() |
1675 | | - |
1676 | 1677 | gen_inds = (gen_token_seq[:, 1:] - 1).cpu().numpy() |
1677 | 1678 | gen_op_seq = op_pool[gen_inds] |
1678 | 1679 | true_Es = get_final_energies(gen_op_seq) |
1679 | 1680 |
|
1680 | | - if device == "cuda": |
1681 | | - torch.cuda.synchronize() |
1682 | | - |
1683 | 1681 | mae = np.mean(np.abs(pred_Es - true_Es)) |
1684 | 1682 | ave_E = np.mean(true_Es) |
1685 | 1683 |
|
|
0 commit comments