From f7cc875e5fee9fad85cd09dbf067f7e66d5bf122 Mon Sep 17 00:00:00 2001 From: Dmitry Vasilevsky Date: Wed, 5 Mar 2025 13:44:06 -0800 Subject: [PATCH 1/4] Added SimpleBellPair sample --- samples/algorithms/SimpleBellPair.qs | 34 ++++++++++++++++++++++++++++ samples/samples.mjs | 1 + samples_test/src/tests/algorithms.rs | 10 ++++++++ 3 files changed, 45 insertions(+) create mode 100644 samples/algorithms/SimpleBellPair.qs diff --git a/samples/algorithms/SimpleBellPair.qs b/samples/algorithms/SimpleBellPair.qs new file mode 100644 index 0000000000..ef69db4b9e --- /dev/null +++ b/samples/algorithms/SimpleBellPair.qs @@ -0,0 +1,34 @@ +/// # 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 +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. + (MResetZ(q1), MResetZ(q2)) + + // Qubits `q1` and `q2` are automatically released at the end of the block. +} + +/// # 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 the Hadamard gate. + H(q1); + + // Entangle the two qubits `q1` and `q2` using the `CNOT` gate. + CNOT(q1, q2); +} diff --git a/samples/samples.mjs b/samples/samples.mjs index ed9bd88dac..9ea6b48fe1 100644 --- a/samples/samples.mjs +++ b/samples/samples.mjs @@ -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 }, diff --git a/samples_test/src/tests/algorithms.rs b/samples_test/src/tests/algorithms.rs index 58cc396595..27e0519dcc 100644 --- a/samples_test/src/tests/algorithms.rs +++ b/samples_test/src/tests/algorithms.rs @@ -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 = From 58551c7a7d7a26df95aec61e8c024bba25b6d3af Mon Sep 17 00:00:00 2001 From: Dmitry Vasilevsky Date: Wed, 5 Mar 2025 14:02:26 -0800 Subject: [PATCH 2/4] Updated comments --- samples/algorithms/SimpleBellPair.qs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/samples/algorithms/SimpleBellPair.qs b/samples/algorithms/SimpleBellPair.qs index ef69db4b9e..2af4df82e1 100644 --- a/samples/algorithms/SimpleBellPair.qs +++ b/samples/algorithms/SimpleBellPair.qs @@ -5,6 +5,9 @@ /// 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(); @@ -16,15 +19,13 @@ operation Main() : (Result, Result) { // Show the state of qubits using the `DumpMachine` function. Std.Diagnostics.DumpMachine(); - // Measure the two qubits and reset them. + // Measure the two qubits and reset them. Return measurement results. (MResetZ(q1), MResetZ(q2)) - - // Qubits `q1` and `q2` are automatically released at the end of the block. } /// # Summary /// Prepare Bell pair |Φ+⟩ = (|00⟩+|11⟩)/√2 on two qubits. -/// Qubits are assumed to be in |00> state. +/// 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 the Hadamard gate. H(q1); From 2f1db3e12c3bf85cfbfd713f52870352596d8a30 Mon Sep 17 00:00:00 2001 From: Dmitry Vasilevsky Date: Wed, 5 Mar 2025 14:05:27 -0800 Subject: [PATCH 3/4] Updated comments --- samples/algorithms/SimpleBellPair.qs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/algorithms/SimpleBellPair.qs b/samples/algorithms/SimpleBellPair.qs index 2af4df82e1..95e7386a54 100644 --- a/samples/algorithms/SimpleBellPair.qs +++ b/samples/algorithms/SimpleBellPair.qs @@ -27,7 +27,7 @@ operation Main() : (Result, Result) { /// 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 the Hadamard gate. + // 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. From e9e144877261a3affa955245c05715cccbfa48b7 Mon Sep 17 00:00:00 2001 From: Dmitry Vasilevsky Date: Wed, 5 Mar 2025 14:11:17 -0800 Subject: [PATCH 4/4] Updated comments --- samples/algorithms/SimpleBellPair.qs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/samples/algorithms/SimpleBellPair.qs b/samples/algorithms/SimpleBellPair.qs index 95e7386a54..4e8d7c95b8 100644 --- a/samples/algorithms/SimpleBellPair.qs +++ b/samples/algorithms/SimpleBellPair.qs @@ -4,7 +4,7 @@ /// # 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 +/// prepares |Φ⁺⟩ = (|00⟩+|11⟩)/√2. For other Bell states see BellState.qs /// /// # References /// - [Bell state](https://en.wikipedia.org/wiki/Bell_state) @@ -24,7 +24,7 @@ operation Main() : (Result, Result) { } /// # Summary -/// Prepare Bell pair |Φ+⟩ = (|00⟩+|11⟩)/√2 on two qubits. +/// 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.