Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pipeline refinements and packaging #172

Merged
merged 18 commits into from
May 21, 2024
Merged
29 changes: 17 additions & 12 deletions .ado/llvm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,37 +22,42 @@ steps:
cacheHitVar: CACHE_RESTORED
displayName: Cache LLVM

- script: |
- pwsh: |
git config --global core.longpaths true
echo "##vso[task.setvariable variable=QIRLIB_CACHE_DIR;]${{ parameters.directory }}"
echo "##vso[task.setvariable variable=LLVM_SYS_140_PREFIX;]${{ parameters.directory }}"
echo "##vso[task.setvariable variable=PYQIR_LLVM_FEATURE_VERSION;]llvm${{ parameters.version }}-0"
Write-Host "##vso[task.setvariable variable=QIRLIB_CACHE_DIR;]${{ parameters.directory }}"
Write-Host "##vso[task.setvariable variable=LLVM_SYS_140_PREFIX;]${{ parameters.directory }}"
Write-Host "##vso[task.setvariable variable=PYQIR_LLVM_FEATURE_VERSION;]llvm${{ parameters.version }}-0"
Write-Host "##vso[task.setvariable variable=QIRLIB_DOWNLOAD_LLVM;]false"
displayName: Configure Environment

# prerequisites for building
- script: |
- pwsh: |
sudo apt-get install -y ninja-build
displayName: Install build dependencies
condition: and(eq(variables['Agent.OS'], 'Linux'), ne(variables.CACHE_RESTORED, 'true'))

- script: |
- pwsh: |
brew install ninja
displayName: Install build dependencies
condition: and(eq(variables['Agent.OS'], 'Darwin'), ne(variables.CACHE_RESTORED, 'true'))

- script: |
- pwsh: |
choco install --accept-license -y ninja
displayName: Install build dependencies
condition: and(eq(variables['Agent.OS'], 'Windows_NT'), ne(variables.CACHE_RESTORED, 'true'))

# build and install LLVM

- script: |
cargo install --path llvm-build -vv --features llvm14-0
- pwsh: |
$vcvars = Join-Path "$(Build.SourcesDirectory)" "llvm-build" "vcvars.ps1"
if(Test-Path $vcvars) { . $vcvars } else { throw "$vcvars not found" }
cd (Join-Path "$(Build.SourcesDirectory)" "llvm-build")
cargo build --release --features llvm14-0 -vv
displayName: Build LLVM (non-Mac)
condition: and(not(canceled()), not(failed()), ne(variables.CACHE_RESTORED, 'true'), ne(variables['Agent.OS'], 'Darwin'))

- script: |
env ARCHFLAGS="${{ parameters.arch_flags }}" cargo install --path llvm-build -vv --features llvm14-0
displayName: Build LLVM (Mac)
- pwsh: |
cd (Join-Path "$(Build.SourcesDirectory)" "llvm-build")
env ARCHFLAGS="${{ parameters.arch_flags }}" cargo build --release --features llvm14-0 -vv
displayName: Build LLVM (Mac)
condition: and(not(canceled()), not(failed()), ne(variables.CACHE_RESTORED, 'true'), eq(variables['Agent.OS'], 'Darwin'))
36 changes: 29 additions & 7 deletions .ado/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ pr: none
variables:
CARGO_TERM_COLOR: always
RUST_TOOLCHAIN_VERSION: "1.78"
QIRLIB_DOWNLOAD_LLVM: "false"
QIRLIB_CACHE_DIR: $(Build.SourcesDirectory)/target/llvm14-0
LLVM_SYS_140_PREFIX: $(QIRLIB_CACHE_DIR)
PYTHON_VERSION: "3.11"
AUDITWHEEL_TAG: "manylinux_2_31_x86_64"

jobs:
- job: "Build"
Expand Down Expand Up @@ -55,7 +53,7 @@ jobs:
additionalTargets: aarch64-apple-darwin
cratesIoFeedOverride: $(cratesIoFeedOverride)
toolchainFeed: $(toolchainFeed)
displayName: Install Rust toolchain
displayName: Install Rust toolchain (Mac)
condition: eq(variables['Agent.OS'], 'Darwin')

- script: |
Expand All @@ -69,6 +67,16 @@ jobs:

# prerequisites for building

- pwsh: |
Write-Host "##vso[task.setvariable variable=MACOSX_DEPLOYMENT_TARGET;]10.9"
displayName: Configure Environment (MACOSX_DEPLOYMENT_TARGET x86_64)
condition: and(eq(variables['Agent.OS'], 'Darwin'), eq(variables['arch'], 'x86_64'))

- pwsh: |
Write-Host "##vso[task.setvariable variable=MACOSX_DEPLOYMENT_TARGET;]11.0"
displayName: Configure Environment (MACOSX_DEPLOYMENT_TARGET aarch64/universal)
condition: and(eq(variables['Agent.OS'], 'Darwin'), ne(variables['arch'], 'x86_64'))

- template: llvm.yml
parameters:
version: "14"
Expand All @@ -82,12 +90,12 @@ jobs:
- script: |
cargo build -vv --release
displayName: Build (non-Mac)
condition: ne(succeeded(), variables['Agent.OS'], 'Darwin')
condition: and(succeeded(), ne(variables['Agent.OS'], 'Darwin'))

- script: |
env ARCHFLAGS="$(ARCHFLAGS)" cargo build -vv --release
displayName: Build (Mac)
condition: eq(succeeded(), variables['Agent.OS'], 'Darwin')
condition: and(succeeded(), eq(variables['Agent.OS'], 'Darwin'))

# test the project

Expand All @@ -111,7 +119,7 @@ jobs:
- script: |
python -m pip --verbose wheel --verbose --wheel-dir target/wheels ./pip
displayName: Create Non-Linux Python wheel
condition: ne(succeeded(), variables['Agent.OS'], 'Linux')
condition: and(succeeded(), ne(variables['Agent.OS'], 'Linux'))

- script: |
python -m pip install -r pip/requirements-manylinux.txt
Expand Down Expand Up @@ -231,3 +239,17 @@ jobs:
displayName: Move Py Artifacts to Publishing Dir

# Add ESRP steps here

- task: EsrpRelease@4
displayName: Publish Py Packages
inputs:
ConnectedServiceName: 'ESRP_Release'
Intent: 'PackageDistribution'
ContentType: 'PyPi'
FolderLocation: '$(System.DefaultWorkingDirectory)/target/wheels'
Owners: '$(OwnerPersonalAlias)@microsoft.com' # NB: Group email here fails the task with non-actionable output.
Approvers: '[email protected]'
# Auto-inserted Debugging defaults:
ServiceEndpointUrl: 'https://api.esrp.microsoft.com'
MainPublisher: 'QuantumDevelpmentKit' # ESRP Team's Correction (including the critical typo "Develpm").
DomainTenantId: '72f988bf-86f1-41af-91ab-2d7cd011db47'
11 changes: 2 additions & 9 deletions runner/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,6 @@ fn run_basic_passes_on(module: &Module) -> bool {
fpm.run_on(module)
}

// Forward declare IR defined functions to force linking with static library.
// Note that the types are not needed as linking is only based on function name.
extern "C" {
fn __quantum__rt__array_slice_1d();
fn __quantum__rt__range_to_string();
}

#[allow(clippy::too_many_lines)]
fn bind_functions(module: &Module, execution_engine: &ExecutionEngine) -> Result<(), String> {
let mut uses_legacy = vec![];
Expand Down Expand Up @@ -447,7 +440,7 @@ fn bind_functions(module: &Module, execution_engine: &ExecutionEngine) -> Result

bind!(__quantum__rt__array_get_element_ptr_1d, 2);
bind!(__quantum__rt__array_get_size_1d, 1);
bind!(__quantum__rt__array_slice_1d, 3);
bind!(quantum__rt__array_slice_1d, 3);
bind!(__quantum__rt__array_update_alias_count, 2);
bind!(__quantum__rt__array_update_reference_count, 2);
bind!(__quantum__rt__bigint_add, 2);
Expand Down Expand Up @@ -493,8 +486,8 @@ fn bind_functions(module: &Module, execution_engine: &ExecutionEngine) -> Result
bind!(__quantum__rt__qubit_release, 1);
bind!(__quantum__rt__qubit_release_array, 1);
bind!(__quantum__rt__qubit_to_string, 1);
bind!(__quantum__rt__range_to_string, 1);
bind!(__quantum__rt__result_equal, 2);
bind!(quantum__rt__range_to_string, 1);
bind!(__quantum__rt__result_get_one, 0);
bind!(__quantum__rt__result_get_zero, 0);
bind!(__quantum__rt__result_to_string, 1);
Expand Down
Binary file modified runner/tests/resources/bv.bc
Binary file not shown.
Binary file modified runner/tests/resources/cji.bc
Binary file not shown.
Binary file removed runner/tests/resources/ranges.bc
Binary file not shown.
Binary file modified runner/tests/resources/shor.bc
Binary file not shown.
12 changes: 0 additions & 12 deletions runner/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,18 +252,6 @@ fn test_bernstein_vazirani() -> Result<(), String> {
run_bitcode(bitcode, None, 1, &mut std::io::sink())
}

// This tests support for range operations `__quantum__rt__array_slice_1d` and `__quantum__rt__range_to_string`
// since those two operations are defined in LLVM IR instead of Rust. As such, they are compiled into the stdlib
// and linked by the runner in a manner different than all the other functions. The test verifies that a slice of
// an array has the expected values and prints a calculated range to stdout. Range support is not exhaustively
// tested (that is left to unit tests in the stdlib), this just verifies the function linking works as expected
// for these two special cases.
#[test]
fn test_ranges() -> Result<(), String> {
let bitcode = include_bytes!("resources/ranges.bc");
run_bitcode(bitcode, None, 1, &mut std::io::sink())
}

// This test runs a sample Shor's algorithm for integer factorization. It makes use of quantum execution
// from backend and BigInt support from stdlib. It prints to stdout the value being factored, progress
// and number of retries followed by a tuple of the identified prime factors.
Expand Down
47 changes: 0 additions & 47 deletions stdlib/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,53 +9,6 @@ fn main() -> Result<(), String> {
.map(PathBuf::from)
.ok_or_else(|| "Environment variable OUT_DIR not defined.".to_string())?;

#[cfg(feature = "range-support")]
{
// Compile the LLVM IR bridge file. Requires the llvm-tools-preview component.
// This is only needed for range support, and this entire build.rs can be dropped when that functionality is
// no longer needed.

let llvm_tools = llvm_tools::LlvmTools::new().map_err(|err| {
format!(
"Failed to locate llvm tools: {:?}. Is the llvm-tools-preview component installed? Try using `rustup component add llvm-tools-preview`.",
err
)
})?;

let llc_path = llvm_tools
.tool(llvm_tools::exe("llc").to_string().as_str())
.ok_or_else(|| "Failed to find llc.".to_string())?;
let llvm_ar_path = llvm_tools
.tool(llvm_tools::exe("llvm-ar").to_string().as_str())
.ok_or_else(|| "Failed to find llvm-ar.".to_string())?;
let lib_name = if cfg!(target_os = "windows") {
"bridge-rt.lib"
} else {
"libbridge-rt.a"
};

std::process::Command::new(llc_path)
.args([
"--filetype=obj",
"./src/bridge-rt.ll",
"-o",
&format!("{}/bridge-rt.o", out_dir.display()),
])
.status()
.map_err(|err| format!("llc failed: {}.", err))?;
std::process::Command::new(llvm_ar_path)
.args([
"-r",
&format!("{}/{}", out_dir.display(), lib_name),
&format!("{}/bridge-rt.o", out_dir.display()),
])
.status()
.map_err(|err| format!("llvm-ar failed: {}.", err))?;

println!("cargo:rustc-link-lib=static=bridge-rt");
println!("cargo:rustc-link-search=native={}", out_dir.display());
}

// Copy the include files for non-Rust consumers and make them available for downstream compilation.
let include_dir = out_dir.join("include");
fs::create_dir_all(&include_dir)
Expand Down
38 changes: 0 additions & 38 deletions stdlib/src/bridge-rt.ll

This file was deleted.

Loading