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

Merge pull request #165 from tnguyen-ornl/tnguyen/qsharp-build-update

Update Q# integration and support
parents 1d25d37e 0b3cdd7b
Loading
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -53,3 +53,8 @@ __pycache__/
# LLVM files
*.ll 
*.bc

# Build results
[Bb]in/
[Oo]bj/
*.bson
 No newline at end of file
+15 −27
Original line number Diff line number Diff line
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-focal
from qcor/deploy-base

# Mono is required to run pack.ps1, so we install it here.
RUN apt-get -y update && \
    apt-get -y install dirmngr gnupg apt-transport-https ca-certificates && \
    apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF && \
    sh -c 'echo "deb https://download.mono-project.com/repo/ubuntu stable-focal main" > /etc/apt/sources.list.d/mono-official-stable.list' && \
    apt-get -y update && \
    apt-get -y install mono-complete && \
    apt-get clean && rm -rf /var/lib/apt/lists/
# We can now get Mono itself.
RUN curl -o /usr/local/bin/nuget.exe https://dist.nuget.org/win-x86-commandline/latest/nuget.exe && \
    # Create as alias for nuget
    echo "alias nuget=\"mono /usr/local/bin/nuget.exe\"" >> /root/.bash_aliases
# Install .NET
RUN wget https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb && \
    dpkg -i packages-microsoft-prod.deb && \
    apt-get update && apt-get install -y apt-transport-https && apt-get update && apt-get install -y dotnet-sdk-3.1

# Install qsharp compiler from source
RUN git clone https://github.com/microsoft/qsharp-compiler.git
RUN cd qsharp-compiler && export SOURCE_DIR=${PWD} && cd src/QsCompiler/CommandLineTool && dotnet build && \
    echo "export PATH=${PATH}:${SOURCE_DIR}/src/QsCompiler/CommandLineTool/bin/Debug/netcoreapp3.1/" >> /root/.bashrc && \
    echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${SOURCE_DIR}/src/QsCompiler/QirGeneration/Llvm.Net/runtimes/linux-x64/native" >> /root/.bashrc && \
    # Build QirGeneration extension
    cd ${SOURCE_DIR}/src/QsCompiler/QirGeneration && dotnet build && \
    # Export the DLL location to an environment variable.
    echo "export QIR_GEN_DLL=${SOURCE_DIR}/src/QsCompiler/QirGeneration/bin/Debug/netstandard2.1/Microsoft.Quantum.QirGeneration.dll" >> /root/.bashrc
# Install Q# SDK
RUN dotnet new -i Microsoft.Quantum.ProjectTemplates

RUN apt-get update && apt-get -y install cmake gcc g++ clang-format libcurl4-openssl-dev libunwind-dev libpython3-dev python3-pip libblas-dev liblapack-dev lsb-release && \
    wget -qO- https://aide-qc.github.io/deploy/aide_qc/debian/PUBLIC-KEY.gpg | apt-key add - && \
    wget -qO- "https://aide-qc.github.io/deploy/aide_qc/debian/$(lsb_release -cs)/aide-qc.list" | tee -a /etc/apt/sources.list.d/aide-qc.list && \
    apt-get update && apt-get -y install aideqc-llvm && \
    pip3 install cmake
 No newline at end of file
# XACC and QCOR
RUN git clone --recursive https://github.com/eclipse/xacc && cd xacc && mkdir build && cd build \
    && cmake .. \
    && make -j$(nproc) install 

RUN cd ../../ && git clone -b master https://github.com/ornl-qci/qcor && cd qcor && mkdir build && cd build \
    && cmake .. -DXACC_DIR=~/.xacc -DLLVM_ROOT=/usr/local/aideqc/llvm -DMLIR_DIR=/usr/local/aideqc/llvm/lib/cmake/mlir -DQCOR_BUILD_TESTS=TRUE \
    && make -j$(nproc) install && ctest --output-on-failure
 No newline at end of file
+6 −1
Original line number Diff line number Diff line
@@ -70,3 +70,8 @@ add_qcor_compile_and_exe_test(qrt_qpu_lambda_hadamard_test ctrl-gates/hadamard_t
# Arithmetic tests
add_qcor_compile_and_exe_test(qrt_qpu_arith_adder arithmetic/simple.cpp)
add_qcor_compile_and_exe_test(qrt_qpu_arith_integer_add arithmetic/integer_add.cpp)


if (QCOR_BUILD_QSHARP_TESTS)
  add_subdirectory(qsharp)
endif()
 No newline at end of file
+14 −0
Original line number Diff line number Diff line
function(add_qcor_qsharp_test test_name relative_qs_source_location relative_cpp_source_location)
  add_test(
  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}; \
              ${CMAKE_CURRENT_BINARY_DIR}/${test_name}"
  )
endfunction()

add_qcor_qsharp_test(qcor_qsharp_bell FTQC/Bell/bell.qs FTQC/Bell/bell_driver.cpp)
add_qcor_qsharp_test(qcor_qsharp_deuteron FTQC/Deuteron/vqe_ansatz.qs FTQC/Deuteron/vqe_driver.cpp)
add_qcor_qsharp_test(qcor_qsharp_functor FTQC/Functor/functor.qs FTQC/Functor/driver.cpp)
add_qcor_qsharp_test(qcor_qsharp_qpe FTQC/qpe/qpe.qs FTQC/qpe/driver.cpp)
 No newline at end of file
+5 −4
Original line number Diff line number Diff line
namespace QCOR 
{   
// Using QCOR Intrinsic instruction set
// see QirTarget.qs    
open QCOR.Intrinsic;
open Microsoft.Quantum.Intrinsic;
@EntryPoint()
operation TestBell(count : Int) : Int {
    Message($"Count = {count}");
    // Simple bell test
    mutable numOnes = 0;
    mutable agree = 0;
    use q = Qubit[2];
    for test in 1..count {
        Message("Run Bell experiment");
        H(q[0]);
        CNOT(q[0],q[1]);
        let res0 = M(q[0]);
@@ -21,6 +21,7 @@ operation TestBell(count : Int) : Int {
        // Count the number of ones we saw:
        if res0 == One {
            set numOnes += 1;
            Message("Get one");
        }
        
        Reset(q[0]);
Loading