This repository was archived by the owner on Jan 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 90
Generate command-line program for Q# projects with an entry point #169
Merged
Merged
Changes from all commits
Commits
Show all changes
75 commits
Select commit
Hold shift + click to select a range
501ad89
Start set up for entry point code generation
d5787a2
Generate sequence of command-line options
bb1b8a2
Generate argument properties
b2de6e5
Capitalize first letter of argument property
c345fa4
Add autogen comment to entry point file
b8e939f
Add run method to runner
3b0f10f
Check if temp entry point exists in CodegenContext.Create
ba6fb11
Get entry points from compilation
50b14bb
Add non-generated entry point driver source
b9010cc
Use IEnumerable for array types
41d599b
Convert argument names to kebab-case
75e5a7c
Undo changes to CodegenContext
737ed37
Remove unnecessary string interpolation
a2dc23a
Use entry point summary as description for root command
1799688
Use doc comment for option descriptions
913b265
One-letter parameters get one dash
17b122e
Don't output anything if return type is Unit
93f8867
Handle parameters of type Range
7abfca2
Add doc comments to driver
f356c8a
Add argument handler for BigInt
f854579
Don't allow more dots than necessary in range
29798f1
Don't show duplicate errors
12041a8
Add function to create error messages
af30876
Add argument handler for Result type
b768e31
Add argument handler for type Unit
091ce83
Change readonly fields to properties
1fa663d
Refactor argument parsers
c77cf9f
Refactor getArgumentHandler
7b6e8ad
Merge remote-tracking branch 'origin/master' into samarsha/standalone
f30a397
Remove extra blank line
0925f76
Use Enum.TryParse for Result
261eb2d
Combine simulate and resources commands
b0e2044
Pass simulate description to constructor
1a63d62
Set simulate command as the default
e106ace
Add suggestions for custom argument types
59175c0
Entry point option names shadow standard names
39997c6
Support custom simulators
8bca47e
Merge branch 'master' into samarsha/standalone
bamarsha f0a6b51
Use DefaultSimulator property
583168f
Support custom DefaultSimulator; remove reflection
88801bc
Add TODO for option alias constants
5fd5720
Merge branch 'master' into samarsha/standalone
bamarsha fb4cbcd
Verify not more than one entry point
5d44673
Use CommandLineArguments.SimulatorOption
ee15b5c
Simplify function names
e85a806
Add constants for simulator names
c331f48
Protect namespace name instead of class names
e5a790a
Support tab completion for simulators
bc7a216
Consistent trailing newlines for generatedClasses and driver
0cb3ef0
Add basic unit tests
e6b266c
Add tests for option types
84b71b5
Add failure cases
d2afefb
Better test syntax
a3ba32d
Add help message test
1778b9e
Add tests for name conversions and shadowing
d8a9fd0
Add tests for multiple options
d5819ba
Add simulator tests
f4b6357
Should be private
db81d14
More detailed error message for missing reference
c7fcc70
Use platform-specific delimiter
42f8fd3
Use default simulator when --simulator is shadowed
92a1f1c
Normalize whitespace in tests
d56c837
Update DefaultIfShadowed summary
fcd1c20
Add DefaultSimulator tests
960cc71
Use AssemblyConstants for simulator names
b006c3b
Use H gate to test for ToffoliSimulator
a26a637
Use try/finally for console redirects and current culture
52c2873
Add missing dashes in test name
6f426a8
Better way to write the testAssembly function
c938ae8
adding an execution test (#174)
bettinaheim 7ed88f0
forgot to use dll instead of exe
bba191c
Merge branch 'master' into samarsha/standalone
bettinaheim f1dc2f6
Add TODO
a422cf8
Merge branch 'samarsha/standalone' of https://github.com/microsoft/qs…
0de879d
Remove space-separated range parsing
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| namespace Microsoft.Quantum.Core { | ||
| @Attribute() | ||
| newtype Attribute = Unit; | ||
|
|
||
| @Attribute() | ||
| newtype EntryPoint = Unit; | ||
| } |
247 changes: 247 additions & 0 deletions
247
src/Simulation/CsharpGeneration.Tests/Circuits/EntryPointTests.qs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,247 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| // | ||
| // No Options | ||
| // | ||
|
|
||
| namespace Microsoft.Quantum.CsharpGeneration.Testing.EntryPoint { | ||
| @EntryPoint() | ||
| operation ReturnUnit() : Unit { } | ||
| } | ||
|
|
||
| // --- | ||
|
|
||
| namespace Microsoft.Quantum.CsharpGeneration.Testing.EntryPoint { | ||
| @EntryPoint() | ||
| operation ReturnInt() : Int { | ||
| return 42; | ||
| } | ||
| } | ||
|
|
||
| // --- | ||
|
|
||
| namespace Microsoft.Quantum.CsharpGeneration.Testing.EntryPoint { | ||
| @EntryPoint() | ||
| operation ReturnString() : String { | ||
| return "Hello, World!"; | ||
| } | ||
| } | ||
|
|
||
| // --- | ||
|
|
||
| // | ||
| // Single Option | ||
| // | ||
|
|
||
| namespace Microsoft.Quantum.CsharpGeneration.Testing.EntryPoint { | ||
| @EntryPoint() | ||
| operation AcceptInt(n : Int) : Int { | ||
| return n; | ||
| } | ||
| } | ||
|
|
||
| // --- | ||
|
|
||
| namespace Microsoft.Quantum.CsharpGeneration.Testing.EntryPoint { | ||
| @EntryPoint() | ||
| operation AcceptBigInt(n : BigInt) : BigInt { | ||
| return n; | ||
| } | ||
| } | ||
|
|
||
| // --- | ||
|
|
||
| namespace Microsoft.Quantum.CsharpGeneration.Testing.EntryPoint { | ||
| @EntryPoint() | ||
| operation AcceptDouble(n : Double) : Double { | ||
| return n; | ||
| } | ||
| } | ||
|
|
||
| // --- | ||
|
|
||
| namespace Microsoft.Quantum.CsharpGeneration.Testing.EntryPoint { | ||
| @EntryPoint() | ||
| operation AcceptBool(b : Bool) : Bool { | ||
| return b; | ||
| } | ||
| } | ||
|
|
||
| // --- | ||
|
|
||
| namespace Microsoft.Quantum.CsharpGeneration.Testing.EntryPoint { | ||
| @EntryPoint() | ||
| operation AcceptPauli(p : Pauli) : Pauli { | ||
| return p; | ||
| } | ||
| } | ||
|
|
||
| // --- | ||
|
|
||
| namespace Microsoft.Quantum.CsharpGeneration.Testing.EntryPoint { | ||
| @EntryPoint() | ||
| operation AcceptResult(r : Result) : Result { | ||
| return r; | ||
| } | ||
| } | ||
|
|
||
| // --- | ||
|
|
||
| namespace Microsoft.Quantum.CsharpGeneration.Testing.EntryPoint { | ||
| @EntryPoint() | ||
| operation AcceptRange(r : Range) : Range { | ||
| return r; | ||
| } | ||
| } | ||
|
|
||
| // --- | ||
|
|
||
| namespace Microsoft.Quantum.CsharpGeneration.Testing.EntryPoint { | ||
| @EntryPoint() | ||
| operation AcceptString(s : String) : String { | ||
| return s; | ||
| } | ||
| } | ||
|
|
||
| // --- | ||
|
|
||
| namespace Microsoft.Quantum.CsharpGeneration.Testing.EntryPoint { | ||
| @EntryPoint() | ||
| operation AcceptStringArray(xs : String[]) : String[] { | ||
| return xs; | ||
| } | ||
| } | ||
|
|
||
| // --- | ||
|
|
||
| namespace Microsoft.Quantum.CsharpGeneration.Testing.EntryPoint { | ||
| @EntryPoint() | ||
| operation AcceptUnit(u : Unit) : Unit { | ||
| return u; | ||
| } | ||
| } | ||
|
|
||
| // --- | ||
|
|
||
| // | ||
| // Multiple Options | ||
| // | ||
|
|
||
| namespace Microsoft.Quantum.CsharpGeneration.Testing.EntryPoint { | ||
| @EntryPoint() | ||
| operation TwoOptions(n : Int, b : Bool) : String { | ||
| return $"{n} {b}"; | ||
| } | ||
| } | ||
|
|
||
| // --- | ||
|
|
||
| namespace Microsoft.Quantum.CsharpGeneration.Testing.EntryPoint { | ||
| @EntryPoint() | ||
| operation ThreeOptions(n : Int, b : Bool, xs : String[]) : String { | ||
| return $"{n} {b} {xs}"; | ||
| } | ||
| } | ||
|
|
||
| // --- | ||
|
|
||
| // | ||
| // Name Conversion | ||
| // | ||
|
|
||
| namespace Microsoft.Quantum.CsharpGeneration.Testing.EntryPoint { | ||
| @EntryPoint() | ||
| operation CamelCase(camelCaseName : String) : String { | ||
| return camelCaseName; | ||
| } | ||
| } | ||
|
|
||
| // --- | ||
|
|
||
| namespace Microsoft.Quantum.CsharpGeneration.Testing.EntryPoint { | ||
| @EntryPoint() | ||
| operation SingleLetter(x : String) : String { | ||
| return x; | ||
| } | ||
| } | ||
|
|
||
| // --- | ||
|
|
||
| // | ||
| // Shadowing | ||
| // | ||
|
|
||
| namespace Microsoft.Quantum.CsharpGeneration.Testing.EntryPoint { | ||
| @EntryPoint() | ||
| operation ShadowSimulator(simulator : String) : String { | ||
| return simulator; | ||
| } | ||
| } | ||
|
|
||
| // --- | ||
|
|
||
| namespace Microsoft.Quantum.CsharpGeneration.Testing.EntryPoint { | ||
| @EntryPoint() | ||
| operation ShadowS(s : String) : String { | ||
| return s; | ||
| } | ||
| } | ||
|
|
||
| // --- | ||
|
|
||
| namespace Microsoft.Quantum.CsharpGeneration.Testing.EntryPoint { | ||
| @EntryPoint() | ||
| operation ShadowVersion(version : String) : String { | ||
| return version; | ||
| } | ||
| } | ||
|
|
||
| // --- | ||
|
|
||
| // | ||
| // Simulators | ||
| // | ||
|
|
||
| namespace Microsoft.Quantum.CsharpGeneration.Testing.EntryPoint { | ||
| open Microsoft.Quantum.Intrinsic; | ||
|
|
||
| @EntryPoint() | ||
| operation XOrH(useH : Bool) : String { | ||
| using (q = Qubit()) { | ||
| if (useH) { | ||
| H(q); | ||
| } else { | ||
| X(q); | ||
| } | ||
|
|
||
| if (M(q) == One) { | ||
| X(q); | ||
| } | ||
| } | ||
| return "Hello, World!"; | ||
| } | ||
| } | ||
|
|
||
| // --- | ||
|
|
||
| // | ||
| // Help | ||
| // | ||
|
|
||
| namespace Microsoft.Quantum.CsharpGeneration.Testing.EntryPoint { | ||
| /// # Summary | ||
| /// This test checks that the entry point documentation appears correctly in the command line help message. | ||
| /// | ||
| /// # Input | ||
| /// ## n | ||
| /// A number. | ||
| /// | ||
| /// ## pauli | ||
| /// The name of a Pauli matrix. | ||
| /// | ||
| /// ## myCoolBool | ||
| /// A neat bit. | ||
| @EntryPoint() | ||
| operation Help(n : Int, pauli : Pauli, myCoolBool : Bool) : Unit { } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.