Skip to content

[FEATURE] Introduce unroll Command in PyQASM CLI #189

@TheGupta2012

Description

@TheGupta2012

Description

  • Add an unroll command to the PyQASM CLI, similar to the behavior and interface of the existing validate command.
  • The new command will accept either a directory or a single QASM file as input. It will unroll each file using PyQASM's unroll functionality, with options to either overwrite the original files or create new ones with an _unrolled suffix.
  • For each file processed, the CLI will report whether the unrolling was successful or if an error occurred.

Details

  • Input: Single file or directory containing .qasm files.
  • Overwrite Option: By default, files are not overwritten. If --overwrite is specified, the original files are updated in-place.
  • Output Naming: If not overwriting, output files are named /path/to/file/<<file_name>>_unrolled.qasm.
  • Result Reporting: For each file, print a message indicating success or failure of the unroll operation.

Implementation

  • Command Registration: Add an unroll subcommand to the CLI in main.py.
  • Input Handling: Accept a file or directory path as the main argument.
    • If a directory is given, process all .qasm files in the directory (non-recursively, unless otherwise specified).
  • Unroll Logic: For each file:
    • Attempt to unroll using PyQASM's unroll functionality.
    • If successful:
      • If --overwrite is set, write the result to the original file.
      • If not, write to a new file with _unrolled appended to the base name.
    • If unsuccessful, print an error message for that file.
  • Result Reporting: Print a summary line for each erroneous file:
    • Example: Successfully unrolled 3 files or Failed to unroll: example.qasm (error details)
  • CLI Options:
    • --overwrite (default: False)
    • --help for usage info

Example Usage

# Unroll a single file, output to 'example_unrolled.qasm'
pyqasm unroll example.qasm

# Unroll all .qasm files in a directory, outputting new files with '_unrolled' suffix
pyqasm unroll ./qasm_files/

# Overwrite the original files after unrolling
pyqasm unroll ./qasm_files/ --overwrite

NOTE: The unroll command should handle invalid QASM files gracefully, reporting errors but continuing to process other files in batch mode.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requestllm-assistedUsed LLMs to fine tune issue description.no-qc-knowledge-reqdDoes not require knowledge of QC or QIS

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions