Skip to content

Add argument parsing [unitaryHACK]

Created by: amirebrahimi

Resolves #123 (closed)

I'm not that familiar with cmake, but I tried to match as much of the convention that XACC uses with third party libraries.

There are two ways this can be used:

Explicitly

__qpu__ void f(qreg q) {
  H(q);
  Measure(q);
}

int main(int argc, char** argv) {
    ArgumentParser program(argv[0]);

    program.add_argument("n-qubits")
            .default_value(1)
            .action([](const std::string& value) { return std::stoi(value); });
    program.parse_args(argc, argv);
    auto N = program.get<int>("n-qubits");

    auto q = qalloc(N);
    f(q);
    q.print();
}

Implicitly

__qpu__ void f(qreg q) {
  H(q);
  Measure(q);
}

int main(int argc, char** argv) {
    using namespace qcor::arg;

    add_argument("n-qubits")
        .default_value(1)
        .action([](const std::string& value) { return std::stoi(value); });
    parse_args(argc, argv);
    auto N = get_argument<int>("n-qubits");

    auto q = qalloc(N);
    f(q);
    q.print();
}

I thought it was better to expose the ArgumentParser through the qcor namespace, so that the program name and version number could be specified. If you would rather this be hidden behind static function calls w/ a global, then let me know and I can rework this a little bit.

Merge request reports

Loading