Registry & Noise Models¶
registry ¶
NoiseSpec ¶
JAX PyTree wrapper around a NoiseModel configuration, so noise
parameters can be threaded through jax.jit/jax.grad/jax.vmap natively
-- e.g. as the noise= argument to circuit_to_energy_fn's energy_fn
-- instead of being applied as an external, Python-side step around
the already-traced circuit (the old way: build sv, exit the trace,
call apply_to_sv separately).
model/qubits are static (aux_data): they select which code path
runs, not values to differentiate or batch over -- the same role
static_argnames plays for a plain jax.jit function, but automatic
here because it's part of the pytree structure. p/jax_key are
pytree leaves (children): p can be a traced/differentiable value
(e.g. optimizing noise strength itself), and jax_key flows through
jit/vmap/scan the way any other JAX array does -- no external
Python-level key management, no OS-entropy fallback (unlike
apply_to_sv called standalone with jax_key=None), so a NoiseSpec's
result is always reproducible from the key it was built with.
jax_key is required (not Optional) -- the whole point of wiring
noise into the traced computation this way is to remove the need for
an external, ad-hoc key-management workaround; a caller who wants a
fresh key per call should split one themselves (jax.random.split)
and build a fresh NoiseSpec, the same as any other JAX-idiomatic
stateless-key pattern.
Source code in dense_evolution/registry.py
NoiseModel ¶
Stochastic single-qubit Kraus channels applied directly to a statevector.
All channels are mathematically correct Kraus maps: - trace is preserved (normalisation enforced at the end) - phaseflip applies Z with probability p per qubit (non-deterministic) - amplitude_damping applies the correct K0/K1 Kraus operators - combined is a true worst-case NISQ mixture of all three Pauli errors plus amplitude damping
Supported models¶
'ideal' identity — no modification 'depolarizing' {√(1-p)I, √(p/3)X, √(p/3)Y, √(p/3)Z} 'bitflip' {√(1-p)I, √p·X} 'phaseflip' {√(1-p)I, √p·Z} ← was broken, now fixed 'amplitude_damping'{K0=diag(1,√(1-γ)), K1=[[0,√γ],[0,0]]} 'combined' depolarizing(p/2) + amplitude_damping(p/3), renormalised
apply_to_sv
staticmethod
¶
apply_to_sv(
sv: ndarray,
n: int,
model: str,
p: float,
rng: Optional[Generator] = None,
qubits: Optional[List[int]] = None,
jax_key: Optional[Any] = None,
) -> np.ndarray
Apply a stochastic Kraus channel to statevector sv in-place (numpy path) or via functional updates (JAX path).
Parameters¶
sv : complex statevector of length 2n
n : number of qubits
model : one of NoiseModel.MODELS
p : error probability (or damping rate γ for amplitude_damping)
rng : optional pre-seeded numpy Generator. Used directly when
sv is a NumPy array. When sv is a JAX array, rng
used to be silently ignored in favor of jax_key (or a
non-reproducible OS-entropy key if that was also None
-- issue #7); it is now used to derive a reproducible
jax_key (rng.integers(...) seeds jax.random.PRNGKey)
whenever jax_key isn't given explicitly, so seeding
rng has the effect a caller expects on both array
types instead of only on one of them.
qubits : subset of qubits to apply the channel to; defaults to all
jax_key : optional JAX PRNGKey, only meaningful when sv is a JAX
array. Takes precedence over rng when both are given
(explicit key beats a derived one). Created from OS
entropy if neither jax_key nor rng is given.
Returns¶
Normalised statevector (same array type as input).
Source code in dense_evolution/registry.py
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 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 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 | |