Skip to content

Conversation

@mudit2812
Copy link
Contributor

@mudit2812 mudit2812 commented Nov 19, 2025

Duplicate of PennyLaneAI/pennylane#8638

Methods available through the PLPatternRewriter class:

  • All methods available through xDSL's PatternRewriter
  • get_qnode: Given a starting point, finds the QNode module (or function) containing that operation, if it exists.
  • get_qreg: Given an insertion point, finds the latest quantum register, if it exists.
  • get_idx_from_qubit: Given a qubit, get the index into the quantum register that it corresponds to.
  • get_active_qubits: Given an insertion point, return a bidirectional map between all live qubits and their corresponding indices.
  • insert_active_qubits: Given an insertion point, insert all active qubits into the latest quantum register. The active qubit map and the latest quantum register can optionally be given as arguments, if known.
  • insert_constant: Insert a scalar constant into the IR and return it.
  • get_num_qubits: Given an insertion point, get an SSA value corresponding to the number of currently allocated qubits.
  • get_num_shots: Get the number of shots as an SSA value. If requested, and the number of shots is static, can be returned as a Python int
  • erase_gate: Erase the provided quantum gate operation
  • insert_mid_measure: Insert a PennyLane mid-circuit measurement at the given insertion point. Postselection and reset are supported. The wire must be an SSA qubit.
    • Nice to have TODO: Add support for parametrized MCMs
  • insert_gate: Insert a quantum gate at the given insertion point. If parameters are SSA values already in the IR, they can be provided. Otherwise, the static parameters of the gate will be inserted as constants into the IR. Wires must be SSA qubits.
  • insert_observable: Insert a PennyLane observable at the given insertion point. If parameters are SSA values already in the IR, they can be provided. Otherwise, the static parameters of the observable will be inserted as constants into the IR. Wires must be SSA qubits.
  • insert_measurement: Insert a PennyLane measurement process at the given insertion point. If parameters are SSA values already in the IR, they can be provided. Otherwise, the static parameters of the measurement process will be inserted as constants into the IR. Wires must be SSA qubits.
  • swap_gates: (TODO) Swap two provided gate operations. There must be at least one overlapping wire between the gates, but not all wires need to overlap.

Note:
Everything is untested 😅 . If anyone would like to test out the prototype and something doesn't work, please let me know.

[sc-103609]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

unified compiler Pull requests for the integration with xDSL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants