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

Allow users to specify the QDK version in the qcor command line



Also, add QDK alpha nuget source to the Dockerfile (i.e. nuget find alpha packages if need be)

Signed-off-by: default avatarThien Nguyen <nguyentm@ornl.gov>
parent e401f95e
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
+2 −2
Original line number Diff line number Diff line
@@ -4,7 +4,7 @@ OPENQASM 3;
const n_counting = 3;

// Declare external quantum subroutine:
def QCOR__IQFT__Interop qubit[n_counting]:qq extern;
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,7 @@ for i in [0:n_counting] {
}

// Run inverse QFT 
QCOR__IQFT__Interop counting;
QCOR__IQFT__body counting;

// Now lets measure the counting qubits
bit c[n_counting];
+15 −3
Original line number Diff line number Diff line
@@ -4,11 +4,11 @@ import argparse, sys, os, glob, subprocess, mimetypes, re, pathlib
# Helper to generate Q# build config by running the SDK
# Input: the source file directory where the build
# csproj will be saved to.
def generate_qsc_build_command(target_name, src_dir, input_files):
def generate_qsc_build_command(target_name, src_dir, input_files, qdk_ver):
  import os, tempfile, shutil
  temp_dir = tempfile.mkdtemp()
  # print(temp_dir)
  os.system('dotnet new console -lang Q# -o ' + temp_dir + ' -n test')
  os.system('dotnet new classlib -lang Q# -o ' + temp_dir + ' -n test')

  import xml.etree.ElementTree as ET
  # Parse the SDK generated Project file
@@ -18,6 +18,9 @@ def generate_qsc_build_command(target_name, src_dir, input_files):
  root = tree.getroot()
  # run this target:
  root.attrib['DefaultTargets'] = 'PrepareQSharpCompile'
  if qdk_ver is not None:
    print('Set Microsoft Quantum SDK to version ', qdk_ver)
    root.attrib['Sdk'] = 'Microsoft.Quantum.Sdk/' + qdk_ver
  propertyGroup = root.find('PropertyGroup')
  # enable QIR generation
  qir_gen = ET.Element('QirGeneration')
@@ -150,6 +153,7 @@ def main(argv=None):
        # Q# options to be passed to the Q# QIR generator:
        parser.add_argument('-qs-build-exe', metavar='', help='Q# QIR generator to emit alias functions for entry points.')
        parser.add_argument('-qs-runtime', metavar='', help='Specifies the classical capabilites of the QIR runtime. Valid options: BasicQuantumFunctionality, BasicMeasurementFeedback, FullComputation')
        parser.add_argument('-qdk-version', metavar='', help='Specifies the Microsoft Quantum SDK version to use.')

        args = parser.parse_args(sys.argv)

@@ -435,8 +439,16 @@ def main(argv=None):
    # Util to compile Q#
    def compile_qsharp(filename):
        base_name = os.path.splitext(filename)[0]

        qdk_version = None
        if '-qdk-version' in sys.argv[1:]:
            sidx = sys.argv.index('-qdk-version')
            qdk_version = sys.argv[sidx+1]
            sys.argv.remove(qdk_version)
            sys.argv.remove('-qdk-version')

        # Generate build command:
        build_cmd = generate_qsc_build_command(base_name, os.path.dirname(os.path.abspath(filename)), [filename, '@CMAKE_INSTALL_PREFIX@/include/qsharp/QirTarget.qs'])
        build_cmd = generate_qsc_build_command(base_name, os.path.dirname(os.path.abspath(filename)), [filename], qdk_version)
        # QSharp compiler now generates a bitcode file,
        # i.e. no need to do llvm-as
        bc_file_name = base_name + '.bc'