Skip to content

Add missing express_nolookup for HGate → sHadamard under CliffordRepr#174

Merged
Krastanov merged 3 commits intoQuantumSavory:mainfrom
giovanniligato:fix-hgate-clifford-express
Mar 3, 2026
Merged

Add missing express_nolookup for HGate → sHadamard under CliffordRepr#174
Krastanov merged 3 commits intoQuantumSavory:mainfrom
giovanniligato:fix-hgate-clifford-express

Conversation

@giovanniligato
Copy link
Contributor

@giovanniligato giovanniligato commented Feb 26, 2026

Problem

express(H, CliffordRepr(), UseAsOperation()) fails with:

"Encountered an object H of type HGate that can not be converted to CliffordRepr() representation"

This means apply!(slot, H) works with QuantumOpticsRepr states but crashes with CliffordRepr states. In contrast, X, Y, and Z all have both Clifford and QuantumOptics mappings and work with either backend.

The QuantumOpticsExt already maps HGate, and HGate is already imported in QuantumCliffordExt, but the express_nolookup method for (::HGate, ::CliffordRepr, ::UseAsOperation) was never defined. QuantumClifford provides sHadamard as the corresponding symbolic Clifford gate.

Fix

Add the one-liner mapping, following the same pattern as the Pauli gates:

express_nolookup(::HGate, ::CliffordRepr, ::UseAsOperation) = QuantumClifford.sHadamard

Impact

After this fix, apply!(slot, H) becomes fully representation-agnostic, matching the behavior of X, Y, Z.

Discovered while working on a QuantumSavory-based protocol package where switching the default repr of registers from CliffordRepr() to QuantumOpticsRepr() (or vice versa) should not require changing gate references.


  • The code is properly formatted and commented.
  • Substantial new functionality is documented within the docs.
  • All new functionality is tested.
  • All of the automated tests on github pass.
  • We recently started enforcing formatting checks. If formatting issues are reported in the new code you have written, please correct them. There will be plenty of old code that is flagged as we are slowly transitioning to enforced formatting. Please do not worry about or address older formatting issues -- keep your PR just focused on your planned contribution.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 26, 2026

Benchmark Results (Julia v1)

Time benchmarks
main 9e49fde... main / 9e49fde...
creation/ket 20 ± 8 ns 20 ± 1 ns 1 ± 0.4
creation/large_trees/10_layers 0.796 ± 0.028 ms 0.794 ± 0.029 ms 1 ± 0.05
creation/large_trees/50_layers 0.0359 ± 0.003 s 0.0347 ± 0.0028 s 1.03 ± 0.12
creation/op 19 ± 1 ns 20 ± 1 ns 0.95 ± 0.069
creation/super_op 19 ± 1 ns 20 ± 2 ns 0.95 ± 0.11
express/clifford/simple_ket 1.18 ± 0.063 μs 1.19 ± 0.057 μs 0.995 ± 0.071
express/clifford/simple_observable 2.16 ± 0.24 μs 2.16 ± 0.24 μs 0.998 ± 0.16
express/optics/pauli_op_4 6.38 ± 0.24 μs 6.38 ± 0.21 μs 1 ± 0.051
express/optics/pauli_state_8 2.24 ± 0.086 μs 2.33 ± 0.085 μs 0.959 ± 0.051
express/optics/simple_ket 1.17 ± 0.06 μs 1.41 ± 0.077 μs 0.828 ± 0.062
express/optics/simple_op 1.32 ± 0.078 μs 1.26 ± 0.062 μs 1.04 ± 0.08
linalg/anticommutator 0.353 ± 0.039 μs 0.401 ± 0.043 μs 0.88 ± 0.14
linalg/commutator 0.375 ± 0.029 μs 0.393 ± 0.028 μs 0.954 ± 0.1
linalg/conjugate 0.039 ± 0.004 μs 0.038 ± 0.003 μs 1.03 ± 0.13
linalg/dagger 0.039 ± 0.004 μs 0.039 ± 0.003 μs 1 ± 0.13
linalg/inverse 0.038 ± 0.003 μs 0.04 ± 0.004 μs 0.95 ± 0.12
linalg/ptrace 11.7 ± 0.16 μs 11.9 ± 0.23 μs 0.984 ± 0.023
linalg/trace 0.038 ± 0.004 μs 0.037 ± 0.002 μs 1.03 ± 0.12
linalg/transpose 0.038 ± 0.005 μs 0.039 ± 0.004 μs 0.974 ± 0.16
manipulation/expand/commutator 1.61 ± 0.14 ms 1.64 ± 0.093 ms 0.986 ± 0.1
manipulation/expand/distribution 1.47 ± 0.04 ms 1.44 ± 0.043 ms 1.02 ± 0.041
manipulation/simplify/applicable_rules 5.24 ± 0.11 ms 5.13 ± 0.1 ms 1.02 ± 0.029
manipulation/simplify/commutator 0.0365 ± 0.0006 ms 0.0366 ± 0.00067 ms 0.999 ± 0.025
manipulation/simplify/irrelevant_rules 0.749 ± 0.019 ms 0.748 ± 0.018 ms 1 ± 0.034
operations/addition/ket 1.22 ± 0.086 μs 1.22 ± 0.062 μs 0.993 ± 0.086
operations/addition/op 1.2 ± 0.069 μs 1.21 ± 0.069 μs 0.995 ± 0.081
operations/multiplication/bra_ket 1.23 ± 0.027 μs 1.22 ± 0.033 μs 1.01 ± 0.035
operations/multiplication/bra_op 1.27 ± 0.04 μs 1.27 ± 0.04 μs 1 ± 0.045
operations/multiplication/inner 1.24 ± 0.02 μs 1.22 ± 0.027 μs 1.02 ± 0.028
operations/multiplication/many 8.53 ± 0.28 μs 8.53 ± 0.3 μs 1 ± 0.048
operations/multiplication/op 1.16 ± 0.045 μs 1.16 ± 0.027 μs 0.999 ± 0.045
operations/multiplication/op_ket 1.32 ± 0.029 μs 1.32 ± 0.037 μs 0.994 ± 0.035
operations/multiplication/outer 1.27 ± 0.038 μs 1.29 ± 0.036 μs 0.981 ± 0.04
operations/scaling/ket 0.076 ± 0.006 μs 0.098 ± 0.023 μs 0.776 ± 0.19
operations/scaling/op 0.075 ± 0.008 μs 0.097 ± 0.024 μs 0.773 ± 0.21
operations/tensor/ket 1.08 ± 0.047 μs 1.08 ± 0.035 μs 0.994 ± 0.054
operations/tensor/many 9.42 ± 0.18 μs 9.39 ± 0.18 μs 1 ± 0.027
operations/tensor/op 1.06 ± 0.035 μs 1.07 ± 0.035 μs 0.995 ± 0.046
time_to_load 2.16 ± 0.007 s 2.17 ± 0.0057 s 0.996 ± 0.0042
Memory benchmarks
main 9e49fde... main / 9e49fde...
creation/ket 0 allocs: 0 B 0 allocs: 0 B
creation/large_trees/10_layers 11.6 k allocs: 0.283 MB 11.6 k allocs: 0.283 MB 1
creation/large_trees/50_layers 0.662 M allocs: 13 MB 0.662 M allocs: 13 MB 1
creation/op 0 allocs: 0 B 0 allocs: 0 B
creation/super_op 0 allocs: 0 B 0 allocs: 0 B
express/clifford/simple_ket 16 allocs: 0.641 kB 16 allocs: 0.641 kB 1
express/clifford/simple_observable 0.06 k allocs: 2.66 kB 0.06 k allocs: 2.66 kB 1
express/optics/pauli_op_4 0.055 k allocs: 3.72 kB 0.055 k allocs: 3.72 kB 1
express/optics/pauli_state_8 31 allocs: 1.27 kB 31 allocs: 1.27 kB 1
express/optics/simple_ket 20 allocs: 0.75 kB 20 allocs: 0.75 kB 1
express/optics/simple_op 26 allocs: 1.09 kB 26 allocs: 1.09 kB 1
linalg/anticommutator 11 allocs: 0.438 kB 11 allocs: 0.438 kB 1
linalg/commutator 11 allocs: 0.438 kB 11 allocs: 0.438 kB 1
linalg/conjugate 3 allocs: 0.125 kB 3 allocs: 0.125 kB 1
linalg/dagger 3 allocs: 0.125 kB 3 allocs: 0.125 kB 1
linalg/inverse 3 allocs: 0.125 kB 3 allocs: 0.125 kB 1
linalg/ptrace 0.098 k allocs: 3.56 kB 0.098 k allocs: 3.56 kB 1
linalg/trace 3 allocs: 0.125 kB 3 allocs: 0.125 kB 1
linalg/transpose 3 allocs: 0.125 kB 3 allocs: 0.125 kB 1
manipulation/expand/commutator 14.4 k allocs: 0.453 MB 14.5 k allocs: 0.453 MB 1
manipulation/expand/distribution 15.4 k allocs: 0.492 MB 15.4 k allocs: 0.492 MB 1
manipulation/simplify/applicable_rules 0.0496 M allocs: 1.66 MB 0.0497 M allocs: 1.67 MB 0.999
manipulation/simplify/commutator 0.444 k allocs: 14.1 kB 0.444 k allocs: 14.1 kB 1
manipulation/simplify/irrelevant_rules 8.5 k allocs: 0.267 MB 8.5 k allocs: 0.267 MB 1
operations/addition/ket 25 allocs: 1.48 kB 25 allocs: 1.48 kB 1
operations/addition/op 25 allocs: 1.48 kB 25 allocs: 1.48 kB 1
operations/multiplication/bra_ket 12 allocs: 0.453 kB 12 allocs: 0.453 kB 1
operations/multiplication/bra_op 13 allocs: 0.484 kB 13 allocs: 0.484 kB 1
operations/multiplication/inner 12 allocs: 0.453 kB 12 allocs: 0.453 kB 1
operations/multiplication/many 0.083 k allocs: 3.17 kB 0.083 k allocs: 3.17 kB 1
operations/multiplication/op 12 allocs: 0.469 kB 12 allocs: 0.469 kB 1
operations/multiplication/op_ket 13 allocs: 0.484 kB 13 allocs: 0.484 kB 1
operations/multiplication/outer 13 allocs: 0.484 kB 13 allocs: 0.484 kB 1
operations/scaling/ket 4 allocs: 0.156 kB 4 allocs: 0.156 kB 1
operations/scaling/op 4 allocs: 0.156 kB 4 allocs: 0.156 kB 1
operations/tensor/ket 12 allocs: 0.469 kB 12 allocs: 0.469 kB 1
operations/tensor/many 0.078 k allocs: 3.44 kB 0.078 k allocs: 3.44 kB 1
operations/tensor/op 12 allocs: 0.469 kB 12 allocs: 0.469 kB 1
time_to_load 0.149 k allocs: 11.2 kB 0.149 k allocs: 11.2 kB 1

@Krastanov
Copy link
Member

Well, this was an embarrassing omission. Thanks for adding it!

@Krastanov Krastanov merged commit 6ed325d into QuantumSavory:main Mar 3, 2026
12 of 16 checks passed
@Krastanov
Copy link
Member

Should be in a release version in 15ish minutes.

@giovanniligato giovanniligato deleted the fix-hgate-clifford-express branch March 4, 2026 07:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants