Skip to content

Commit 54a67fa

Browse files
update llm guides
1 parent 535da56 commit 54a67fa

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

llm.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ pylint tensorcircuit/quantum.py
137137

138138
## Further Reading
139139

140-
- **Specific Protocols**: See `experience.md` for detailed protocols on development, profiling, and performance tuning.
140+
- **Specific Protocols**: See `llm_experience.md` for detailed protocols on development, profiling, and performance tuning.
141141

142142
- **Official Docs**: https://tensorcircuit-ng.readthedocs.io/
143143

llm_experience.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,23 @@ This document records specific technical protocols, lessons learned, and advance
1212
* For operations over large batches (e.g., summing $2^{22}$ Pauli strings), `vmap` materializes all intermediate results in memory.
1313
* **Protocol**: Use `jax.lax.scan` or sequential loops for reductions over large inputs to keep peak memory usage constant ($O(1)$) rather than linear ($O(N)$).
1414

15+
3. **Vmap Broadcasting with Optimizers (Optax/Custom)**:
16+
* **Pitfall**: `tc.backend.vmap(func)` implicitly sets `vectorized_argnums=0`. If `func` takes multiple arguments that are *all* batched (e.g. `update_step(params, opt_state)`), you MUST specify `vectorized_argnums=(0, 1)`.
17+
* **Symptom**: Dimension mismatch errors (e.g. `broadcast_shapes got incompatible shapes`) where one argument is treated as a scalar/unbatched while the other is batched.
18+
* **Protocol**: Explicitly define `vectorized_argnums` when vmapping functions with optimizer states or multiple batched inputs.
19+
20+
## Qudit Simulation & Advanced Models
21+
22+
1. **Ansatz Expressibility**:
23+
* For $d > 2$ (Qudits), simple "Hardware Efficient" ansätze (single layer of rotations) are often insufficient to reach ground states of complex Hamiltonians (e.g. Potts model).
24+
* **Protocol**: Ensure high expressibility by parameterizing *all* $d$ diagonal phases (`rz` on levels $0 \dots d-1$) and *all* off-diagonal mixing angles (`ry` on pairs $(j, k)$).
25+
* **Dimension Agnostic Code**: Write code using variables `d` and loops `range(d)` instead of hardcoding `d=3`. This allows the same script to simulate qutrits, ququarts, etc. seamlessly.
26+
27+
2. **Sparse Matrix Hamiltonian**:
28+
* For larger Hilbert spaces ($d^N \gg 10^3$), dense matrix construction explodes in memory.
29+
* **Protocol**: Construct Hamiltonians using `scipy.sparse` (COO format), but first prefer to use `PauliStringSum2COO` if available.
30+
* **Integration**: Convert to JAX Sparse via `tc.backend.coo_sparse_matrix(indices, values, shape)` and use `tc.backend.sparse_dense_matmul(H_sparse, ket)` for expectation values. This provides massive speedups and enables simulation of larger $N$ or $d$.
31+
1532
## Testing and Robustness
1633

1734
1. **Sparse Matrix Compatibility**:

0 commit comments

Comments
 (0)