Closed maffoo closed 1 year ago
All modified and coverable lines are covered by tests :white_check_mark:
Comparison is base (
3c81961
) 97.84% compared to head (c43f689
) 97.84%.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
Updated to optimized NamedQubit
as well; first-time hashing sped up from 1.78us to 553ns (3.2x speedup) and repeated hashing sped up from 220ns to 162ns (1.36x speedup).
On master:
In [2]: nq = cirq.NamedQubit("abc")
In [3]: %timeit hash(nq)
220 ns ± 14.1 ns per loop (mean ± std. dev. of 7 runs, 1,000,000 loops each)
In [4]: %timeit hash(cirq.NamedQubit("abc"))
1.78 µs ± 13.9 ns per loop (mean ± std. dev. of 7 runs, 1,000,000 loops each)
On this branch:
In [2]: nq = cirq.NamedQubit("abc")
In [3]: %timeit hash(nq)
162 ns ± 4.14 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each)
In [4]: %timeit hash(cirq.NamedQubit("abc"))
553 ns ± 1.16 ns per loop (mean ± std. dev. of 7 runs, 1,000,000 loops each)
This speeds up hashing on
GridQubit
,GridQid
,LineQubit
, andLineQid
. Instead of using_compat.cached_method
, we store an explicitself._hash
property to cache computing the hash. We also make the constructors explicit in the concrete classes with no need to call a subperclass constructor. We did some basic benchmarks to compare performance with current master. On this branchGridQubit.__hash__
dropped from 1.3us to 488ns (2.66x speedup), while repeated hashing of the same grid qubit dropped from 150ns to 121ns (1.24x speedup). Similarly,LineQubit.__hash__
dropped from 685uns to 453ns (1.51x speedup), while repeated hashing of the same line qubit dropped from 142ns to 124ns (1.15x speedup).On master:
and on this branch: