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

fix: Correct MitTask type #197

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions qermit/taskgraph/mittask.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from collections import namedtuple
from enum import Enum
from types import MethodType
from typing import Callable, Dict, List, Optional, Union
from typing import Callable, Dict, List, Optional, Tuple, Union

from pytket import Bit, Circuit, Qubit
from pytket.backends import ResultHandle
Expand Down Expand Up @@ -55,6 +55,22 @@ class IOTask(Enum):
Dict,
]

WireList = Union[
List[CircuitShots],
List[Circuit],
List[BackendResult],
List[ResultHandle],
List[AnsatzCircuit],
List[ObservableExperiment],
List[int],
List[float],
List[bool],
List[str],
List[QubitPauliOperator],
List[Dict[Qubit, Bit]],
List[Dict],
]

Comment on lines +58 to +73
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't know if there is a more succinct way of doing this. I would like Tuple[List[Wire], ...] to work but that assumes every List[Wire] in Tuple uses the same Wire.


class MitTask:
"""
Expand Down Expand Up @@ -98,7 +114,7 @@ def n_in_wires(self):
def n_out_wires(self):
return self._n_out_wires

def __call__(self, input_wires: List[Wire]) -> List[Wire]:
def __call__(self, input_wires: Tuple[WireList, ...]) -> Tuple[WireList, ...]:
return self.run(*input_wires)

def __str__(self):
Expand Down
8 changes: 6 additions & 2 deletions tests/leakage_gadget_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import cast

from pytket import Circuit
from pytket.extensions.quantinuum.backends.leakage_gadget import (
prune_shots_detected_as_leaky,
Expand Down Expand Up @@ -69,13 +71,15 @@ def test_compare_with_prune() -> None:
),
n_shots=detection_circuit_shots.Shots,
)
for detection_circuit_shots in detection_circuit_shots_list
for detection_circuit_shots in cast(
list[CircuitShots], detection_circuit_shots_list
)
]

qermit_result_list = postselection_task(
(
result_list,
postselect_mgr_list,
postselect_mgr_list, # type: ignore
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is required since PostselectMgr, is not a recognised wire type. Simply adding it to the list of recognised wire types induces cyclic imports.

I don't really know what the right solution to this is...

I assume there must be a way to define a type annotation for PostselectMgr within mittask.py although I have tried and failed to do that. User defined generic types might also help -> https://docs.python.org/3/library/typing.html#user-defined-generic-types but I think that only works for python 3.12. If you happen to know how to do something like that then I would be very interested to know about that.

Another solution is to move serialised versions of PostselectMgr along wires. As far as I can tell that is the best solution, but would be some significant work.

Another solution would be to allow Any as a wire type, which I don't want to do...

)
)
pytket_result_list = [
Expand Down
Loading