Skip to content

Fix final mypy errors for issue #1282 and enable strict checking#1392

Merged
mhucka merged 4 commits into
quantumlib:mainfrom
rosspeili:fix/issue-1282-mypy-final
Jun 30, 2026
Merged

Fix final mypy errors for issue #1282 and enable strict checking#1392
mhucka merged 4 commits into
quantumlib:mainfrom
rosspeili:fix/issue-1282-mypy-final

Conversation

@rosspeili

Copy link
Copy Markdown
Contributor

Complete strict mypy for split_operator, linear_swap_network, and thc_jax, set ignore_errors to false in pyproject.toml, and fix shell_tools_test duplicate kwarg. Closes #1282

…cking

Complete strict mypy for split_operator, linear_swap_network, and thc_jax; set ignore_errors to false in pyproject.toml; fix shell_tools_test duplicate kwarg.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request enables mypy type checking by setting ignore_errors = false in pyproject.toml and addresses numerous type annotation issues across the codebase. Specifically, it updates generator functions in Trotter algorithms to return Iterator[cirq.OP_TREE] instead of cirq.OP_TREE, introduces proper type casting for DiagonalCoulombHamiltonian, and modernizes type annotations in thc_jax.py using Python 3.9+ built-in collections and union operators. However, the review highlights a critical issue in thc_jax.py where calling np.asarray(xcur) on a JAX tracer object will raise a TracerArrayConversionError at runtime. To resolve this, it is recommended to pass xcur directly and update the type signature of unpack_thc_factors to accept npt.NDArray | jax.Array.

Comment thread src/openfermion/resource_estimates/pbc/thc/factorizations/thc_jax.py Outdated
Comment thread src/openfermion/resource_estimates/pbc/thc/factorizations/thc_jax.py Outdated
Cast isdf norm to float, pass list to json_normalize for pandas-stubs, and widen unpack_thc_factors for JAX tracers without np.asarray in the objective.
@rosspeili

Copy link
Copy Markdown
Contributor Author

Pushed fixes on CI mypy (isdf float cast, data_types .tolist() for pandas-stubs), Gemini JAX tracing suggestion (unpack_thc_factors widened, no np.asarray in the objective), and black formatting on thc_jax.py.

@mhucka mhucka left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very minor tweak, otherwise it's good.

Comment thread dev_tools/shell_tools_test.py Outdated
Comment thread dev_tools/shell_tools_test.py Outdated
@mhucka

mhucka commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator

@rosspeili I took the liberty of making the 2 tiny changes and pushing to your branch, so that I can merge this PR today.

@mhucka
mhucka added this pull request to the merge queue Jun 30, 2026
Merged via the queue into quantumlib:main with commit 864df59 Jun 30, 2026
23 checks passed
@mhucka mhucka mentioned this pull request Jul 1, 2026
@rosspeili
rosspeili deleted the fix/issue-1282-mypy-final branch July 1, 2026 07:46
@rosspeili

Copy link
Copy Markdown
Contributor Author

Glad to see this merge @mhucka, thanks a lot for the patience and guidance as always <3

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.

Mypy reports many errors, and they should be fixed

2 participants