qiskit-algorithms icon indicating copy to clipboard operation
qiskit-algorithms copied to clipboard

Improve typing

Open mrossinek opened this issue 1 year ago • 3 comments

What should we add?

While working on #73, @ElePT and I have identified the following inconsistencies and/or problems around the type hints which should be investigated further. Rather than holding up that PR unnecessarily, we decided to gather these here. That way, they can be investigated one-by-one.

Note: some of these may very likely require code changes to resolve inconsistencies in the interfaces.

  • [ ] Typing around np.ndarray vs Sequence[float]. It is a known issue that to mypy the numpy arrays do not satisfy the Sequence type. This leads to many type ignore statements right now which can hopefully be improved upon.
    • [ ] For example, typing around parameter values being passed on to the primitives: sometimes its Sequence[float], sometimes its Sequence[Sequence[float]], and oftentimes internally it ends up as np.ndarray causing many type ignore comments
  • [ ] The typing of the initial_point attributes is very inconsistent across its various occurrences.
  • [ ] The Minimizer interface does not appear to be supported properly by VQD and PVQD (for example) since they do not provide the required jac argument
  • [ ] The ListOrDict type is causing quite some oddities. This has multiple cases:
    • [ ] for the metadata (e.g. variance) types and implementations are inconsistent with the variance sometimes wrapped in dictionaries and sometimes provided as a single number
    • [ ] for aux_operators and/or observables we had to add many type ignores which would need to be re-evaluated (possibly linked to the previous point)
  • [ ] All classes that use the EsimationProblem have very poor typing around the following points:
    • [ ] the post_processing function
    • [ ] the confidence intervals
    • [ ] the circuit_results
  • [ ] Add py.typed file back again - removed by #121

mrossinek avatar Sep 08 '23 14:09 mrossinek