Skip to content

[BUG] Duplicate qubits not detected in function call  #80

@TheGupta2012

Description

@TheGupta2012

Environment

  • PyQASM version: source
  • Python version: 3.12.7
  • Operating system: macOS 14.4

What happened?

The following qasm program passes unrolling -

In [1]: import pyqasm

In [2]: qasm_str = """
   ...: OPENQASM 3.0;
   ...: include "stdgates.inc";
   ...:
   ...: qubit[2] q;
   ...:
   ...: def custom_fn( qubit q1, qubit q2, qubit q3) -> bool {
   ...:    h q1;
   ...:    h q2;
   ...:    h q3;
   ...:    return true;
   ...: }
   ...:
   ...: bool result = custom_fn(q[0], q[1], q[1]);
   ...: """

In [3]: mod = pyqasm.loads(qasm_str)

In [4]: mod.unroll()

In [5]: mod.qasm_str().splitlines()
Out[5]:
['OPENQASM 3.0;',
 'include "stdgates.inc";',
 'qubit[2] q;',
 'h q[0];',
 'h q[1];',
 'h q[1];']

but should have raised the error that we have duplicate qubit arguments present in the function call.

Suggestions (Optional)

  • The duplicate_qubit_detect_map should be updated across argument validation. Presently, it is only getting updated if a register name is not present.
  • Moreover, the validate_unique_qubits should have a more descriptive doc and moved to the Qasm3SubroutineProcessor because it is referred only inside the process_quantum_arg method

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingqasm3Related to openqasm3

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions