Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added SimpleBellPair sample #2213

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
35 changes: 35 additions & 0 deletions samples/algorithms/SimpleBellPair.qs
Copy link
Contributor

Choose a reason for hiding this comment

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

We have simple bell pair generation in the algorithms/entanglement.qs. How about renaming that to entanglement-simple-bell-pair.qs? That way we improve searchability and avoid redundancy. Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, good observation. I still think that we need a separate sample for discoverability and AI training. But we may need to adjust entanglement sample. We'll discuss.

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/// # Sample
/// Simple Bell Pair
///
/// # Description
/// Bell pairs are specific quantum states of two qubits that represent
/// the simplest (and maximal) examples of quantum entanglement. This sample
/// prepares |Φ⁺⟩ = (|00⟩+|11⟩)/√2. For other Bell states see BellState.qs
///
/// # References
/// - [Bell state](https://en.wikipedia.org/wiki/Bell_state)
operation Main() : (Result, Result) {
// Allocate the two qubits that will be used to create a Bell pair.
use q1 = Qubit();
use q2 = Qubit();

// Create Bell pair by calling `PrepareBellPair` operation defined below.
PrepareBellPair(q1, q2);

// Show the state of qubits using the `DumpMachine` function.
Std.Diagnostics.DumpMachine();

// Measure the two qubits and reset them. Return measurement results.
(MResetZ(q1), MResetZ(q2))
}

/// # Summary
/// Prepare Bell pair |Φ⁺⟩ = (|00⟩+|11⟩)/√2 on two qubits.
/// Qubits are assumed to be in |00⟩ state.
operation PrepareBellPair(q1 : Qubit, q2 : Qubit) : Unit {
// Set qubit `q1` in superposition of |0⟩ and |1⟩ by applying a Hadamard gate.
H(q1);

// Entangle the two qubits `q1` and `q2` using the `CNOT` gate.
CNOT(q1, q2);
}
1 change: 1 addition & 0 deletions samples/samples.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export default [
{ title: "Minimal", file: "./language/GettingStarted.qs", shots: 100 },
{ title: "Superposition", file: "./algorithms/Superposition.qs", shots: 100 },
{ title: "Entanglement", file: "./algorithms/Entanglement.qs", shots: 100 },
{ title: "Simple Bell Pair", file: "./algorithms/SimpleBellPair.qs", shots: 1000 },
{ title: "Bell States", file: "./algorithms/BellState.qs", shots: 100 },
{ title: "Teleportation", file: "./algorithms/Teleportation.qs", shots: 1 },
{ title: "Random Bit", file: "./algorithms/RandomBit.qs", shots: 100 },
Expand Down
10 changes: 10 additions & 0 deletions samples_test/src/tests/algorithms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,16 @@ pub const SHOR_EXPECT_DEBUG: Expect = expect![[r#"
Found factor=17
Found factorization 187 = 17 * 11
(17, 11)"#]];
pub const SIMPLEBELLPAIR_EXPECT: Expect = expect![[r#"
STATE:
|00⟩: 0.7071+0.0000𝑖
|11⟩: 0.7071+0.0000𝑖
(Zero, Zero)"#]];
pub const SIMPLEBELLPAIR_EXPECT_DEBUG: Expect = expect![[r#"
STATE:
|00⟩: 0.7071+0.0000𝑖
|11⟩: 0.7071+0.0000𝑖
(Zero, Zero)"#]];
pub const SIMPLEISING_EXPECT: Expect =
expect!["[Zero, Zero, Zero, One, One, Zero, One, One, Zero]"];
pub const SIMPLEISING_EXPECT_DEBUG: Expect =
Expand Down
Loading