-
Notifications
You must be signed in to change notification settings - Fork 47
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
Open
ritu-thombre99
wants to merge
35
commits into
main
Choose a base branch
from
ritu/ppm_specs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+626
−2
Open
Implement ppm_specs
pass
#1794
Changes from 21 commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
eacfe86
test new print spec pass
ritu-thombre99 24e0afd
fix some descriptions
ritu-thombre99 ca994e4
fix passes.td file
ritu-thombre99 54c2460
4 stats recorded
ritu-thombre99 1f6ac67
implement ppm_spec logic
ritu-thombre99 ba5fb0c
slicing working
ritu-thombre99 940a16a
revert ppm_compilation
ritu-thombre99 dca7989
working in frontend
ritu-thombre99 09512cf
format and comment
ritu-thombre99 2b53308
track with main
ritu-thombre99 aa16ead
check if opt contains json
ritu-thombre99 ef174bf
resolve PR comments
ritu-thombre99 3304c10
fix formatting
ritu-thombre99 726237a
track with main
ritu-thombre99 ddc30f1
check nullptr for num_qubit
ritu-thombre99 eeffd55
move get_ppm_spec() API function out of jit.py and compiler.py; remov…
paul0403 bc4efce
remove ppm_specs from unnecessary places
ritu-thombre99 2dc9fc2
code cleanup
ritu-thombre99 f17706a
assert dynamic qubit count
ritu-thombre99 05ef5c3
formatting
ritu-thombre99 c1d5322
track with main
ritu-thombre99 f72df33
resolve some PR comments
ritu-thombre99 19900c7
check op type instead of name:
ritu-thombre99 d88e70f
Merge branch 'main' into ritu/ppm_specs
ritu-thombre99 34aa5ff
separate count functions
ritu-thombre99 ecae329
remove snake_case
ritu-thombre99 1260335
add frontend pytests
ritu-thombre99 641a416
formatting changes
ritu-thombre99 341e75b
fix pytests
ritu-thombre99 29d5b74
mlir test
ritu-thombre99 b596d18
update with main
ritu-thombre99 04e914e
mlir test with ppm specs
ritu-thombre99 e4c17b9
fix asserts
ritu-thombre99 a2265be
lit tests
ritu-thombre99 b282b0b
lit tests
ritu-thombre99 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
// Copyright 2025 Xanadu Quantum Technologies Inc. | ||
|
||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
|
||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#define DEBUG_TYPE "ppm_specs" | ||
|
||
#include <algorithm> | ||
sengthai marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#include <string> | ||
|
||
#include <nlohmann/json.hpp> | ||
|
||
#include "mlir/IR/PatternMatch.h" | ||
#include "mlir/Pass/Pass.h" | ||
|
||
#include "QEC/IR/QECDialect.h" | ||
#include "Quantum/IR/QuantumOps.h" | ||
|
||
using namespace llvm; | ||
using namespace mlir; | ||
using namespace catalyst; | ||
using namespace catalyst::qec; | ||
using json = nlohmann::json; | ||
|
||
namespace catalyst { | ||
namespace qec { | ||
|
||
#define GEN_PASS_DEF_COUNTPPMSPECSPASS | ||
#define GEN_PASS_DECL_COUNTPPMSPECSPASS | ||
#include "QEC/Transforms/Passes.h.inc" | ||
|
||
struct CountPPMSpecsPass : public impl::CountPPMSpecsPassBase<CountPPMSpecsPass> { | ||
ritu-thombre99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
using CountPPMSpecsPassBase::CountPPMSpecsPassBase; | ||
|
||
void print_specs() | ||
ritu-thombre99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
llvm::BumpPtrAllocator string_allocator; | ||
llvm::DenseMap<StringRef, int> PPM_Specs; | ||
PPM_Specs["num_logical_qubits"] = 0; | ||
PPM_Specs["num_of_ppm"] = 0; | ||
|
||
// Walk over all operations in the IR (could be ModuleOp or FuncOp) | ||
getOperation()->walk([&](Operation *op) { | ||
// Skip top-level container ops if desired | ||
if (isa<ModuleOp>(op)) | ||
return; | ||
|
||
StringRef gate_name = op->getName().getStringRef(); | ||
|
||
if (gate_name == "quantum.alloc") { | ||
ritu-thombre99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
uint64_t num_qubits = cast<quantum::AllocOp>(op).getNqubitsAttr().value_or(0); | ||
assert(num_qubits != 0 && | ||
"PPM specs with dynamic number of qubits is not implemented"); | ||
PPM_Specs["num_logical_qubits"] = num_qubits; | ||
} | ||
ritu-thombre99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if (gate_name == "qec.ppm") { | ||
PPM_Specs["num_of_ppm"]++; | ||
} | ||
|
||
if (gate_name == "qec.ppr") { | ||
auto rotation_attr = op->getAttrOfType<mlir::IntegerAttr>("rotation_kind"); | ||
auto pauli_product_attr = op->getAttrOfType<mlir::ArrayAttr>("pauli_product"); | ||
int16_t rotation_kind = | ||
rotation_attr ? static_cast<int16_t>(rotation_attr.getInt()) : 0; | ||
if (rotation_kind) { | ||
ritu-thombre99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
llvm::StringSaver saver(string_allocator); | ||
StringRef num_pi_key = | ||
saver.save("num_pi" + std::to_string(abs(rotation_kind)) + "_gates"); | ||
StringRef max_weight_pi_key = | ||
saver.save("max_weight_pi" + std::to_string(abs(rotation_kind))); | ||
|
||
if (PPM_Specs.find(llvm::StringRef(num_pi_key)) == PPM_Specs.end()) { | ||
PPM_Specs[num_pi_key] = 1; | ||
PPM_Specs[max_weight_pi_key] = static_cast<int>(pauli_product_attr.size()); | ||
} | ||
else { | ||
PPM_Specs[num_pi_key]++; | ||
PPM_Specs[max_weight_pi_key] = | ||
std::max(PPM_Specs[max_weight_pi_key], | ||
static_cast<int>(pauli_product_attr.size())); | ||
} | ||
} | ||
} | ||
}); | ||
|
||
json PPM_Specs_Json = PPM_Specs; | ||
paul0403 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
llvm::outs() << PPM_Specs_Json.dump(4) << "\n"; | ||
ritu-thombre99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return; | ||
} | ||
|
||
void runOnOperation() final { print_specs(); } | ||
}; | ||
|
||
} // namespace qec | ||
|
||
/// Create a pass for lowering operations in the `QECDialect`. | ||
std::unique_ptr<Pass> createCountPPMSpecsPass() { return std::make_unique<CountPPMSpecsPass>(); } | ||
|
||
} // namespace catalyst |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.