Skip to content

Remove empty arg gates

RemoveEmptyArgOps dataclass

RemoveEmptyArgOps(call_graph: CallGraph, callee: Method)

Bases: RewriteRule


              flowchart TD
              bloqade.rewrite.rules.remove_empty_arg_gates.RemoveEmptyArgOps[RemoveEmptyArgOps]

              

              click bloqade.rewrite.rules.remove_empty_arg_gates.RemoveEmptyArgOps href "" "bloqade.rewrite.rules.remove_empty_arg_gates.RemoveEmptyArgOps"
            

Remove squin gates, noise channels, and measurements on empty qubit lists.

rewrite_Statement

rewrite_Statement(node: Statement) -> RewriteResult

Delete quantum statements whose qubit arguments are compile-time empty.

Source code in .venv/lib/python3.12/site-packages/bloqade/rewrite/rules/remove_empty_arg_gates.py
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
def rewrite_Statement(self, node: ir.Statement) -> RewriteResult:
    """Delete quantum statements whose qubit arguments are compile-time empty."""
    if not isinstance(node, QuantumOperation):
        return RewriteResult()

    qubit_arg_values = _qubit_args(node)
    if not qubit_arg_values or not all(
        _is_empty_ilist_value(arg, call_graph=self.call_graph, callee=self.callee)
        for arg in qubit_arg_values
    ):
        return RewriteResult()

    if isinstance(node, qubit.stmts.Measure):
        for result in node.results:
            if not result.uses:
                continue
            empty = ilist.New((), elem_type=MeasurementResultType)
            empty.insert_before(node)
            result.replace_by(empty.result)

    node.delete()
    return RewriteResult(has_done_something=True)