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 pauli_decompose_hermitian() 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. The function validates that the number of qubits matches the matrix size, but uses assert instead of a proper exception.
Current Behavior
# paulialgebra.py:554
if qubits is None:
qubits = list(range(N))
else:
assert len(qubits) == NValidation Performed
$ python -O -m pytest quantumflow/ --tb=short
# 1332 passed — no tests fail when asserts are disabledWhy Fix Anyway?
- Input validation should use exceptions, not asserts
- 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
- Better error messages for users
Technical Details
- File:
quantumflow/paulialgebra.py - Line: 554
- Effort: ~15 minutes
- Risk: Very low
Proposed Fix
if qubits is None:
qubits = list(range(N))
elif len(qubits) != N:
raise ValueError(
f"Number of qubits ({len(qubits)}) must match matrix size. "
f"Matrix size {np.size(matrix)} requires {N} qubits."
)References
- Tracking issue: Review state of QuantumFlow #1
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels