MS gate validation error handling

Open Beginner friendly
#115 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
65/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
python
Domain
compilers

Research direction

The traceback points to the loop in the validation code that calls gate_function(*targets) near line 666, and to ms_gate(), which fails on a missing qubit1 argument. Run the two-argument ms(0, 0.5) q[0], q[1]; snippet from the issue, then check the argument count against the gate's signature before the call so it raises a ValidationError naming the missing third parameter. Done when module.validate() raises that error for the snippet and the existing tests still pass.

Written by the indexing model from the issue text.

Description

enhancement error-handling program-validation

This issue is very similar in nature to https://github.com/qBraid/pyqasm/issues/109, and is indirectly related to https://github.com/qBraid/pyqasm/issues/113.

The ms currently requires 3 parameters. If you instead provide it 2 parameters, there is an uncaught TypeError:

import pyqasm

qasm = """
OPENQASM 2;
include "qelib1.inc";
qreg q[2];

ms(0, 0.5) q[0], q[1];
"""

module = pyqasm.loads(qasm)

module.validate()
...
    [665] for targets in all_targets:
--> [666]     result.extend(gate_function(*targets))
    [667] return result

TypeError: ms_gate() missing 1 required positional argument: 'qubit1'

Instead, it should raise a ValidationError and tell you that the third parameter is missing.

Dominant language
Python
Stars
29
Forks
33
Avg merge
1d 20h
Merged PRs (30d)
8

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from qBraid/pyqasm

All issues in qBraid/pyqasm

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.