Repository navigation
Commit 29c603d
Fix Pow/Pow2 eigvals branch cut on Python 3.14
Python 3.14 implements C99 mixed-mode real/complex arithmetic
(python/cpython#69639), so `complex * float` is now componentwise
instead of promoting the float to `complex(x, +0.0)`:
3.13: (1+0j) * -1.0 -> (-1+0j)
3.14: (1+0j) * -1.0 -> (-1-0j)
The negative zero imaginary part puts negative eigenvalues on the
wrong side of the branch cut of `**`, so `Pow.eigvals()` and
`Pow2.eigvals()` returned the complex conjugate of the correct
eigenvalues for non-integer `z`, disagreeing with `qml.matrix`.
Replace the `(1 + 0j) *` cast idiom introduced in #9802 with
`math.cast(..., "complex128")`, and assert in both tests that the
eigenvalues match the diagonal of the matrix so branch-cut flips are
caught on any Python version.
Authored with AI assistance (GitHub Copilot CLI).
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>1 parent 1f51ae2 commit 29c603d
5 files changed
Lines changed: 18 additions & 2 deletions
File tree
- doc/releases
- pennylane/ops/op_math
- tests/ops/op_math
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1596 | 1596 | | |
1597 | 1597 | | |
1598 | 1598 | | |
| 1599 | + | |
| 1600 | + | |
| 1601 | + | |
| 1602 | + | |
| 1603 | + | |
| 1604 | + | |
1599 | 1605 | | |
1600 | 1606 | | |
1601 | 1607 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
336 | 336 | | |
337 | 337 | | |
338 | 338 | | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
339 | 342 | | |
340 | | - | |
| 343 | + | |
341 | 344 | | |
342 | 345 | | |
343 | 346 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
241 | 241 | | |
242 | 242 | | |
243 | 243 | | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
244 | 247 | | |
245 | | - | |
| 248 | + | |
246 | 249 | | |
247 | 250 | | |
248 | 251 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
356 | 356 | | |
357 | 357 | | |
358 | 358 | | |
| 359 | + | |
| 360 | + | |
359 | 361 | | |
360 | 362 | | |
361 | 363 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
446 | 446 | | |
447 | 447 | | |
448 | 448 | | |
| 449 | + | |
| 450 | + | |
449 | 451 | | |
450 | 452 | | |
451 | 453 | | |
| |||
0 commit comments