Commit 8ecdd0cf authored by Nguyen, Thien Minh's avatar Nguyen, Thien Minh
Browse files

Added qir array and tuple stubs



Signed-off-by: default avatarThien Nguyen <nguyentm@ornl.gov>
parent 1a34e7e6
Loading
Loading
Loading
Loading
+28 −0
Original line number Diff line number Diff line
#include <iostream> 
#include <vector>
#include "qcor.hpp"

// Include the external QSharp function.
qcor_include_qsharp(XACC__Ansatz__body, void, Array*, Array*)


// Compile with:
// Include both the qsharp source and this driver file 
// in the command line.
// $ qcor -qrt ftqc bell.qs bell_driver.cpp
// Run with:
// $ ./a.out
int main() {
  int64_t bit0 = 0;
  int64_t bit1 = 1;
  int64_t bit2 = 2;
  std::vector<int64_t*> qReg { &bit0, &bit1, &bit2 };
  double theta0 = 1.0;
  double theta1 = 2.0;
  double theta2 = 3.0;
  std::vector<double*> thetas { &theta0, &theta1, &theta2 };

  XACC__Ansatz__body(&qReg, &thetas);
  std::cout << "HOWDY\n";
  return 0;
}
 No newline at end of file
+18 −0
Original line number Diff line number Diff line
namespace XACC 
{
open Microsoft.Quantum.Intrinsic;
operation Ansatz(qubits : Qubit[], angles : Double[]) : Unit {
    for qubit in qubits {
        H(qubit);
    }

    for index in 0 .. Length(qubits) - 1 {
        Rx(angles[index], qubits[index]);
    }
    
    mutable results = new (Int, Result)[Length(qubits)];
    for index in 0 .. Length(qubits) - 1 {
        set results += [(index-1, M(qubits[index]))];
    }
}
}
 No newline at end of file
+96 −0
Original line number Diff line number Diff line
#include "qir-qrt.hpp"
#include <iostream>

extern "C" {
Array *__quantum__rt__array_create_1d(int32_t itemSizeInBytes,
                                      int64_t count_items) {
  // TODO
  if (verbose)
    std::cout << "CALL: " << __PRETTY_FUNCTION__ << "\n";

  return nullptr;
}

void __quantum__rt__array_update_reference_count(Array *array,
                                                 int32_t increment) {
  // TODO
  if (verbose)
    std::cout << "CALL: " << __PRETTY_FUNCTION__ << "\n";
}

void __quantum__rt__array_update_alias_count(Array *array, int32_t increment) {
  // TODO
  if (verbose)
    std::cout << "CALL: " << __PRETTY_FUNCTION__ << "\n";
}

// Returns the number of dimensions in the array.
int32_t __quantum__rt__array_get_dim(Array *array) {
  if (verbose)
    std::cout << "CALL: " << __PRETTY_FUNCTION__ << "\n";
  return 0;
}

int64_t __quantum__rt__array_get_size(Array *array, int32_t dim) {
  if (verbose)
    std::cout << "CALL: " << __PRETTY_FUNCTION__ << "\n";
  return 0;
}

Array *__quantum__rt__array_copy(Array *array, bool forceNewInstance) {
  if (verbose)
    std::cout << "CALL: " << __PRETTY_FUNCTION__ << "\n";
  return nullptr;
}

Array *__quantum__rt__array_concatenate(Array *head, Array *tail) {
  if (verbose)
    std::cout << "CALL: " << __PRETTY_FUNCTION__ << "\n";
  return nullptr;
}

// Creates a new array. The first int is the size of each element in bytes. The
// second int is the dimension count. The variable arguments should be a
// sequence of int64_ts contains the length of each dimension. The bytes of the
// new array should be set to zero.
Array *__quantum__rt__array_create_nonvariadic(int itemSizeInBytes,
                                               int countDimensions,
                                               va_list dims) {
  if (verbose)
    std::cout << "CALL: " << __PRETTY_FUNCTION__ << "\n";
  return nullptr;
}

Array *__quantum__rt__array_create(int itemSizeInBytes, int countDimensions,
                                   ...) {
  if (verbose)
    std::cout << "CALL: " << __PRETTY_FUNCTION__ << "\n";
  return nullptr;
}

int8_t *__quantum__rt__array_get_element_ptr_nonvariadic(Array *array,
                                                         va_list args) {
  if (verbose)
    std::cout << "CALL: " << __PRETTY_FUNCTION__ << "\n";
  return nullptr;
}

// Returns a pointer to the indicated element of the array. The variable
// arguments should be a sequence of int64_ts that are the indices for each
// dimension.
int8_t *__quantum__rt__array_get_element_ptr(Array *array, ...) {
  if (verbose)
    std::cout << "CALL: " << __PRETTY_FUNCTION__ << "\n";
  return nullptr;
}

// Creates and returns an array that is a projection of an existing array. The
// int indicates which dimension the projection is on, and the int64_t specifies
// the specific index value to project. The returned Array* will have one fewer
// dimension than the existing array.
Array *__quantum__rt__array_project(Array *array, int dim, int64_t index) {
  if (verbose)
    std::cout << "CALL: " << __PRETTY_FUNCTION__ << "\n";
  return nullptr;
}
}
 No newline at end of file
+30 −0
Original line number Diff line number Diff line
#include "qir-qrt.hpp"
#include <iostream>

extern "C" {
int8_t *__quantum__rt__tuple_create(int64_t size) {
  if (verbose)
    std::cout << "CALL: " << __PRETTY_FUNCTION__ << "\n";
  // Leak..
  Array *tuplePtrArray = new Array(size);
  return reinterpret_cast<int8_t *>(tuplePtrArray);
}

void __quantum__rt__tuple_update_reference_count(int8_t *tuple,
                                                 int32_t increment) {
  if (verbose)
    std::cout << "CALL: " << __PRETTY_FUNCTION__ << "\n";
}

void __quantum__rt__tuple_update_alias_count(int8_t *tuple, int32_t increment) {
  if (verbose)
    std::cout << "CALL: " << __PRETTY_FUNCTION__ << "\n";
}

int8_t *__quantum__rt__tuple_copy(int8_t *tuple, bool forceNewInstance) {
  if (verbose)
    std::cout << "CALL: " << __PRETTY_FUNCTION__ << "\n";

  return nullptr;
}
}
 No newline at end of file