-
Notifications
You must be signed in to change notification settings - Fork 90
Merge feature/azure-quantum-simulator to main #761
Merge feature/azure-quantum-simulator to main #761
Conversation
* Create controller project. * Add script to test the QIR controller. * Test QIR controller as part of the build. * Renamed test controller script. * Update test-case file.
…azure-quantum-simulator-20210406 Merge main to feature/azure-quantum-simulator
… into alchocro/prototype-controller
…simulator-20210409
QIR controller (part 1)
…n-to-feature-azure-quantum-simulator-20210409
…azure-quantum-simulator-20210409 Merge main to feature/azure-quantum-simulator
| <#@ import namespace="System.IO" #> | ||
| <#@ import namespace="Microsoft.Quantum.QsCompiler.BondSchemas.Execution" #> | ||
| //------------------------------------------------------------------------------ | ||
| // This code was generated by a tool. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hard to understand if this file was generated by a tool or if this the source templated used by a tool and generated files will have this comment. Think like a person who sees this codebase for the first time and this is the first file that person sees.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created a README.md file at the src/Qir/Execution/Tools level that explains the *.tt files and the corresponding generated *.cs files. It also describes a bit more in detail the contents of each subfolder.
| } | ||
| } | ||
|
|
||
| var inputFiles = sourceDirectory.GetFiles().Select(fileInfo => fileInfo.FullName).ToArray(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider Directory.GetFiles(sourceDirectory.FullName). Shorter and without linq and lambdas.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case, Select is used to transform the FileInfo array returned by GetFiles() into a string array. It doesn't really do anything that requires a search pattern.
| } | ||
| } | ||
|
|
||
| private void CopyDirectoryContents(DirectoryInfo directoryToCopy, DirectoryInfo destinationDirectory) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This uses CopyFileIfNotExists so copies files only if destination file doesn't exist. Suggest reflecting this in the name. Just by the name I'd assume it will overwrite in this situation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed the name to reflect that it only copies the contents if it does not already exist in the target directory,
| process.EnableRaisingEvents = true; | ||
| process.Start(); | ||
| var output = await process.StandardOutput.ReadToEndAsync(); | ||
| process.WaitForExit(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Theoretically there's Process.WaitForExitAsync, but the standard output is closed at this time so the process should be done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe in this case it is ok to use WaitForExit instead of WaitForExitAsync since the latter just provides the option to stop waiting using a cancellation token (documentation here). Given that we don't really want the option to stop waiting using a cancellation token, WaitForExit seems like the appropriate option here.
src/Qir/Execution/Tools/QirTools.cs
Outdated
|
|
||
| if (!executablesDirectory.Exists) | ||
| { | ||
| executablesDirectory.Create(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Conditional isn't needed, Create should be a no op if directory exists.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed conditional.
src/Qir/Execution/Tools/QirTools.cs
Outdated
| executablesDirectory.Create(); | ||
| } | ||
|
|
||
| var tasks = EntryPointOperationLoader.LoadEntryPointOperations(qsharpDll).Select(entryPointOp => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not immediately clear if all the builds will run at the same time. Comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a comment about it.
| { | ||
| var filePath = Path.Combine(directory.FullName, fileName); | ||
| var fileInfo = new FileInfo(filePath); | ||
| using var fileStream = fileInfo.OpenWrite(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you consider File.WriteAllText?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed the implementation to use File.WriteAllText.
| { | ||
| var filePath = Path.Combine(directory.FullName, fileName); | ||
| var fileInfo = new FileInfo(filePath); | ||
| using var fileStream = fileInfo.OpenWrite(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you consider File.WriteAllBytes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed the implementation to use File.WriteAllBytes.
| (int byteA, int byteB) = (0, 0); | ||
| while ((byteA == byteB) && (byteA != -1)) | ||
| { | ||
| (byteA, byteB) = (streamA.ReadByte(), streamB.ReadByte()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably good enough for us, but see discussion here on performance. https://stackoverflow.com/questions/43289/comparing-two-byte-arrays-in-net
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I believe for our use it should be good enough.
| /// <summary> | ||
| /// Interface to provide configuration details to manage execution. | ||
| /// </summary> | ||
| [Obsolete("No longer used.")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I general it would be nice to say what replaces it. And by replacement I don't always mean direct replacement. If we switched to different way of doing things, it's enough to mention this new way of doing things. (Here and other places).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added more specific information about a possible replacement.
| if (settings.DryRun) | ||
| { | ||
| DisplayError("Dry run is not supported with QIR submission.", null); | ||
| return 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we have constants for specific exit codes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe it might be worth doing when we have a larger set of error conditions but for now I believe it is ok to return the same exit code regardless of the specific error.
| /// </summary> | ||
| /// <param name="settings">The Azure Quantum submission settings.</param> | ||
| /// <param name="message">The message.</param> | ||
| private static void Log(AzureSettings settings, string message) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest reflecting condition in the name, i.e. LogIfVerbose or similar.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed name to reflect the condition.
| return ""; | ||
| } | ||
|
|
||
| return baseUri.Host.Substring(0, baseUri.Host.IndexOf('.')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does Host always contain dot?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.
| private static readonly OptionInfo<string?> JobNameOption = new OptionInfo<string?>( | ||
| ImmutableList.Create("--job-name"), default, "The name of the submitted job."); | ||
| private static readonly OptionInfo<string> JobNameOption = new OptionInfo<string>( | ||
| ImmutableList.Create("--job-name"), "", "The name of the submitted job."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't matter much, but String.Empty is considered cleaner.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to string.Empty.
…ld be public and do not need to.
This PR merges the changes made in the feature/azure-quantum-simulator branch to main.