Skip to content

Fix TypeError in pqk data_map_func with unbound ParameterExpression (Qiskit 2.2.0)#7

Open
cgaylord-gwu wants to merge 1 commit into
IBM:mainfrom
cgaylord-gwu:fix/pqk-data-map-func-unbound-parameter
Open

Fix TypeError in pqk data_map_func with unbound ParameterExpression (Qiskit 2.2.0)#7
cgaylord-gwu wants to merge 1 commit into
IBM:mainfrom
cgaylord-gwu:fix/pqk-data-map-func-unbound-parameter

Conversation

@cgaylord-gwu

Copy link
Copy Markdown

Problem

Running pqk() in qbiocode/embeddings/embed.py raises:

TypeError: Parameter expression with unbound parameters {Symbol { name: "_", ... }} is not numeric.

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-supplied data_map_func
with symbolic (unbound) ParameterExpression objects rather than concrete numeric values.

Root cause

Qiskit's documented signature for data_map_func is Callable[[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 x contains ParameterExpression objects. The existing float(coeff) call assumes coeff is always
a plain number, which breaks under this calling convention.

Fix

Wrap the numeric cast in a try/except TypeError. When coeff is a concrete number, behavior is unchanged
(float(coeff) succeeds as before). When coeff is a symbolic, unbound ParameterExpression, return it
unevaluated 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) with qiskit==2.2.0
fails at circuit.compose(feature_map, inplace=True) inside pqk().

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant