Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mitiq requires Typing typehint to create batched executor #2669

Open
natestemen opened this issue Feb 11, 2025 · 0 comments
Open

Mitiq requires Typing typehint to create batched executor #2669

natestemen opened this issue Feb 11, 2025 · 0 comments
Assignees
Labels
bug Something isn't working executors
Milestone

Comments

@natestemen
Copy link
Member

Issue Description

Mitiq's Executor class as a method is_batched_executor which indicates whether it has the capability of running multiple circuits with a single call. It knows whether it can do this by looking at the annotation of the python function passed to the Executor upon instantiation.

return executor_annotation.get("return") in (
BatchedType[T] # type: ignore[index]
for BatchedType in [Iterable, List, Sequence, Tuple]
for T in QuantumResult.__args__ # type: ignore[attr-defined]
)

The way this is written requires the annotated return type to use a typing class. We should generalize this code to allow for users to create batched executors while using modern python type-hints using data structure constructors (list, set, tuple, etc).

How to Reproduce

def batched_ex(circuits: list[...]) -> list[float]: ...

ex = mitiq.Executor(batched_ex)

ex.is_batched_executor
>>> False  # this should be True
@natestemen natestemen added bug Something isn't working executors labels Feb 11, 2025
@natestemen natestemen added this to the 0.44.0 milestone Feb 11, 2025
@natestemen natestemen self-assigned this Feb 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working executors
Projects
None yet
Development

No branches or pull requests

1 participant