Description
Description
- Add an
unroll
command to the PyQASM CLI, similar to the behavior and interface of the existingvalidate
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 inmain.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).
- If a directory is given, process all
- 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
- If unsuccessful, print an error message for that file.
- Attempt to unroll using PyQASM's
- Result Reporting: Print a summary line for each erroneous file:
- Example:
Successfully unrolled 3 files
orFailed to unroll: example.qasm (error details)
- Example:
- 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.