`tfq_ps_decompose` corrupts `PhasedISwapPowGate` when `exponent` is numeric and `phase_exponent` is symbolic
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 78/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- python, tensorflow
- Área
- backend, machine-learning
Línea de trabajo
Lee tensorflow_quantum/core/ops/tfq_ps_decompose_op.cc, especialmente getOpForISP y su punto de llamada a tfq_ps_decompose en TfqPsDecomposeOp::Compute. Compara cómo maneja los exponentes simbólicos y numéricos con getOpForPXP, getOpForPISP y getOpForFSIM. Reproduce el problema con el circuito proporcionado y el ejemplo de resolución de parámetros; se considera terminado cuando las operaciones descompuestas conservan el exponente numérico correcto y se resuelven sin el error indicado.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
In TfqPsDecomposeOp::Compute (tensorflow_quantum/core/ops/tfq_ps_decompose_op.cc, lines 75–97), a PISP (cirq.PhasedISwapPowGate) operation is decomposed whenever either exponent or phase_exponent is symbolic (Arg::ArgCase::kSymbol):
if (exponent.arg_case() == Arg::ArgCase::kSymbol ||
phase_exponent.arg_case() == Arg::ArgCase::kSymbol) {
// Decompose cirq.PhasedISwapPowGate only if it is
// parameterized.
num_extra_moments = 5;
Operation new_op;
new_op = getOpForPISP(cur_op, 0, 0);
cur_moment.mutable_operations()->at(k) = new_op;
new_op = getOpForPISP(cur_op, 1, 1);
*temp_moment_list[0].add_operations() = new_op;
new_op = getOpForISP(cur_op, "XXP", exponent.symbol());
*temp_moment_list[1].add_operations() = new_op;
new_op = getOpForISP(cur_op, "YYP", exponent.symbol());
*temp_moment_list[2].add_operations() = new_op;
new_op = getOpForPISP(cur_op, 1, 0);
*temp_moment_list[3].add_operations() = new_op;
new_op = getOpForPISP(cur_op, 0, 1);
*temp_moment_list[4].add_operations() = new_op;
}
However, getOpForISP (lines 164–187) was written for ISP, where exponent is guaranteed to be symbolic, and unconditionally writes new_op_map["exponent"].set_symbol(symbol).
When phase_exponent is a sympy.Symbol and exponent is a numeric constant (Arg::ArgCase::kArgValue — including Cirq's default exponent=1.0, or any non-unit float such as 0.5):
exponent.symbol()evaluates to""(empty string), andexponent.arg_value().float_value()is ignored.- The decomposed
XXPandYYPoperations receive a symbolicexponentwith empty symbol name""(sympy.Symbol('')after deserialization) instead of a numeric float-0.5 * exponent.arg_value().float_value(). - Resolving circuit parameters leaves unresolved
sympy.Symbol('')expressions on theXXPowGateandYYPowGateoperations, corrupting the decomposed circuit and breakingParameterShiftdifferentiation wheneverPhasedISwapPowGatehas a symbolicphase_exponentand numericexponent.
Minimal Reproduction
import cirq
import sympy
import tensorflow_quantum as tfq
from tensorflow_quantum.core.ops import tfq_ps_util_ops
q0, q1 = cirq.GridQubit.rect(1, 2)
beta = sympy.Symbol("beta")
# Numeric exponent with symbolic phase_exponent.
circuit = cirq.Circuit(
cirq.PhasedISwapPowGate(phase_exponent=beta, exponent=0.5).on(q0, q1)
)
decomposed_tensor = tfq_ps_util_ops.tfq_ps_decompose(
tfq.convert_to_tensor([circuit])
)
decomposed_circuit = tfq.from_tensor(decomposed_tensor)[0]
print(decomposed_circuit)
# Raises TypeError because XXPowGate and YYPowGate contain sympy.Symbol('').
cirq.unitary(cirq.resolve_parameters(decomposed_circuit, {"beta": 0.72}))
Observed decomposed circuit:
(0, 0): ───Z^beta───────────────XX───────────YY───────────Z^(-beta)────────────
│ │
(0, 1): ────────────Z^(-beta)───XX^(-0.5*)───YY^(-0.5*)───────────────Z^beta───
Possible Fix
Update getOpForISP to read exponent from cur_op directly (or accept const Arg& instead of std::string symbol) and switch on exponent.arg_case(), consistent with getOpForPXP, getOpForPISP, and getOpForFSIM: keep set_symbol(...) and exponent_scalar = -0.5 * cur_exponent_scalar for Arg::ArgCase::kSymbol, and set exponent to -0.5 * exponent.arg_value().float_value() with exponent_scalar = 1.0 for Arg::ArgCase::kArgValue.
- Lenguaje dominante
- Python
- Estrellas
- 2.2k
- Forks
- 674
- Merge medio
- 1 d 14 h
- PR fusionados (30 d)
- 5
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de tensorflow/quantum
-
Avoid hard-coding "quantum" in `scripts/` scriptsPosiblemente ocupada @openbotgit la tomó hace 23 días. Abiertoarea/devops help wanted no QC knowledge needed priority/before-0.7.7
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
tensorflow/quantum#1082 · 2 comentarios · 1 reacción ·
Los mantenedores suelen responder en 1 día
-
area/c++ area/core kind/bug-report
Dificultad 3/5 1-2 días Aptitud para principiantes 74/100
tensorflow/quantum#1141 ·
Los mantenedores suelen responder en 1 día
-
Bug (likely typo) in `core/serialize/serializer_test.py`Posiblemente ocupada @mhucka la tomó hace 15 días. Abiertoarea/serialization area/tests
tensorflow/quantum#1129 · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
Support Keras 3Quizá libre de nuevo @rosspeili la tomó hace 118 días y no hay ningún pull request abierto. Abiertoarea/keras help wanted skill-level/intermediate
tensorflow/quantum#1090 · 5 comentarios · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
Support dynamic quantum circuitsAbiertoarea/circuits priority/after-0.7.7 skill-level/expert
Dificultad 5/5 Más de una semana Aptitud para principiantes 25/100
tensorflow/quantum#1087 ·
Los mantenedores suelen responder en 1 día
Todos los issues de tensorflow/quantum
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
UKGovernmentBEIS/inspect_ai#6512 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 68/100
Kav-K/GPTDiscord#501 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
UKGovernmentBEIS/inspect_evals#2863 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
[Bug]: graphify query loads every language extractor just for _file_stem (about 34 ms per call)Posiblemente ocupada @rohit-jsfreaky la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Graphify-Labs/graphify#5160 · 1 comentario ·
Los mantenedores suelen responder en 2 días