Skip to content

Commit e4bfabf

Browse files
committed
fix: guard symbolic comparison in apply_flasq_cost_model
Address feedback from code review regarding potential TypeError when n_fluid_ancilla is symbolic. Added is_symbolic check to guard the comparison. Adversarial review: Checked that it preserves behavior for concrete values and falls through to division for symbolic ones. No issues found.
1 parent d74f277 commit e4bfabf

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

qualtran/surface_code/flasq/flasq_model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
)
4040
from qualtran.surface_code.flasq.utils import substitute_until_fixed_point
4141
from qualtran.surface_code.flasq.volume_counting import FLASQGateCounts
42-
from qualtran.symbolics import SymbolicFloat, SymbolicInt
42+
from qualtran.symbolics import is_symbolic, SymbolicFloat, SymbolicInt
4343

4444
# Initialize logger
4545
logger = logging.getLogger(__name__)
@@ -524,7 +524,7 @@ def apply_flasq_cost_model(
524524
# Guard against division by zero when n_fluid_ancilla is zero (or negative),
525525
# which produces zoo and leads to NaN errors during substitution/simplification.
526526
volume_limited_depth: SymbolicFloat
527-
if n_fluid_ancilla <= 0:
527+
if not is_symbolic(n_fluid_ancilla) and n_fluid_ancilla <= 0:
528528
volume_limited_depth = sympy.oo
529529
else:
530530
volume_limited_depth = total_computational_volume / n_fluid_ancilla # type: ignore[operator]

0 commit comments

Comments
 (0)