Unverified Commit 63d179e1 authored by Mccaskey, Alex's avatar Mccaskey, Alex Committed by GitHub
Browse files

Merge pull request #175 from tnguyen-ornl/tnguyen/qsc-alpha-rel

Ability to select MSFT QDK version during qcor compilation
parents 536c58cc b49ef38c
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -6,6 +6,8 @@ RUN wget https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-p
    apt-get update && apt-get install -y apt-transport-https && apt-get update && apt-get install -y dotnet-sdk-3.1

# Install Q# SDK
# Add QDK-alpha source
RUN dotnet nuget add source "https://pkgs.dev.azure.com/ms-quantum-public/Microsoft Quantum (public)/_packaging/alpha/nuget/v3/index.json" -n qdk-alpha
RUN dotnet new -i Microsoft.Quantum.ProjectTemplates

# XACC and QCOR
+1 −1
Original line number Diff line number Diff line
@@ -3,7 +3,7 @@ function(add_qcor_qsharp_test test_name relative_qs_source_location relative_cpp
  NAME
    ${test_name}
  COMMAND
    bash -c "${CMAKE_BINARY_DIR}/qcor -qrt ftqc ${CMAKE_CURRENT_SOURCE_DIR}/${relative_qs_source_location} ${CMAKE_CURRENT_SOURCE_DIR}/${relative_cpp_source_location} -o ${test_name}; \
    bash -c "${CMAKE_BINARY_DIR}/qcor -qrt ftqc -qs-build-exe ${CMAKE_CURRENT_SOURCE_DIR}/${relative_qs_source_location} ${CMAKE_CURRENT_SOURCE_DIR}/${relative_cpp_source_location} -o ${test_name}; \
              ${CMAKE_CURRENT_BINARY_DIR}/${test_name}"
  )
endfunction()
+17 −45
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@ namespace QCOR
{
open Microsoft.Quantum.Intrinsic;
open Microsoft.Quantum.Convert;
open Microsoft.Quantum.Canon;

operation SWAP(q1 : Qubit, q2: Qubit) : Unit is Adj {
  CNOT(q1, q2);
@@ -9,53 +10,24 @@ operation SWAP(q1 : Qubit, q2: Qubit) : Unit is Adj {
  CNOT(q1, q2);
}

// 1-qubit QFT
operation OneQubitQFT (q : Qubit) : Unit is Adj {
  H(q);
}
// Rotation gate
// Applies a rotation about the |1⟩ state by an angle 
// specified as a dyadic fraction.
operation Rotation (q : Qubit, k : Int) : Unit is Adj+Ctl {
  let angle = 2.0 * 3.14159 / IntAsDouble(1 <<< k);
  // Message($"Angle {angle}");
  Rz(angle, q);
}
// Prepare binary fraction exponent in place (quantum input)
operation BinaryFractionQuantumInPlace (register : Qubit[]) : Unit is Adj {
  OneQubitQFT(register[0]);
  for ind in 1 .. Length(register) - 1 {
      // Message("Apply BinaryFractionQuantumInPlace");
      Controlled Rotation([register[ind]], (register[0], ind + 1));
  }
}
// Reverse the order of qubits
operation ReverseRegister (register : Qubit[]) : Unit is Adj {
    let N = Length(register);
    for ind in 0 .. N / 2 - 1 {
        SWAP(register[ind], register[N - 1 - ind]);
    }
}
// Quantum Fourier transform
// Input: A register of qubits in state |j₁j₂...⟩
// Goal: Apply quantum Fourier transform to the input register
operation QuantumFourierTransform (register : Qubit[]) : Unit is Adj {
  let n = Length(register);
  for i in 0 .. n - 1 {
      BinaryFractionQuantumInPlace(register[i ...]);
  }
  ReverseRegister(register);
operation IQFT(qq: Qubit[]): Unit {
  Message("Hello from Q# IQFT");
  for i in 0 .. Length(qq)/2 - 1 {
    SWAP(qq[i], qq[Length(qq)-i-1]);
  }
    
operation IQFT (register : Qubit[]) : Unit {
  Adjoint QuantumFourierTransform(register);
  for i in 0 .. Length(qq) - 2 {
    H(qq[i]);
    let j = i + 1;
    mutable y = i;
    repeat {
      let theta = -3.14159 / IntAsDouble(1 <<< (j-y));
      // Controlled R1 == CPhase
      Controlled R1([qq[j]], (theta, qq[y]));
      set y = y - 1;
    } until (y < 0);
  }

@EntryPoint() 
operation Dummy(): Unit {
  use qubits = Qubit[3] 
  {
    IQFT(qubits);
  }
  H(qq[Length(qq) -1]);
}
}
 No newline at end of file
+5 −4
Original line number Diff line number Diff line
@@ -3,8 +3,8 @@ OPENQASM 3;

const n_counting = 3;

// Declare external quantum subroutine:
def QCOR__IQFT__Interop qubit[n_counting]:qq extern;
// Declare external quantum subroutine (Q#)
def QCOR__IQFT__body qubit[n_counting]:qq extern;

// For this example, the oracle is the T gate 
// on the provided qubit
@@ -36,7 +36,8 @@ for i in [0:n_counting] {
}

// Run inverse QFT 
QCOR__IQFT__Interop counting;
// This Kernel is from Q#
QCOR__IQFT__body counting;

// Now lets measure the counting qubits
bit c[n_counting];
@@ -44,4 +45,4 @@ measure counting -> c;

// Backend is QPP which is lsb, 
// so return should be 100
print(c);
print("Final Bitstring:", c);
+1 −1
Original line number Diff line number Diff line
@@ -122,7 +122,7 @@ antlrcpp::Any qasm3_visitor::visitSubroutineDefinition(
  }
  // Handle "extern" subroutine declaration:
  if (context->subroutineBlock()->EXTERN()) {
    std::cout << "Handle extern subroutine: " << subroutine_name << "\n";
    // std::cout << "Handle extern subroutine: " << subroutine_name << "\n";
    builder.setInsertionPointToStart(&m_module.getRegion().getBlocks().front());
    auto func_decl = builder.create<mlir::FuncOp>(
        get_location(builder, file_name, context), subroutine_name,
Loading