Fix TypeError in pqk data_map_func with unbound ParameterExpression (Qiskit 2.2.0)#7
Open
cgaylord-gwu wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Running
pqk()inqbiocode/embeddings/embed.pyraises:This fires during quantum circuit construction — specifically in
circuit.compose(feature_map, inplace=True),which triggers
PauliFeatureMap's lazy_build(), which in turn calls the user-supplieddata_map_funcwith symbolic (unbound)
ParameterExpressionobjects rather than concrete numeric values.Root cause
Qiskit's documented signature for
data_map_funcisCallable[[Parameter], ParameterExpression](see zz_feature_map docs) —
i.e. it's expected to handle symbolic parameters, not only bound numeric data. In current Qiskit
(tested on 2.2.0), this function is invoked during circuit construction, before any real data is bound,
so
xcontainsParameterExpressionobjects. The existingfloat(coeff)call assumescoeffis alwaysa plain number, which breaks under this calling convention.
Fix
Wrap the numeric cast in a
try/except TypeError. Whencoeffis a concrete number, behavior is unchanged(
float(coeff)succeeds as before). Whencoeffis a symbolic, unboundParameterExpression, return itunevaluated so Qiskit can bind real values later during circuit execution.
To reproduce (pre-fix)
Run the PQK cell in the QSage tutorial notebook (
tutorial/QSage/qsage.ipynb) withqiskit==2.2.0—fails at
circuit.compose(feature_map, inplace=True)insidepqk().Testing done
Ran the PQK workflow end-to-end post-fix, including live execution against real IBM Quantum hardware
(
ibm_fez), with no regressions observed in the numeric-input path.Found while working through the ISMB 2026 tutorial materials.