Add QuantumGates module#50
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests.
🚀 New features to boost your workflow:
|
|
After the build completes, the updated documentation will be available here |
Agreed, i would keep Although the aliases are very much in line with the names often used in literature, exporting things like |
|
I think the exports are probably okay, this is within the submodule, so you would only import them if you included that in its entirety (since we already have name clashes between Hubbard and TJ too). I don't think this can accidentally leak into previous scripts, you really need |
|
That |
|
I'm not sure if anyone is ever really using U1 for quantum computing operations, it seems like in that context this doesn't happen all that often, which is more or less why I was asking if this is useful |
Introduce a QuantumGates submodule exposing common single-, two-, and three-qubit gates as TensorMaps on qubit spaces (Trivial and U1Irrep). Each gate is defined through the @operator macro from a single non-symmetric reference method: the symmetric terminal routes the dense operator through `symmetrize` using an identity `basis_transform` (the qubit computational basis already coincides with the U(1) charge eigenbasis). Number-conserving gates gain their U(1) version automatically, while gates that flip qubits raise an ArgumentError under U1Irrep. Parametric gates (phase_shift, rotation_x/y/z, cphase) take the rotation angle as a required keyword `θ`, with the ASCII name `theta` accepted as an alias, matching the package convention of keyword operator parameters. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add the parametric two-qubit rotation gates rotation_xx/Rxx, rotation_yy/Ryy,
rotation_zz/Rzz and rotation_zx/Rzx, i.e. exp(-iθ/2 P⊗P) for P⊗P in
{X⊗X, Y⊗Y, Z⊗Z, Z⊗X}. Like the single-qubit rotations they take the angle as
a required keyword `θ` (with `theta` accepted as an ASCII alias). rotation_zz is
diagonal and gains its U(1) version automatically; the others reject U1Irrep.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- swap: build the identity at the requested eltype (`id(elt, q ⊗ q)`); permuting a non-symmetric tensor preserves eltype, so the extra scalar multiplication is no longer needed. - rotation_x/y/z: compute sin and cos in one `sincos` call and fill the 2×2 matrix entries directly instead of assembling `cos·I - i·sin·P`; the two-site rotations likewise share a single `sincos`. - phase_shift: build `diag(1, cis(θ))` directly. - hadamard: build from `RationalRoots.signedroot(1//2)` and promote to eltype. - Docstrings now use unicode (|0⟩, ⟨0|, ⊗, θ, †, ↦, ↔) where it renders cleanly, matching the house style; each parametric gate documents both `θ` and `theta`. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- Export and document `basis_transform`, matching the other macro-based
operator modules (index.md advertises it as each module's public entry
point). Collapse its three per-symmetry methods into the single
`symmetry::Type{<:Sector}` form used by FermionOperators/BosonOperators;
the invalid-symmetry error now comes from `qubit_space` for free.
- Factor the repeated `θ`/`theta` angle-resolution idiom (duplicated across
all nine parametric gates) into a single `_gate_angle` helper.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This adds a
QuantumGatessubmodule with the typical quantum-computing gates (a good chunk of the Clifford and non-Clifford ones), returned asTensorMaps on qubit spaces. It has been rebased ontomainand rewritten on top of the new@operatormacro (#51).Following the earlier discussion, the boilerplate-heavy first version has been reworked:
@operator. Each gate is now defined by a single non-symmetricTrivialreference method, and the element-type/symmetry forwarding methods plus the symmetric version are generated automatically viasymmetrize/basis_transform. Because the qubit computational basis already coincides with the U(1) charge eigenbasis,basis_transformis just the identity: number-conserving gates get theirU1Irrepversion for free, while qubit-flipping gates simply throw anArgumentErrorunderU1Irrep. This removes all the hand-written per-symmetry boilerplate (e.g.pauli_z's explicit U(1) branch).sqrtgates (sqrt_x/SX,sqrt_swap,sqrt_iswap) — these are trivially reconstructible from the primitives (sqrt_iswap(...) = sqrt(iswap(...)), etc.) and don't add much.Rxx,Ryy,Rzz,Rzx, i.e.exp(-iθ/2 · P⊗P).Rzzis diagonal and so gains aU1Irrepversion; the others areTrivial-only.θrather than positional, matching the package'sspin=/cutoff=convention (and letting the parametric gates go through@operatoruniformly). The ASCII namethetais accepted as an alias, so bothrotation_x(; θ=π/2)androtation_x(; theta=π/2)work.Still open for opinions:
U1Irrepoption is actually worth it.Implemented gates
qubit_spaceTrivial,U1Irreppauli_xXTrivialpauli_yYTrivialpauli_zZTrivial,U1Irrepproj_0P0Trivial,U1Irrepproj_1P1Trivial,U1IrrephadamardHTrivials_gateSTrivial,U1Irrept_gateTTrivial,U1Irrepphase_shiftPTrivial,U1Irreprotation_xRxTrivialrotation_yRyTrivialrotation_zRzTrivial,U1IrrepcnotCNOT,CXTrivialcyCYTrivialczCZTrivial,U1IrrepchCHTrivialcsCSTrivial,U1IrrepcphaseCPTrivial,U1IrrepswapSWAPTrivial,U1IrrepiswapISWAPTrivial,U1IrrepdcxDCXTrivialecrECRTrivialrotation_xxRxxTrivialrotation_yyRyyTrivialrotation_zzRzzTrivial,U1Irreprotation_zxRzxTrivialtoffoliTOFFOLI,CCXTrivialfredkinFREDKIN,CSWAPTrivial,U1Irrep🤖 Generated with Claude Code