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

Conversation

@cesarzc
Copy link
Contributor

@cesarzc cesarzc commented Jun 30, 2021

This PR merges the changes made in the feature/azure-quantum-simulator branch to main.

cesarzc and others added 30 commits April 5, 2021 10:57
* 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
…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.
Copy link
Contributor

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.

Copy link
Contributor Author

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();
Copy link
Contributor

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.

Copy link
Contributor Author

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)
Copy link
Contributor

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.

Copy link
Contributor Author

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();
Copy link
Contributor

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.

Copy link
Contributor Author

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.


if (!executablesDirectory.Exists)
{
executablesDirectory.Create();
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed conditional.

executablesDirectory.Create();
}

var tasks = EntryPointOperationLoader.LoadEntryPointOperations(qsharpDll).Select(entryPointOp =>
Copy link
Contributor

@DmitryVasilevsky DmitryVasilevsky Jul 3, 2021

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?

Copy link
Contributor Author

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();
Copy link
Contributor

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?

Copy link
Contributor Author

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();
Copy link
Contributor

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?

Copy link
Contributor Author

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());
Copy link
Contributor

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

Copy link
Contributor Author

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.")]
Copy link
Contributor

@DmitryVasilevsky DmitryVasilevsky Jul 6, 2021

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).

Copy link
Contributor Author

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;
Copy link
Contributor

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?

Copy link
Contributor Author

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)
Copy link
Contributor

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.

Copy link
Contributor Author

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('.'));
Copy link
Contributor

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?

Copy link
Contributor Author

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.");
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to string.Empty.

@cesarzc cesarzc merged commit 9fa45de into main Jul 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants