Skip to content

Add rank validation in QMPI operations #5

@CardamaS99

Description

@CardamaS99

Description

Files: communicator.py, p2p.py, collective.py

Problem

No validation is performed to check that:

  • dest_rank / src_rank is in the range [0, size)
  • rank_sender is consistent
  • The qubit list is not empty

Any out-of-range value produces cryptic NetQASM errors instead of a clear message.

Solution

Add validations at the beginning of qsend, qrecv, qscatter, qgather:

def qsend(self, qubits: List[Qubit], dest_rank: int):
    if not 0 <= dest_rank < self.size:
        raise ValueError(f"dest_rank {dest_rank} out of range [0, {self.size})")
    if dest_rank == self.rank:
        raise ValueError("Cannot send to self")
    if not qubits:
        raise ValueError("qubits list must not be empty")
    ...

Impact

  • Severity: High
  • Improvement: Clear error messages and fail-fast behavior

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions