Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into t-abalaji/update-resource-estimator
Browse files Browse the repository at this point in the history
  • Loading branch information
msoeken authored Sep 17, 2021
2 parents 3aa4661 + 5604fc6 commit 5c38f9c
Show file tree
Hide file tree
Showing 86 changed files with 1,401 additions and 2,030 deletions.
2 changes: 1 addition & 1 deletion bootstrap.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Push-Location (Join-Path $PSScriptRoot "./src/Simulation/qdk_sim_rs")
--version $Env:NUGET_VERSION;
Pop-Location

if (-not (Test-Path Env:AGENT_OS)) { # If not CI build, i.e. local build (if AGENT_OS envvar is not defined)
if (-not (Test-Path Env:/AGENT_OS)) { # If not CI build, i.e. local build (if AGENT_OS envvar is not defined)
if ($Env:ENABLE_NATIVE -ne "false") {
Write-Host "Build release flavor of the native simulator"
$Env:BUILD_CONFIGURATION = "Release"
Expand Down
37 changes: 37 additions & 0 deletions build/ci-codecheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: $(date:yyMM).$(DayOfMonth)$(rev:rr)

trigger: none

pr:
- main
- feature/*
- features/*
- release/*

schedules:
- cron: "0 9 * * Sat"
displayName: 'Build for Component Governance'
branches:
include:
- main
always: true

variables:
CI: "true"

jobs:
- job: build
displayName: Build
strategy:
matrix:
linux:
imageName: 'ubuntu-latest'
mac:
imageName: 'macOS-latest'
#windows: # No sanitizers supported on Win at the moment.
# imageName: 'windows-latest'
pool:
vmImage: $(imageName)

steps:
- template: steps-codecheck.yml
50 changes: 50 additions & 0 deletions build/steps-codecheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
##
# Run all build steps.
##
steps:

- task: NuGetToolInstaller@0
displayName: 'Use NuGet 5.6.0'
inputs:
versionSpec: '5.6.0'

# QIR Runtime:
- pwsh: src/Qir/Runtime/prerequisites.ps1
displayName: "Install QIR Runtime Prerequisistes"
workingDirectory: $(System.DefaultWorkingDirectory)

- pwsh: src/Qir/Runtime/build-qir-runtime.ps1
displayName: "Build QIR Runtime"
workingDirectory: $(System.DefaultWorkingDirectory)

- pwsh: src/Qir/Runtime/test-qir-runtime.ps1
displayName: "Test QIR Runtime"
workingDirectory: $(System.DefaultWorkingDirectory)

# Native Simulator (needed to build and run the QIR tests):
- pwsh: src/Simulation/Native/prerequisites.ps1
displayName: "Install Native Simulator Prerequisites"
workingDirectory: $(System.DefaultWorkingDirectory)

- powershell: |
.\build-native-simulator.ps1
displayName: "Build Native Simulator"
workingDirectory: $(System.DefaultWorkingDirectory)/src/Simulation/Native

# QIR Tests:
- pwsh: src/Qir/Tests/build-qir-tests.ps1
displayName: "Build QIR Tests"
workingDirectory: $(System.DefaultWorkingDirectory)

- pwsh: src/Qir/Tests/test-qir-tests.ps1
displayName: "Run QIR Tests"
workingDirectory: $(System.DefaultWorkingDirectory)

# QIR Samples:
- pwsh: src/Qir/Samples/build-qir-samples.ps1
displayName: "Build QIR Samples"
workingDirectory: $(System.DefaultWorkingDirectory)

- pwsh: src/Qir/Samples/test-qir-samples.ps1
displayName: "Run QIR Samples"
workingDirectory: $(System.DefaultWorkingDirectory)
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,19 @@ public class TokenFileCredentialTests
[TestInitialize]
public void TestInitialize()
{
Environment.SetEnvironmentVariable("AZUREQUANTUM_TOKEN_FILE", _tokenFilePath);
Environment.SetEnvironmentVariable("AZURE_QUANTUM_TOKEN_FILE", _tokenFilePath);
}

[TestCleanup]
public void TestCleanup()
{
Environment.SetEnvironmentVariable("AZUREQUANTUM_TOKEN_FILE", null);
Environment.SetEnvironmentVariable("AZURE_QUANTUM_TOKEN_FILE", null);
}

[TestMethod]
public void Test_WhenFileNotSet_Throws_CredentialUnavailableException()
{
Environment.SetEnvironmentVariable("AZUREQUANTUM_TOKEN_FILE", null);
Environment.SetEnvironmentVariable("AZURE_QUANTUM_TOKEN_FILE", null);
var credential = new TokenFileCredential();

var exception = Assert.ThrowsException<CredentialUnavailableException>(() =>
Expand Down
26 changes: 13 additions & 13 deletions src/Azure/Azure.Quantum.Client.Test/WorkspaceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ public class WorkspaceTest
{
private const string SETUP = @"
Live tests require you to configure your environment with these variables:
* AZUREQUANTUM_WORKSPACE_NAME: the name of an Azure Quantum workspace to use for live testing.
* AZUREQUANTUM_SUBSCRIPTION_ID: the Azure Quantum workspace's Subscription Id.
* AZUREQUANTUM_WORKSPACE_RG: the Azure Quantum workspace's resource group.
* AZUREQUANTUM_WORKSPACE_LOCATION: the Azure Quantum workspace's location (region).
* AZURE_QUANTUM_WORKSPACE_NAME: the name of an Azure Quantum workspace to use for live testing.
* AZURE_QUANTUM_SUBSCRIPTION_ID: the Azure Quantum workspace's Subscription Id.
* AZURE_QUANTUM_WORKSPACE_RG: the Azure Quantum workspace's resource group.
* AZURE_QUANTUM_WORKSPACE_LOCATION: the Azure Quantum workspace's location (region).
We'll also try to authenticate with Azure using an instance of DefaultCredential. See
https://docs.microsoft.com/en-us/dotnet/api/overview/azure/identity-readme#authenticate-the-client
Expand Down Expand Up @@ -187,24 +187,24 @@ private static void AssertJob(CloudJob job)

private IWorkspace GetLiveWorkspace()
{
if (string.IsNullOrWhiteSpace(System.Environment.GetEnvironmentVariable("AZUREQUANTUM_SUBSCRIPTION_ID")) ||
string.IsNullOrWhiteSpace(System.Environment.GetEnvironmentVariable("AZUREQUANTUM_WORKSPACE_RG")) ||
string.IsNullOrWhiteSpace(System.Environment.GetEnvironmentVariable("AZUREQUANTUM_WORKSPACE_NAME")) ||
string.IsNullOrWhiteSpace(System.Environment.GetEnvironmentVariable("AZUREQUANTUM_SUBSCRIPTION_ID")))
if (string.IsNullOrWhiteSpace(System.Environment.GetEnvironmentVariable("AZURE_QUANTUM_SUBSCRIPTION_ID")) ||
string.IsNullOrWhiteSpace(System.Environment.GetEnvironmentVariable("AZURE_QUANTUM_WORKSPACE_RG")) ||
string.IsNullOrWhiteSpace(System.Environment.GetEnvironmentVariable("AZURE_QUANTUM_WORKSPACE_NAME")) ||
string.IsNullOrWhiteSpace(System.Environment.GetEnvironmentVariable("AZURE_QUANTUM_SUBSCRIPTION_ID")))
{
Assert.Inconclusive(SETUP);
}

var options = new QuantumJobClientOptions();
options.Diagnostics.ApplicationId = "ClientTests";
options.Diagnostics.ApplicationId = Environment.GetEnvironmentVariable("AZURE_QUANTUM_NET_APPID") ?? "ClientTests";

var credential = Authentication.CredentialFactory.CreateCredential(Authentication.CredentialType.Default);

return new Workspace(
subscriptionId: System.Environment.GetEnvironmentVariable("AZUREQUANTUM_SUBSCRIPTION_ID"),
resourceGroupName: System.Environment.GetEnvironmentVariable("AZUREQUANTUM_WORKSPACE_RG"),
workspaceName: System.Environment.GetEnvironmentVariable("AZUREQUANTUM_WORKSPACE_NAME"),
location: System.Environment.GetEnvironmentVariable("AZUREQUANTUM_WORKSPACE_LOCATION"),
subscriptionId: System.Environment.GetEnvironmentVariable("AZURE_QUANTUM_SUBSCRIPTION_ID"),
resourceGroupName: System.Environment.GetEnvironmentVariable("AZURE_QUANTUM_WORKSPACE_RG"),
workspaceName: System.Environment.GetEnvironmentVariable("AZURE_QUANTUM_WORKSPACE_NAME"),
location: System.Environment.GetEnvironmentVariable("AZURE_QUANTUM_WORKSPACE_LOCATION"),
options: options,
credential: credential);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace Microsoft.Azure.Quantum.Authentication
/// <summary>
/// Implements a custom TokenCredential to use a local file as the source for an AzureQuantum token.
///
/// It will only use the local file if the <c>AZUREQUANTUM_TOKEN_FILE</c> environment variable is set, and references
/// It will only use the local file if the <c>AZURE_QUANTUM_TOKEN_FILE</c> environment variable is set, and references
/// an existing json file that contains the access_token and expires_on timestamp in milliseconds.
///
/// If the environment variable is not set, the file does not exist, or the token is invalid in any way(expired, for example),
Expand All @@ -28,7 +28,7 @@ public class TokenFileCredential : TokenCredential
/// <summary>
/// Environment variable name for the token file path.
/// </summary>
private const string TokenFileEnvironmentVariable = "AZUREQUANTUM_TOKEN_FILE";
private const string TokenFileEnvironmentVariable = "AZURE_QUANTUM_TOKEN_FILE";

/// <summary>
/// File system dependency injected so that unit testing is possible.
Expand Down
2 changes: 2 additions & 0 deletions src/Azure/Azure.Quantum.Client/JobManagement/Workspace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public Workspace(
// Optional parameters:
credential ??= CredentialFactory.CreateCredential(CredentialType.Default, subscriptionId);
options ??= new QuantumJobClientOptions();
options.Diagnostics.ApplicationId = options.Diagnostics.ApplicationId
?? Environment.GetEnvironmentVariable("AZURE_QUANTUM_NET_APPID");

this.ResourceGroupName = resourceGroupName;
this.WorkspaceName = workspaceName;
Expand Down
8 changes: 7 additions & 1 deletion src/Qir/.clang-tidy
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
Checks:
'-*,bugprone-*,-readability-*,readability-identifier-*,readability-braces-around-statements'
'bugprone-*,readability-identifier-*,readability-braces-around-statements,cert*,\
-llvmlibc-callee-namespace,-llvmlibc-implementation-in-namespace,\
-llvmlibc-restrict-system-libc-headers,-modernize-use-trailing-return-type,\
-fuchsia-default-arguments-calls,-fuchsia-default-arguments-declarations,
-google-readability-casting'
# TODO(rokuzmin): '*, . . .'

WarningsAsErrors: '*'
HeaderFilterRegex: '.*'

Expand Down
19 changes: 16 additions & 3 deletions src/Qir/CommandLineTool/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,14 @@ private static Command CreateBuildCommand()
{
var buildCommand = new Command("build", "(default) Build the executables from a QIR DLL.")
{
Handler = CommandHandler.Create((BuildOptions settings) =>
QirTools.BuildFromQSharpDll(settings.QSharpDll, settings.LibraryDirectories, settings.IncludeDirectories, settings.ExecutablesDirectory))
Handler = CommandHandler.Create((BuildOptions settings) => QirTools.BuildFromQSharpDll(
settings.QSharpDll,
settings.LibraryDirectories,
settings.IncludeDirectories,
settings.ExecutablesDirectory,
settings.Debug)),
TreatUnmatchedTokensAsErrors = true
};
buildCommand.TreatUnmatchedTokensAsErrors = true;

buildCommand.AddOption(new Option<FileInfo>(
aliases: new string[] { "--qsharp-dll", "--dll" },
Expand Down Expand Up @@ -83,6 +87,10 @@ private static Command CreateBuildCommand()
Required = true
});

buildCommand.AddOption(new Option<bool>(
alias: "--debug",
description: "Enable additional debugging checks at runtime."));

return buildCommand;
}

Expand Down Expand Up @@ -145,6 +153,11 @@ public sealed class BuildOptions
/// The path to the output directory where the created executables will be placed.
/// </summary>
public DirectoryInfo ExecutablesDirectory { get; set; }

/// <summary>
/// Enable additional debugging checks at runtime.
/// </summary>
public bool Debug { get; set; }
}
}
}
1 change: 0 additions & 1 deletion src/Qir/Runtime/lib/QIR/.clang-tidy

This file was deleted.

1 change: 0 additions & 1 deletion src/Qir/Runtime/lib/QIR/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
# create qir-rt-support lib from the C++ sources
#
set(rt_sup_source_files
QirRange.cpp
OutputStream.cpp
Output.cpp
allocationsTracker.cpp
Expand Down
2 changes: 1 addition & 1 deletion src/Qir/Runtime/lib/QIR/Output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Public API:
extern "C"
{
void quantum__rt__message(QirString* qstr) // NOLINT
void __quantum__rt__message(QirString* qstr) // NOLINT
{
Microsoft::Quantum::OutputStream::Get() << qstr->str << std::endl;
}
Expand Down
21 changes: 0 additions & 21 deletions src/Qir/Runtime/lib/QIR/QirRange.cpp

This file was deleted.

10 changes: 5 additions & 5 deletions src/Qir/Runtime/lib/QIR/QubitManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ namespace Quantum

[[noreturn]] static void FailNow(const char* message)
{
quantum__rt__fail_cstr(message);
__quantum__rt__fail_cstr(message);
}

static void FailIf(bool condition, const char* message)
{
if (condition)
{
quantum__rt__fail_cstr(message);
__quantum__rt__fail_cstr(message);
}
}

Expand Down Expand Up @@ -181,8 +181,8 @@ namespace Quantum
sharedQubitStatusArray = new QubitIdType[(size_t)qubitCapacity];

// These objects are passed by value (copies are created)
QubitListInSharedArray FreeQubitsFresh(0, qubitCapacity - 1, sharedQubitStatusArray);
RestrictedReuseArea outermostArea(FreeQubitsFresh);
QubitListInSharedArray freeQubitsFresh(0, qubitCapacity - 1, sharedQubitStatusArray);
RestrictedReuseArea outermostArea(freeQubitsFresh);
freeQubitsInAreas.PushToBack(outermostArea);

freeQubitCount = qubitCapacity;
Expand Down Expand Up @@ -431,7 +431,7 @@ namespace Quantum
// existing values (NonMarker or indexes in the array).

// Prepare new shared status array
QubitIdType* newStatusArray = new QubitIdType[(size_t)requestedCapacity];
auto* newStatusArray = new QubitIdType[(size_t)requestedCapacity];
memcpy(newStatusArray, sharedQubitStatusArray, (size_t)qubitCapacity * sizeof(newStatusArray[0]));
QubitListInSharedArray newFreeQubits(qubitCapacity, requestedCapacity - 1, newStatusArray);

Expand Down
35 changes: 14 additions & 21 deletions src/Qir/Runtime/lib/QIR/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,50 +17,43 @@ Same-level entities are independent of each other (unless specified otherwise).
**public\QirTypes.hpp** Defines `QirArray`, `QirString`, `PTuple`, `QirTupleHeader`, `TupleWithControls`, `QirCallable`, `QirRange`.
Depends on the listed earlier ones.

**public\QirRuntime.hpp** Declares `quantum__rt__*()`. Depends on the listed earlier ones.
**public\QirRuntime.hpp** Declares `__quantum__rt__*()`. Depends on the listed earlier ones.


## Level 1

**allocationsTracker.hpp** Defines `Microsoft::Quantum::AllocationsTracker` that tracks the allocations and detects the mem leaks.
Does not depend on anything of our code.

**utils.cpp** Implements `quantum__rt__fail()`, `quantum__rt__memory_allocate()`, `quantum__rt__heap_{alloc,free}()`.
`quantum__rt__heap_alloc()` calls **strings.cpp**'s `quantum__rt__string_create()` - cyclical dependency.
**utils.cpp** Implements `__quantum__rt__fail()`, `__quantum__rt__memory_allocate()`, `__quantum__rt__heap_{alloc,free}()`.
`__quantum__rt__heap_alloc()` calls **strings.cpp**'s `__quantum__rt__string_create()` - cyclical dependency.

**strings.cpp** Implements `QirString`, `quantum__rt__string_*()`, `quantum__rt__<type>_to_string()` (except `qubit_to_string` and `result_to_string`).
Depends on **utils.cpp**'s `quantum__rt__fail()` - cyclical dependency.
**strings.cpp** Implements `QirString`, `__quantum__rt__string_*()`, `__quantum__rt__<type>_to_string()` (except `qubit_to_string` and `result_to_string`).
Depends on **utils.cpp**'s `__quantum__rt__fail()` - cyclical dependency.


## Level 2

**allocationsTracker.cpp** Implements the internals of `Microsoft::Quantum::AllocationsTracker`.
Depends on `quantum__rt__fail()`, `quantum__rt__string_create()`
Depends on `__quantum__rt__fail()`, `__quantum__rt__string_create()`

**context.cpp** Implements the internals of `Microsoft::Quantum::QirExecutionContext`,
Depends on **allocationsTracker.hpp**'s `Microsoft::Quantum::AllocationsTracker`.
Gets/returns `IRuntimeDriver *`.

## Level 3

**delegated.cpp** Implements `quantum__rt__result_*()`, `quantum__rt__qubit_{allocate,release,to_string}()`.
**delegated.cpp** Implements `__quantum__rt__result_*()`, `__quantum__rt__qubit_{allocate,release,to_string}()`.
Each API depends on `Microsoft::Quantum::GlobalContext()[->GetDriver()]`,
`quantum__rt__qubit_to_string()` also depends on strings.cpp's `quantum__rt__string_create()`.
`quantum__rt__result_to_string()` also depends on strings.cpp's `quantum__rt__string_create()`.
`__quantum__rt__qubit_to_string()` also depends on strings.cpp's `__quantum__rt__string_create()`.
`__quantum__rt__result_to_string()` also depends on strings.cpp's `__quantum__rt__string_create()`.

**arrays.cpp** Implements {the internals of `QirArray`} and `quantum__rt__*array*`.
Depends on `Microsoft::Quantum::GlobalContext()`, `quantum__rt__fail()`, `quantum__rt__string_create()`,
**delegated.cpp**'s `quantum__rt__qubit_allocate()`
**arrays.cpp** Implements {the internals of `QirArray`} and `__quantum__rt__*array*`.
Depends on `Microsoft::Quantum::GlobalContext()`, `__quantum__rt__fail()`, `__quantum__rt__string_create()`,
**delegated.cpp**'s `__quantum__rt__qubit_allocate()`

## Level 4

**callables.cpp** Defines the {internals of `QirTupleHeader`, `QirCallable`}, `quantum__rt__tuple_*()`, `quantum__rt__callable_*()`
Depends on `QirArray`, `Microsoft::Quantum::GlobalContext()`, `quantum__rt__fail()`, `quantum__rt__string_create()`, `TupleWithControls`,
**callables.cpp** Defines the {internals of `QirTupleHeader`, `QirCallable`}, `__quantum__rt__tuple_*()`, `__quantum__rt__callable_*()`
Depends on `QirArray`, `Microsoft::Quantum::GlobalContext()`, `__quantum__rt__fail()`, `__quantum__rt__string_create()`, `TupleWithControls`,
Consider breaking up into **Tuples.cpp** and **Callables.cpp**.

## Level 5

**bridge-rt.ll** Defines the `@__quantum__rt__*` entry points (to be called by the `.ll` files generated from users' `.qs` files).
The C++ Standard reserves the identifiers starting with double underscores `__`, that is why the definitions of `@__quantum__rt__*`
have been put to `.ll` file rather than `.cpp` file.
Depends on `quantum__rt__*` implementations (in **utils.cpp**, **strings.cpp**, **delegated.cpp**, **arrays.cpp**, **callables.cpp**).
Loading

0 comments on commit 5c38f9c

Please sign in to comment.