Skip to content

Implement ppm_specs pass #1794

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 24 commits into
base: main
Choose a base branch
from
Draft

Implement ppm_specs pass #1794

wants to merge 24 commits into from

Conversation

ritu-thombre99
Copy link
Member

@ritu-thombre99 ritu-thombre99 commented Jun 6, 2025

Context:

Description of the Change: Count the following PPR/PPM specs after qec transformation and print it using pass ppm_specs (with function circuit.get_ppm_spec() in python frontend) or --ppm_specs in the Catalyst CLI

  • Max weight for pi/8 PPRs.
  • Max weight for pi/4 PPRs.
  • Max weight for pi/2 PPRs.
  • Number of logical qubits.
  • Number of PPMs.
  • Number of logical qubits

Benefits: Useful for resource estimation

Possible Drawbacks:
Running Catalyst CLI with --ppm_specs will output both MLIR output and ppm_specs.

Related GitHub Issues:

TODO

  1. Add the following specs for PPR:
  • Pi/4 PPR depth (count the number of clifford PPRs)
  • Pi/8 PPR depth (count the number of non-clifford PPRs)
  • Pi/2 PPR depth (count the number of classical PPRs)
  1. Add lit-tests and pytests
  2. Update docstrings
  3. Update changelog

Example:

import pennylane as qml
from catalyst import qjit, measure
from catalyst.passes import ppm_compilation, get_ppm_spec

pipeline = [("pipe", ["enforce-runtime-invariants-pipeline"])]
method = "clifford-corrected"

@qjit(pipelines=pipeline, target="mlir")

@ppm_compilation
@qml.qnode(qml.device("lightning.qubit", wires=4))
def circuit():
    qml.T(0)
    qml.CNOT([0, 1])
    qml.Z(3)
    qml.CNOT([1, 0])
    qml.adjoint(qml.T)(0)
    qml.X(4)
    qml.T(5)
    return measure(0), measure(1),

print(get_ppm_spec(circuit))   

Prints the following output:

{
    "max_weight_pi2": 1,
    "num_logical_qubits": 4,
    "num_of_ppm": 8,
    "num_pi2_gates": 2
}

[sc-92003]

@ritu-thombre99 ritu-thombre99 requested a review from a team June 6, 2025 22:49
Copy link
Contributor

github-actions bot commented Jun 6, 2025

Hello. You may have forgotten to update the changelog!
Please edit doc/releases/changelog-dev.md on your branch with:

  • A one-to-two sentence description of the change. You may include a small working example for new features.
  • A link back to this PR.
  • Your name (or GitHub username) in the contributors section.

@ritu-thombre99 ritu-thombre99 changed the title Ritu/ppm specs Implement ppm_specs pass Jun 6, 2025
Copy link
Contributor

@dime10 dime10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @ritu-thombre99

@ritu-thombre99 ritu-thombre99 marked this pull request as draft June 11, 2025 15:13
Copy link
Contributor

@sengthai sengthai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice works, @ritu-thombre99! I left some comments here. Thanks for PR.

struct CountPPMSpecsPass : public impl::CountPPMSpecsPassBase<CountPPMSpecsPass> {
using CountPPMSpecsPassBase::CountPPMSpecsPassBase;

void print_specs()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function works; however, I would recommend breaking it into functions. Example: countPPM(op), countPPR(op), countLogicalQubit(op).

#define GEN_PASS_DECL_COUNTPPMSPECSPASS
#include "QEC/Transforms/Passes.h.inc"

struct CountPPMSpecsPass : public impl::CountPPMSpecsPassBase<CountPPMSpecsPass> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you change the variable name using CamelCase, as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants