Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Kartik Singhal <[email protected]>
  • Loading branch information
neal-erickson and qartik authored Oct 2, 2023
1 parent e5e09f1 commit 3faaa27
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
4 changes: 2 additions & 2 deletions pytket/phir/sharding/shard.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from pytket.unit_id import Bit, Qubit, UnitID


@dataclass(unsafe_hash=False)
@dataclass
class Shard:
"""
A shard is a logical grouping of operations that represents the unit by which
Expand Down Expand Up @@ -47,7 +47,7 @@ def __post_init__(self) -> None:
for sub_command in all_sub_commands:
self.bits_written.update(sub_command.bits)
self.bits_read.update(
set(filter(lambda x: isinstance(x, Bit), sub_command.args)), # type: ignore # noqa: PGH003
set(filter(lambda x: isinstance(x, Bit), sub_command.args)), # type: ignore [misc,arg-type] # noqa: E501
)

def pretty_print(self) -> str:
Expand Down
13 changes: 5 additions & 8 deletions pytket/phir/sharding/sharder.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ def _build_shard(self, command: Command) -> None:
# Handle dependency calculations
depends_upon: set[int] = set()
for shard in self._shards:
# Check qubit dependencies (R/W implicitly) since all commands on a given qubit
# need to be ordered as the circuit dictated
# Check qubit dependencies (R/W implicitly) since all commands
# on a given qubit need to be ordered as the circuit dictated
if not shard.qubits_used.isdisjoint(command.qubits):
depends_upon.add(shard.ID)
# Check classical dependencies, which depend on writing and reading
Expand All @@ -83,7 +83,7 @@ def _cleanup_remaining_commands(self) -> None:
Checks for any remaining "unsharded" commands, and if found, adds them
to Barrier op shards for each qubit
"""
remaining_qubits = [k for k, v in self._pending_commands.items() if len(v) > 0]
remaining_qubits = [k for k, v in self._pending_commands.items() if v]
for qubit in remaining_qubits:
self._circuit.add_barrier([qubit])
# Easiest way to get to a command, since there's no constructor. Could
Expand All @@ -110,9 +110,6 @@ def should_op_create_shard(op: Op) -> bool:
This includes non-gate operations like measure/reset as well as 2-qubit gates.
TODO: This is almost certainly inadequate right now
"""
return (
op.type == OpType.Measure
or op.type == OpType.Reset
or op.type == OpType.Barrier
or (op.is_gate() and op.n_qubits > 1)
return op.type in (OpType.Measure, OpType.Reset, OpType.Barrier) or (
op.is_gate() and op.n_qubits > 1
)
2 changes: 1 addition & 1 deletion tests/test_shard.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_shard_ctor_conditional(self) -> None:
circuit = Circuit(4, 4)
circuit.H(0)
circuit.Measure(0, 0)
circuit.X(1, condition_bits=[0], condition_value=1) # type: ignore # noqa: PGH003
circuit.X(1, condition_bits=[0], condition_value=1) # type: ignore [misc]
circuit.Measure(1, 1) # The command we'll build the shard from
commands = circuit.get_commands()

Expand Down

0 comments on commit 3faaa27

Please sign in to comment.