@@ -10,18 +10,40 @@ def combined_hamiltonian_matrix(
1010 hamiltonians : list [Hamiltonian ],
1111 num_qubits : int ,
1212) -> np .ndarray :
13- """Sum Hamiltonian terms on the full ``num_qubits``-site tensor space.
13+ r """Sum Hamiltonian terms on the full ``num_qubits``-site tensor space.
1414
1515 ``LocalHamiltonian`` terms are embedded with identities on the remaining
1616 sites; full-domain ``Hamiltonian`` matrices are added as-is. All terms must
1717 match a common Hilbert-space dimension (``local_dim ** num_qubits`` for
1818 locals, or the matrix size of bare terms).
1919
20- Parameter hamiltonians: The list of Hamiltonians to sum.
21- Precondition: hamiltonians is a list of Hamiltonian objects.
20+ Args:
21+ hamiltonians: Non-empty list of ``Hamiltonian`` objects to sum.
22+ num_qubits: Positive number of sites in the full system.
23+
24+ Returns:
25+ Complex matrix of shape ``(d, d)`` equal to the sum of the (embedded)
26+ terms, where ``d`` is the shared Hilbert-space dimension.
27+
28+ Raises:
29+ ValueError: If ``LocalHamiltonian`` terms use mixed ``local_dim`` values,
30+ or if term dimensions disagree for the requested ``num_qubits``.
31+ AssertionError: If ``hamiltonians`` / ``num_qubits`` fail basic type and
32+ positivity checks.
33+
34+ Examples:
35+ Embed a single-site \(Z\) into a three-qubit chain and inspect the shape:
36+
37+ ```python exec="1" source="above" result="text"
38+ import numpy as np
39+ from shadowsim.core import LocalHamiltonian
40+ from shadowsim.core.combined_hamiltonian_matrix import combined_hamiltonian_matrix
41+
42+ local = LocalHamiltonian(np.diag([1.0, -1.0]), sites=[1], local_dim=2)
43+ out = combined_hamiltonian_matrix([local], num_qubits=3)
44+ print(out.shape)
45+ ```
2246
23- Parameter num_qubits: The number of qubits in the full system.
24- Precondition: num_qubits is a positive integer.
2547 """
2648 assert isinstance (hamiltonians , list ), "hamiltonians must be a list"
2749 assert all (isinstance (h , Hamiltonian ) for h in hamiltonians ), "all hamiltonians must be Hamiltonian objects"
0 commit comments