shadow_hamiltonian
¶
Shadow Hamiltonian construction and closure.
ShadowHamiltonian
¶
Store the input model H and the reduced shadow matrix H_S.
There are two objects:
self.H: the input model on the full qubit space. On the sparse Pauli path this is a PauliSum-backedHamiltonian(no2^nmatrix until.matrixis accessed). On the dense fallback it is the summed(2^n, 2^n)matrix.self.H_S(also.shadow/get_H_S()): the actual shadow object—commutator matrix in the closed Pauli label basis only, shape(m, m)withm = |closure|. That size does not have to equal2^n; it is whatever the closure step produces.
When H and every observable already expose a pauli_sum, construction
stays in label/coeff space (no 4^n tomography, no full-space matrix
multiplies). Otherwise the dense path densifies once, expands via traces,
then shares the same structure-constant assembly for H_S.
Source code in shadowsim/shadow/shadow_hamiltonian.py
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 | |
shadow
property
¶
The shadow Hamiltonian: (m, m) with m = |closure|; not (2^n, 2^n) in general.
__init__
¶
__init__(
operator_set: OperatorSet,
H: Hamiltonian | Sequence[Hamiltonian],
*,
num_qubits: int | None = None,
tol: float = 1e-10,
verbose: bool = False,
) -> None
Build a shadow Hamiltonian from an operator set and Hamiltonian terms.
H may be a single Hamiltonian or a non-empty sequence of terms.
If every term and every observable is Pauli-backed, terms are merged as
PauliSums without densifying. Otherwise terms are summed on the full
num_qubits-qubit space via combined_hamiltonian_matrix.
num_qubits is inferred when possible (required if every term is a
LocalHamiltonian). After closure, self.H_S is the reduced matrix.
Set verbose=True to print Pauli-set and closure progress.
Source code in shadowsim/shadow/shadow_hamiltonian.py
get_H_S
¶
Return the shadow Hamiltonian in the closed Pauli basis.
Same as shadow. Shape (m, m) with m = len(self.basis),
independent of 2^n (unless m happens to match by coincidence).
Source code in shadowsim/shadow/shadow_hamiltonian.py
is_unitary
¶
is_hermitian
¶
__str__
¶
Return a string representation of the ShadowHamiltonian.
Source code in shadowsim/shadow/shadow_hamiltonian.py
__repr__
¶
Return a string representation of the ShadowHamiltonian.