Writing Passes for the MQSS

Adding your pass

  • Two types of passes can be added : Dialect-Agnostic and Dialect-specific

  • The dialect agnostic passes should be added within lib/common/Passes, whereas, dialect-specific passes should be added within lib/mqss-catalyst/lib/MQSSCatalystPasses (for catalyst-quantum) and lib/mqss-cudaq/lib/MQSSQuakePasses (for quake).

  • A key step in adding your pass is pass registration. This ensures that the passes can be found by the targets mqss-cudaq-opt and ``````mqss-catalyst-opt```.

    1. To register a pass we need to make additions to 2 files Transforms.h and Transforms.td. These files can be found within lib/mqss-catalyst/include/MQSSCatalystPasses and lib/mqss-cudaq/include/MQSSQuakePasses.

    2. Here is an example of pass registration within lib/mqss-cudaq/include/MQSSQuakePasses/Transforms.td:

      def CommonNormalizeArgAnglePass : Pass<"CommonNormalizeArgAnglePass", "mlir::ModuleOp"> {
        let summary = "Normalize Arg angle of RX, RY, RZ gates. ";
    
        let description = [{
          Normalize Arg angle of RX, RY, RZ gates.
        }];
    
        let constructor = "mqss_cudaq::opt::CommonNormalizeArgAnglePass()";
      }
    

    The pass is registered for the mqss-cudaq-opt target. Since the pass is dialect agnostic, the same pass can be registered for the mqss-catalyst-opt target by changing the namespace mqss_cudaq::opt to mqss_catalyst::opt within the constructor. 3. In Transforms.h within the mqss_cudaq::opt and mqss_catalyst::opt namespaces, the following should be added:

       std::unique_ptr<mlir::Pass> CommonNormalizeArgAnglePass();
    

Pass Structure

Adding a Dialect