• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Qiskit / qiskit-terra / 5589940418
87%

Build:
DEFAULT BRANCH: main
Ran 18 Jul 2023 04:49PM UTC
Jobs 1
Files 1265
Run time 29s
Badge
Embed ▾
README BADGES
x

If you need to use a raster PNG badge, change the '.svg' to '.png' in the link

Markdown

Textile

RDoc

HTML

Rst

pending completion
5589940418

push

github

web-flow
Use singleton matrices for unparametrised standard gates (#10296)

* Use singleton matrices for unparametrised standard gates

This makes the array form of standard gates with zero parameters
singleton class attributes that reject modification. The class-level
`__array__` methods are updated to return exactly the same instance,
except in very unusual circumstances, which means that
`Gate.to_matrix()` and `numpy.asarray()` calls on the objects will
return the same instance. This avoids a decent amount of construction
time, and avoids several Python-space list allocations and array
allocations.

The dtypes of the static arrays are all standardised to by complex128.
Gate matrices are in general unitary, `Gate.to_matrix()` already
enforces a cast to `complex128`.  For gates that allowed their dtypes to
be inferred, there were several cases where native ints and floats would
be used, meaning that `Gate.to_matrix()` would also involve an extra
matrix allocation to hold the cast, which just wasted time.

For standard controlled gates, we store both the closed- and
open-controlled matrices singly controlled gates.  For gates with more
than one control, we only store the "all ones" controlled case, as a
memory/speed trade-off; open controls are much less common than closed
controls.

For the most part this won't have an effect on peak memory usage, since
all the allocated matrices in standard Qiskit usage would be freed by
the garbage collector almost immediately.  This will, however, reduce
construction costs and garbage-collector pressure, since fewer
allocations+frees will occur, and no calculations will need to be done.

* Store only all-ones controls for large matrices

* Fix lint

* Use metaprogramming decorator to make `__array__` methods

Instead of defining the array functions manually for each class, this
adds a small amount of metaprogramming that adds them in with the
correct `ndarray` properties set, including for controlled gates.

72386 of 84124 relevant lines covered (86.05%)

45693.08 hits per line

Jobs
ID Job ID Ran Files Coverage
1 5589940418.1 18 Jul 2023 04:49PM UTC 0
86.05
GitHub Action Run
Source Files on build 5589940418
Detailed source file information is not available for this build.
  • Back to Repo
  • d62f7801 on github
  • Prev Build on main (#5588970869)
  • Next Build on main (#5591129273)
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc