forked from gecrooks/quantumflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Closed
Description
Summary
Replace assert statement with proper ValueError exception in circuit_to_latex() function.
Classification: Code Quality Improvement
Not a validated bug. Tests pass with python -O (asserts disabled). This is a defensive coding improvement, not a fix for observed failures.
Context
Part of tracking issue #1. Identified during code review. The maintainer left a # FIXME. Throw Exception comment on this line, indicating intent to fix.
Current Behavior
# visualization.py:173
assert package in ["qcircuit", "quantikz"] # FIXME. Throw ExceptionIf an invalid package parameter is passed:
- Normal Python: raises
AssertionError - With
python -O: silently continues, may cause confusing errors later
Validation Performed
$ python -O -m pytest quantumflow/ --tb=short
# 1332 passed — no tests fail when asserts are disabledThis means no existing test exercises this code path with invalid input.
Why Fix Anyway?
- Maintainer flagged it with
# FIXME - Follows pattern from upstream PRs Replace assert False with KeyError in DAGCircuit methods gecrooks/quantumflow#133, Replace assert with proper validation in channel_to_kraus() gecrooks/quantumflow#134
- Defensive coding — better error messages for users
- Asserts should be for internal invariants, not input validation
Technical Details
- File:
quantumflow/visualization.py - Line: 173
- Effort: ~15 minutes
- Risk: Very low
Proposed Fix
if package not in ["qcircuit", "quantikz"]:
raise ValueError(f"Invalid LaTeX package '{package}'. Must be 'qcircuit' or 'quantikz'.")References
- Tracking issue: Review state of QuantumFlow #1
- Similar fixes merged upstream: PRs Replace assert False with KeyError in DAGCircuit methods gecrooks/quantumflow#133, Replace assert with proper validation in channel_to_kraus() gecrooks/quantumflow#134
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels