Skip to content
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

Can empty kernels be stripped during translation to OpenQASM 2? #2220

Open
kshyatt-aws opened this issue Sep 19, 2024 · 0 comments
Open

Can empty kernels be stripped during translation to OpenQASM 2? #2220

kshyatt-aws opened this issue Sep 19, 2024 · 0 comments

Comments

@kshyatt-aws
Copy link

CUDA-QUANTUM version: 0.8.0
OS: Amazon Linux 2023 x86_64

Looking the basic C++ GHZ script:

#include <cudaq.h>

template <std::size_t N>
struct ghz {
  auto operator()() __qpu__ {
    cudaq::qarray<N> q;
    h(q[0]);
    for (int i = 0; i < N - 1; i++) {
      x<cudaq::ctrl>(q[i], q[i + 1]);
    }
    mz(q);
  }
};

int main() {

  auto kernel = ghz<10>{};
  auto counts = cudaq::sample(kernel);

  if (!cudaq::mpi::is_initialized() || cudaq::mpi::rank() == 0) {
    counts.dump();

    // Fine grain access to the bits and counts
    for (auto &[bits, count] : counts) {
      printf("Observed: %s, %lu\n", bits.data(), count);
    }
  }

  return 0;
}

When I try to compile and translate this to OQ2 using:

cudaq-quake ghz.cpp | cudaq-opt --pass-pipeline="builtin.module(canonicalize,lambda-lifting,apply-op-specialization,func.func(memtoreg{quantum=0}),cc-loop-normalize,cc-loop-unroll)"  | cudaq-translate --convert-to=openqasm2 &> ghz.qasm

Here's the output qasm file:

// Code generated by NVIDIA's nvq++ compiler
OPENQASM 2.0;

include "qelib1.inc";

gate ZN3ghzILm10EEclEv(param0)  {
}

qreg var0[10];
h var0[0];
cx var0[0], var0[1];
cx var0[1], var0[2];
cx var0[2], var0[3];
cx var0[3], var0[4];
cx var0[4], var0[5];
cx var0[5], var0[6];
cx var0[6], var0[7];
cx var0[7], var0[8];
cx var0[8], var0[9];
creg var11[10];
measure var0 -> var11;

Looks good! But is there a way to strip the extraneous

gate ZN3ghzILm10EEclEv(param0)  {
}

during the cudaq-opt step? I looked at the cudaq-opt --help output but did not see an pipeline-pass for this, if one exists.

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

No branches or pull requests

1 participant