Skip to content

Commit

Permalink
Add MergeCircuitMeasuresPass and RemoveUnusedCircuitsPass (openqasm#255)
Browse files Browse the repository at this point in the history
Adds a MergeCircuitMeasuresPass to merge quir.measures inside
circuits. Based on `MergeMeasuresTopologicalPass`.

Adds a RemoveUnusedCircuitsPass to clean up unused circuits and reduce the number of operations in a module.
  • Loading branch information
bcdonovan authored Feb 14, 2024
1 parent fcf0ffd commit f816647
Show file tree
Hide file tree
Showing 12 changed files with 864 additions and 0 deletions.
42 changes: 42 additions & 0 deletions include/Dialect/QUIR/Transforms/MergeCircuitMeasures.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//===- MergeCircuitMeasures.h - Merge measurement ops in circuits - C++ -*-===//
//
// (C) Copyright IBM 2024.
//
// This code is part of Qiskit.
//
// This code is licensed under the Apache License, Version 2.0 with LLVM
// Exceptions. You may obtain a copy of this license in the LICENSE.txt
// file in the root directory of this source tree.
//
// Any modifications or derivative works of this code must retain this
// copyright notice, and modified files need to carry a notice indicating
// that they have been altered from the originals.
//
//===----------------------------------------------------------------------===//
///
/// This file declares the pass for merging measurements inside circuits into a
/// single measure op
///
//===----------------------------------------------------------------------===//

#ifndef QUIR_MERGE_CIRCUIT_MEASURES_H
#define QUIR_MERGE_CIRCUIT_MEASURES_H

#include "mlir/Pass/Pass.h"

namespace mlir::quir {

/// @brief Merge together measures in a circuit that are topologically
/// adjacent into a single variadic measurement.
struct MergeCircuitMeasuresTopologicalPass
: public PassWrapper<MergeCircuitMeasuresTopologicalPass, OperationPass<>> {
void runOnOperation() override;

llvm::StringRef getArgument() const override;
llvm::StringRef getDescription() const override;
llvm::StringRef getName() const override;
}; // struct MergeCircuitMeasuresTopologicalPass

} // namespace mlir::quir

#endif // QUIR_MERGE_CIRCUIT_MEASURES_H
2 changes: 2 additions & 0 deletions include/Dialect/QUIR/Transforms/Passes.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@
#include "ConvertDurationUnits.h"
#include "FunctionArgumentSpecialization.h"
#include "LoadElimination.h"
#include "MergeCircuitMeasures.h"
#include "MergeCircuits.h"
#include "MergeMeasures.h"
#include "MergeParallelResets.h"
#include "QuantumDecoration.h"
#include "RemoveQubitOperands.h"
#include "RemoveUnusedCircuits.h"
#include "ReorderCircuits.h"
#include "ReorderMeasurements.h"
#include "SubroutineCloning.h"
Expand Down
41 changes: 41 additions & 0 deletions include/Dialect/QUIR/Transforms/RemoveUnusedCircuits.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//===- RemoveUnusedCircuits.h - Remove Unused Circuits ----------- C++ -*-===//
//
// (C) Copyright IBM 2024.
//
// This code is part of Qiskit.
//
// This code is licensed under the Apache License, Version 2.0 with LLVM
// Exceptions. You may obtain a copy of this license in the LICENSE.txt
// file in the root directory of this source tree.
//
// Any modifications or derivative works of this code must retain this
// copyright notice, and modified files need to carry a notice indicating
// that they have been altered from the originals.
//
//===----------------------------------------------------------------------===//
///
/// This file declares the pass for removing unused circuits.
///
//===----------------------------------------------------------------------===//

#ifndef QUIR_REMOVE_UNUSED_CIRCUITS_H
#define QUIR_REMOVE_UNUSED_CIRCUITS_H

#include "mlir/Pass/Pass.h"

namespace mlir::quir {

/// @brief Merge together measures in a circuit that are topologically
/// adjacent into a single variadic measurement.
struct RemoveUnusedCircuitsPass
: public PassWrapper<RemoveUnusedCircuitsPass, OperationPass<>> {
void runOnOperation() override;

llvm::StringRef getArgument() const override;
llvm::StringRef getDescription() const override;
llvm::StringRef getName() const override;
}; // struct RemoveUnusedCircuits

} // namespace mlir::quir

#endif // QUIR_REMOVE_UNUSED_CIRCUITS_H
2 changes: 2 additions & 0 deletions lib/Dialect/QUIR/Transforms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ add_mlir_dialect_library(MLIRQUIRTransforms
FunctionArgumentSpecialization.cpp
LoadElimination.cpp
MergeCircuits.cpp
MergeCircuitMeasures.cpp
MergeMeasures.cpp
MergeParallelResets.cpp
Passes.cpp
QuantumDecoration.cpp
QUIRCircuitAnalysis.cpp
RemoveQubitOperands.cpp
RemoveUnusedCircuits.cpp
ReorderMeasurements.cpp
ReorderCircuits.cpp
SubroutineCloning.cpp
Expand Down
Loading

0 comments on commit f816647

Please sign in to comment.