`ReflectionUsingPrepare.adjoint()` returns `self` for non-real `global_phase`

Abierto
#2,009 0 comentarios 0 reacciones 0 asignados Ver en GitHub

@doubleMcyber ya está trabajando en esto.

Desde el 25/11/2026.

  • #2010 de @doubleMcyber — abierto

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
35/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Estancado
Stack tecnológico
numpy, python

Línea de trabajo

Read qualtran/bloqs/reflections/reflection_using_prepare.py around adjoint() and review the linked pull request #2010 to see the current work. Run the issue’s reproducer for non-real global_phase and check that composing the gate with its adjoint gives the identity; add or run a regression test for that case.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

ReflectionUsingPrepare implements g·(I − 2|s⟩⟨s|) with g = global_phase. For a non-real g the adjoint is conj(g)·(I − 2|s⟩⟨s|), but adjoint() returns self:

https://github.com/quantumlib/Qualtran/blob/f559b12/qualtran/bloqs/reflections/reflection_using_prepare.py#L196-L197

Uncontrolled, the difference is only a global phase g². With control_val set (or after .controlled()), g is a relative phase, so R followed by R.adjoint() applies a controlled g² instead of the identity. Real g (1 and −1) is unaffected. I found no validator that restricts global_phase to real values.

Reproducer

import itertools, numpy as np, cirq
from qualtran.bloqs.reflections.prepare_identity import PrepareIdentity
from qualtran.bloqs.reflections.reflection_using_prepare import ReflectionUsingPrepare
from qualtran.cirq_interop.testing import GateHelper

def unitary(gate):
    g = GateHelper(gate)
    ctx = cirq.DecompositionContext(cirq.GreedyQubitManager(prefix="anc"))
    c = cirq.Circuit(cirq.decompose(g.operation, context=ctx))
    sys_q = list(itertools.chain(*g.quregs.values()))
    order = sys_q + sorted(c.all_qubits() - set(sys_q))
    U = c.unitary(qubit_order=order)
    n, a = len(sys_q), len(order) - len(sys_q)
    return U.reshape(2**n, 2**a, 2**n, 2**a)[:, 0, :, 0]   # ancillas in |0>

R = ReflectionUsingPrepare(PrepareIdentity.from_bitsizes([2]), control_val=1, global_phase=1j)
U, V = unitary(R), unitary(R.adjoint())
print(np.linalg.norm(U @ V - np.eye(8)))   # prints 4.0, expected about 0

With global_phase=1 or -1 the same script prints about 3e-15.

Suggested fix

def adjoint(self) -> 'ReflectionUsingPrepare':
    return attrs.evolve(self, global_phase=np.conj(self.global_phase))

With this change U @ V is the identity to about 3e-15 in the cases I tested.

Version

qualtran 0.7.0. The file is identical to main at f559b12 for these lines.

I'm happy to open a pull request with the fix and a test if that's useful. I found this with AI-assisted code review and confirmed by running the script above.

Lenguaje dominante
Python
Estrellas
397
Forks
127
Merge medio
2 d 22 h
PR fusionados (30 d)
1

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de quantumlib/Qualtran

Todos los issues de quantumlib/Qualtran

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.