Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
b960396
Added command line project
ScottCarda-MS May 10, 2021
daf3478
Updates to the project file
ScottCarda-MS May 11, 2021
f0da336
Updated option descriptions, changed includeLibrary to includeLibraries.
ScottCarda-MS May 11, 2021
0f96f95
Package reference instead of project reference
ScottCarda-MS May 11, 2021
8e6cf60
Changed name and updated version
ScottCarda-MS May 12, 2021
8f4b596
changes to project file
ScottCarda-MS May 13, 2021
42128a7
made includeDirectories accept multiple arguments
ScottCarda-MS May 13, 2021
eec547b
minor changes
ScottCarda-MS May 13, 2021
126c873
Merge branch 'feature/azure-quantum-simulator' into sccarda/CommandLi…
ScottCarda-MS May 14, 2021
cf0db65
Fixed help for include-directories
ScottCarda-MS May 17, 2021
66f4df3
updated version, added null checks for logger
ScottCarda-MS May 19, 2021
5c1158a
remove package reference to runtime
ScottCarda-MS May 24, 2021
74ffcca
merged in from feature
ScottCarda-MS May 24, 2021
c35834d
Added PackAsTool
ScottCarda-MS May 25, 2021
2dda015
Allow for multiple library and include paths
ScottCarda-MS May 26, 2021
b30a174
Make headers and libraries arguments optional
ScottCarda-MS May 27, 2021
589d268
fixed tests
ScottCarda-MS May 27, 2021
0f37043
fixed API call in controller
ScottCarda-MS May 27, 2021
18ca27e
removed unnecessary checks
ScottCarda-MS May 27, 2021
9d7fbb6
make output folder flat
ScottCarda-MS May 27, 2021
312c220
Add package support and automatically used required headers/libraries.
ScottCarda-MS Jun 1, 2021
a250e18
merged
ScottCarda-MS Jun 2, 2021
4fd55e6
error messages
ScottCarda-MS Jun 2, 2021
8fe6bfc
better switch syntax
ScottCarda-MS Jun 2, 2021
7c4deb8
Removed package reference to qir runtime.
ScottCarda-MS Jun 2, 2021
06cd817
Moved the inclusion of libraries and headers to the Qir.Tools project.
ScottCarda-MS Jun 2, 2021
871deb9
Moved logic to use included resources to the Tools project.
ScottCarda-MS Jun 3, 2021
da50685
fixed test
ScottCarda-MS Jun 3, 2021
1d07c03
fixed test
ScottCarda-MS Jun 3, 2021
a114a9a
Try other method of detecting OS platform.
ScottCarda-MS Jun 4, 2021
d704a86
Check to see if build works without node
ScottCarda-MS Jun 4, 2021
4fc4363
Try it with exceptions first.
ScottCarda-MS Jun 4, 2021
ad68feb
Added LogWarning method and changed to logging warnings instead of th…
ScottCarda-MS Jun 4, 2021
8bf9233
Change to output Simulator path
ScottCarda-MS Jun 4, 2021
1218fa2
update tools project file
ScottCarda-MS Jun 4, 2021
c44fb54
Missed a reference to Simulators
ScottCarda-MS Jun 7, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/Qir/Execution/QirCommandLineTool/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ private static Command CreateBuildCommand()
var buildCommand = new Command("build", "(default) Build the executables from a QIR DLL.")
{
Handler = CommandHandler.Create((BuildOptions settings) =>
{
return QirTools.BuildFromQSharpDll(settings.QSharpDll, settings.LibraryDirectories, settings.IncludeDirectories, settings.ExecutablesDirectory);
})
QirTools.BuildFromQSharpDll(settings.QSharpDll, settings.LibraryDirectories, settings.IncludeDirectories, settings.ExecutablesDirectory))
};
buildCommand.TreatUnmatchedTokensAsErrors = true;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<PackAsTool>true</PackAsTool>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="System.CommandLine" Version="2.0.0-beta1.20213.1" />
<ProjectReference Include="..\..\..\Simulation\Simulators\Microsoft.Quantum.Simulators.csproj" />
<ProjectReference Include="..\Tools\Microsoft.Quantum.Qir.Tools.csproj" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta1.20213.1"/>
<ProjectReference Include="..\Tools\Microsoft.Quantum.Qir.Tools.csproj"/>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Quantum.Qir.Serialization;
using Microsoft.Quantum.Qir.Tools.Driver;
Expand All @@ -27,6 +28,8 @@ public class QirExecutableTests : IDisposable
private readonly FileInfo executableFile;
private readonly byte[] qirBytecode = { 1, 2, 3, 4, 5 };
private readonly IList<string> linkLibraries;
private readonly IList<DirectoryInfo> headerDirectories;
private readonly IList<DirectoryInfo> libraryDirectories;

public QirExecutableTests()
{
Expand All @@ -46,9 +49,13 @@ public QirExecutableTests()
runnerMock = new Mock<IQuantumExecutableRunner>();
qirExecutable = new Mock<QirExecutable>(executableFile, qirBytecode, Mock.Of<ILogger>(), driverGeneratorMock.Object, executableGeneratorMock.Object, runnerMock.Object) { CallBase = true };
linkLibraries = new List<string> { "lib1", "lib2" };
headerDirectories = new List<DirectoryInfo>();
libraryDirectories = new List<DirectoryInfo>();
qirExecutable.SetupGet(obj => obj.LinkLibraries).Returns(linkLibraries);
qirExecutable.SetupGet(obj => obj.SourceDirectoryPath).Returns(sourceDirectory.FullName);
qirExecutable.SetupGet(obj => obj.DriverFileExtension).Returns(".cpp");
qirExecutable.SetupGet(obj => obj.HeaderDirectories).Returns(headerDirectories);
qirExecutable.SetupGet(obj => obj.LibraryDirectories).Returns(libraryDirectories);
}

public void Dispose()
Expand Down
9 changes: 5 additions & 4 deletions src/Qir/Execution/Tools/Executable/QirExecutable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Quantum.Qir.Serialization;
using Microsoft.Quantum.Qir.Tools.Driver;
Expand All @@ -20,6 +21,9 @@ public abstract class QirExecutable : IQirExecutable

public virtual string SourceDirectoryPath => "src";
public abstract string DriverFileExtension { get; }
public abstract IList<string> LinkLibraries { get; }
public abstract IList<DirectoryInfo> HeaderDirectories { get; }
public abstract IList<DirectoryInfo> LibraryDirectories { get; }

protected FileInfo ExecutableFile { get; }

Expand Down Expand Up @@ -76,16 +80,13 @@ public async Task BuildAsync(EntryPointOperation entryPoint, IList<DirectoryInfo
await bytecodeFileStream.WriteAsync(qirBytecode);
}
logger.LogInfo($"Created bytecode file at {bytecodeFile.FullName}.");

await executableGenerator.GenerateExecutableAsync(ExecutableFile, sourceDirectory, libraryDirectories, includeDirectories, LinkLibraries);
await executableGenerator.GenerateExecutableAsync(ExecutableFile, sourceDirectory, libraryDirectories.Concat(this.LibraryDirectories).ToList(), includeDirectories.Concat(this.HeaderDirectories).ToList(), LinkLibraries);
}

public async Task RunAsync(ExecutionInformation executionInformation, Stream output)
{
var stringArguments = driverGenerator.GetCommandLineArguments(executionInformation);
await runner.RunExecutableAsync(ExecutableFile, output, stringArguments);
}

public abstract IList<string> LinkLibraries { get; }
}
}
32 changes: 30 additions & 2 deletions src/Qir/Execution/Tools/Executable/QirExecutableGenerator.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -32,13 +33,40 @@ await Task.Run(async () =>
// Copy all library contents to bin.
logger?.LogInfo("Copying library directories into the executable's folder.");

if (!sourceDirectory.Exists)
{
logger?.LogWarning($"Cannot find source directory: {sourceDirectory.FullName}");
}

var libDirs = new List<string>();
foreach (var dir in libraryDirectories)
{
CopyDirectoryContents(dir, binDirectory);
if (!dir.Exists)
{
logger?.LogWarning($"Cannot find given directory: {dir.FullName}");
}
else
{
CopyDirectoryContents(dir, binDirectory);
libDirs.Add(dir.FullName);
}
}

var includeDirs = new List<string>();
foreach (var dir in includeDirectories)
{
if (!dir.Exists)
{
logger?.LogWarning($"Could not find given directory: {dir.FullName}");
}
else
{
includeDirs.Add(dir.FullName);
}
}

var inputFiles = sourceDirectory.GetFiles().Select(fileInfo => fileInfo.FullName).ToArray();
await clangClient.CreateExecutableAsync(inputFiles, linkLibraries.ToArray(), libraryDirectories.Select(dir => dir.FullName).ToArray(), includeDirectories.Select(dir => dir.FullName).ToArray(), executableFile.FullName);
await clangClient.CreateExecutableAsync(inputFiles, linkLibraries.ToArray(), libDirs.ToArray(), includeDirs.ToArray(), executableFile.FullName);
});
}

Expand Down
37 changes: 30 additions & 7 deletions src/Qir/Execution/Tools/Executable/QirFullStateExecutable.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using Microsoft.Quantum.Qir.Tools.Driver;
using Microsoft.Quantum.Qir.Utility;

Expand All @@ -13,20 +16,40 @@ namespace Microsoft.Quantum.Qir.Tools.Executable
/// </summary>
public class QirFullStateExecutable : QirExecutable
{
public override string DriverFileExtension => "cpp";

public override IList<string> LinkLibraries => new List<string> {
"Microsoft.Quantum.Qir.Runtime",
"Microsoft.Quantum.Qir.QSharp.Foundation",
"Microsoft.Quantum.Qir.QSharp.Core"
};

public override IList<DirectoryInfo> HeaderDirectories { get; } = new List<DirectoryInfo>();

public override IList<DirectoryInfo> LibraryDirectories { get; } = new List<DirectoryInfo>();

public QirFullStateExecutable(FileInfo executableFile, byte[] qirBytecode, ILogger logger = null)
: base(executableFile,
qirBytecode,
new QirFullStateDriverGenerator(),
logger)
{
}
var thisModulePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
if (string.IsNullOrWhiteSpace(thisModulePath))
{
throw new InvalidOperationException("Could not get a path for the current assembly location.");
}
HeaderDirectories.Add(new DirectoryInfo(Path.Combine(thisModulePath, "runtimes", "any", "native", "include")));
HeaderDirectories.Add(new DirectoryInfo(Path.Combine(thisModulePath, "Externals", "CLI11")));

public override IList<string> LinkLibraries => new List<string> {
"Microsoft.Quantum.Qir.Runtime",
"Microsoft.Quantum.Qir.QSharp.Foundation",
"Microsoft.Quantum.Qir.QSharp.Core"
};
var osID = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "win-x64"
: RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? "linux-x64"
: RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? "osx-x64"
: throw new ArgumentException("Unsupported operating system architecture.");

public override string DriverFileExtension => "cpp";
LibraryDirectories.Add(new DirectoryInfo(Path.Combine(thisModulePath, "runtimes", osID, "native")));
LibraryDirectories.Add(new DirectoryInfo(Path.Combine(thisModulePath, "Libraries", osID)));
LibraryDirectories.Add(new DirectoryInfo(Path.Combine(thisModulePath, "Libraries")));
}
}
}
41 changes: 41 additions & 0 deletions src/Qir/Execution/Tools/Microsoft.Quantum.Qir.Tools.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<Import Project="..\..\..\Simulation\Common\Simulators.Dev.props" />

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<PlatformTarget>x64</PlatformTarget>
Expand Down Expand Up @@ -50,4 +52,43 @@
</Compile>
</ItemGroup>

<ItemGroup>
<None Include="..\..\..\Qir\drops\bin\**\*">
<Link>runtimes\%(RecursiveDir)%(FileName)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Visible>false</Visible>
</None>
<None Include="..\..\..\Qir\drops\include\**\*">
<Link>runtimes\any\native\include\%(RecursiveDir)%(FileName)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Visible>false</Visible>
</None>
</ItemGroup>

<ItemGroup>
<None Include="$(QSimDll)">
<Link>Libraries\%(FileName)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Visible>false</Visible>
</None>
</ItemGroup>

<ItemGroup>
<None Include="..\..\..\Simulation\Native\win10\**\*">
<Link>Libraries\win-x64\%(RecursiveDir)%(FileName)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Visible>false</Visible>
</None>
<None Include="..\..\..\Simulation\Native\osx\**\*">
<Link>Libraries\osx-x64\%(RecursiveDir)%(FileName)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Visible>false</Visible>
</None>
<None Include="..\..\..\Simulation\Native\linux\**\*">
<Link>Libraries\linux-x64\%(RecursiveDir)%(FileName)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Visible>false</Visible>
</None>
</ItemGroup>

</Project>
6 changes: 6 additions & 0 deletions src/Qir/Execution/Tools/Utility/ILogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ public interface ILogger
/// <param name="message">Message to log.</param>
void LogInfo(string message);

/// <summary>
/// Logs a message at the "warning" level.
/// </summary>
/// <param name="message">Message to log.</param>
void LogWarning(string message);

/// <summary>
/// Logs a message at the "error" level.
/// </summary>
Expand Down
6 changes: 6 additions & 0 deletions src/Qir/Execution/Tools/Utility/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,19 @@ public Logger(IClock clock)
// ...{exception type}: {exception message}{Environment.NewLine}{stack trace}.
private const string ExceptionMessageFormat = "Exception encountered: {0}: {1}{2}{3}";
private const string InfoLevel = "INFO";
private const string WarningLevel = "WARNING";
private const string ErrorLevel = "ERROR";

public void LogInfo(string message)
{
Console.WriteLine(LogFormat, clock.Now, InfoLevel, message);
}

public void LogWarning(string message)
{
Console.WriteLine(LogFormat, clock.Now, WarningLevel, message);
}

public void LogError(string message)
{
Console.WriteLine(LogFormat, clock.Now, ErrorLevel, message);
Expand Down