Skip to content

Add a \sites\ subcommand (list non-identity site positions) #8

Description

@landau774

Background

qsym-rs is a deliberately small symbolic Pauli-algebra engine and \qsym\ CLI (see \docs/design/qsym-rs.md). Its \PauliString\ (\src/lib.rs) already has \weight() -> usize\ (count of non-\I\ sites) and the \show\ subcommand displays \len\ and \weight\ as metadata. However, there is currently no way to ask which qubits a Pauli string acts on — i.e., the indices of its non-identity sites. This information is directly useful for identifying the support of an operator, e.g. when checking whether two operators act on disjoint qubit sets.

Task

Add a \sites() -> Vec\ method to \PauliString\ in \src/lib.rs\ that returns the 1-indexed positions of all non-\I\ sites. Then add a \sites\ subcommand to the \qsym\ CLI: \qsym sites . It must print the non-identity site positions as a comma-separated list on a single line, or print nothing (empty stdout) if the Pauli string is all identity.

Only \src/lib.rs\ and \src/main.rs\ change. Do not change any existing subcommands or signatures.

Verification

Run each command with \cargo run -q --\ (the crate's only binary), trimming trailing newlines before comparing stdout:

  1. \cargo run -q -- sites XIZ\ — stdout is exactly \1, 3, exit code \

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions