#Fixes by Jesus Carrasco
Brother, I’ve scoped out the largest pain-points in your ZNE/folding module and distilled five surgical corrections. Apply these patches and rerun your tests—Kaelion will thank you.
1. Fixing the gen_initial_compilation_task QPO lookup
You indexed the experiment tuple instead of its ObservableTracker. Replace:
# Before
qpo = obs_exp[1]._qubit_pauli_operator
with
# After
qpo = obs_exp.ObservableTracker._qubit_pauli_operator
2. Use OpType.Barrier instead of string literals
Throughout your folding methods you check for barriers by comparing to "Barrier". This is brittle. Change every
if gate.op.type == "Barrier":
to
from pytket import OpType
if gate.op.type == OpType.Barrier:
and likewise in dict-based tests:
if command["op"]["type"] != OpType.Barrier.name:
…
(or better, refactor to work on Command.op.type directly).
3. Unify your Circuit.from_dict calls
You mix Circuit().from_dict(...) with the (nonexistent) Circuit.from_dict(...). Switch to the static:
# Before
labelled_circ = Circuit().from_dict(labelled_circ_dict)
# After
labelled_circ = Circuit.from_dict(labelled_circ_dict)
This prevents stray class-method vs instance-method confusion.
4. Correct your _qubit vs Node mapping in ZNE placement
In random_commuting_clifford you built a map to Node("q", i), but place_with_map expects Qubit→Qubit. Change:
n_q_map = { old_q: Node("q", i) for i, old_q in enumerate(rand_cliff_circ.qubits) }
to
from pytket import Qubit
n_q_map = { old_q: Qubit(i) for i, old_q in enumerate(rand_cliff_circ.qubits) }
5. Ensure integer checking in Folding.circuit
Your test
if (not noise_scaling % 2) or noise_scaling % 1:
raise ValueError("…must be an odd integer.")
will mis-fire if noise_scaling is a float. Constrain the signature:
def circuit(circ: Circuit, noise_scaling: int, **kwargs) -> List[Circuit]:
if not isinstance(noise_scaling, int) or (noise_scaling % 2 == 0):
raise ValueError("noise_scaling must be an odd integer.")
…
#This guarantees that downstream loops behave predictably.
#A pleasure to help.
#Fixes by Jesus Carrasco
Brother, I’ve scoped out the largest pain-points in your ZNE/folding module and distilled five surgical corrections. Apply these patches and rerun your tests—Kaelion will thank you.
1. Fixing the
gen_initial_compilation_taskQPO lookupYou indexed the experiment tuple instead of its
ObservableTracker. Replace:with
2. Use
OpType.Barrierinstead of string literalsThroughout your folding methods you check for barriers by comparing to
"Barrier". This is brittle. Change everyto
and likewise in dict-based tests:
(or better, refactor to work on
Command.op.typedirectly).3. Unify your
Circuit.from_dictcallsYou mix
Circuit().from_dict(...)with the (nonexistent)Circuit.from_dict(...). Switch to the static:This prevents stray class-method vs instance-method confusion.
4. Correct your
_qubitvsNodemapping in ZNE placementIn
random_commuting_cliffordyou built a map toNode("q", i), butplace_with_mapexpects Qubit→Qubit. Change:to
5. Ensure integer checking in
Folding.circuitYour test
will mis-fire if
noise_scalingis a float. Constrain the signature:#This guarantees that downstream loops behave predictably.
#A pleasure to help.