Skip to content

Warning instead of ValidationError for creg size = 0 #179

@ryanhill1

Description

@ryanhill1

Currently, a program that includes a creg declaration with size 0 raises a ValidationError. The creg of size 0 is a convention used by pyqpanda3, which we are currently trying to integrate into the qBraid-SDK transpiler (qBraid/qBraid#963). However, the ValidationError demonstrated below is causing errors in testing, see comment.

import pyqpanda3

program = pyqpanda3.core.QProg()
program << pyqpanda3.core.RX(0, 3.1415926) << pyqpanda3.core.CNOT(0, 2)

qasm = pyqpanda3.intermediate_compiler.convert_qprog_to_qasm(program)

print(qasm)
OPENQASM 2.0;
include "qelib1.inc";
qreg q[3];
creg c[0];
rx(3.14159260) q[0];
cx q[0],q[2];
import pyqasm

module = pyqasm.loads(qasm)
ValidationError: Failed to parse OpenQASM string: L4:C6: creg size must be positive

I think we should instead just emit a warning if creg size = 0, but still raise a ValidationError if creg size < 0. If creg size is set to 0, and no further creg operations exist in the program, I think the program should still be considered "valid", but we should emit a warning and recommend that instead of declaring a creg of size 0, they should just omit the creg declaration.

Obviously, if creg size is set to 0 and the program also contains a measurement operation, for example, that should still warrant a ValidationError.

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