forked from microsoft/Quantum
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update to 0.9, use some 0.9 features (microsoft#228)
* Updated Dockerfile to 0.9 image. * Updated phase estimation sample a bit. * Fix SHA sum for devcontainer, update simple algorithms. * Update a few samples, add host.py to CHSH game. * Updated database search. * Add editorconfig to devcontainer. * Recommend VSCode extensions. * Force editorconfig to treat workspace as a root. * Update F# sample. * Adapted rest of Q# projects in standard samples. * Adapting notebooks as well. * Updated Numerics as well. * Begin updating chemistry samples. * Addressing feedback. * Finally remembering to ignore symbol cache. * Update Numerics/CustomModAdd/CustomModAdd.qs Co-Authored-By: bettinaheim <[email protected]> * Update Numerics/CustomModAdd/CustomModAdd.qs Co-Authored-By: bettinaheim <[email protected]>
- Loading branch information
1 parent
1ff82ea
commit b29c290
Showing
63 changed files
with
762 additions
and
807 deletions.
There are no files selected for viewing
This file contains 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 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,7 @@ | ||
root = true | ||
charset = utf-8 | ||
end_of_line = lf | ||
indent_size = 4 | ||
indent_style = space | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true |
This file contains 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 |
---|---|---|
|
@@ -328,3 +328,6 @@ __pycache__/ | |
*.btm.cs | ||
*.odx.cs | ||
*.xsd.cs | ||
|
||
# Common VS Code extensions | ||
.ionide/symbolCache.db |
This file contains 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,8 @@ | ||
{ | ||
"recommendations": [ | ||
"quantum.quantum-devkit-vscode", | ||
"ms-vscode.csharp", | ||
"ms-python.python", | ||
"EditorConfig.EditorConfig" | ||
] | ||
} |
This file contains 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 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 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 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 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 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 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 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 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 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 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 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 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 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,49 @@ | ||
# Copyright (c) Microsoft Corporation. | ||
# Licensed under the MIT License. | ||
|
||
import numpy as np | ||
import random | ||
from typing import Tuple | ||
|
||
import qsharp | ||
from Microsoft.Quantum.Samples.CHSHGame import PlayQuantumStrategy | ||
|
||
def get_random_bits(n_bits=1): | ||
return [ | ||
bool(random.getrandbits(1)) | ||
for _ in range(n_bits) | ||
] if n_bits > 1 else bool(random.getrandbits(1)) | ||
|
||
def referee_single_round() -> bool: | ||
""" | ||
Play a single round of the CHSH game and referee to see if the quantum | ||
strategy won the round. | ||
""" | ||
|
||
# Generate random inpus for each player. | ||
alice_input, bob_input = get_random_bits(2) | ||
|
||
# Check whether Alice or Bob should go first. | ||
alice_measures_first = get_random_bits(1) | ||
|
||
# Run the Q# program to get the parity of Alice's and Bob's answers. | ||
output_parity = PlayQuantumStrategy.simulate( | ||
aliceBit=alice_input, | ||
bobBit=bob_input, | ||
aliceMeasuresFirst=alice_measures_first | ||
) | ||
|
||
# Check if Alice and Bob won the round. | ||
return output_parity == (not (alice_input and bob_input)) | ||
|
||
def estimate_quantum_win_probability(n_trials : int) -> Tuple[float, float]: | ||
est = np.mean([ | ||
referee_single_round() | ||
for _ in range(n_trials) | ||
]) | ||
|
||
return est, np.sqrt(est * (1 - est) / n_trials) | ||
|
||
if __name__ == "__main__": | ||
est_win_pr, error = estimate_quantum_win_probability(400) | ||
print(f"Estimated quantum win probability: {est_win_pr:%} ± {error:%}") |
Oops, something went wrong.