qsharp-lang 1.14.5-dev → 1.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -45,7 +45,7 @@ export default [
|
|
|
45
45
|
"code": "/// # Summary\n/// Simple Quantum Random Number Generator sample\n///\n/// # Description\n/// This program implements a quantum random number generator by setting qubits\n/// into superposition and then using the measurement results as random bits.\n/// This is equivalent to generating a random number in the range of 0..2ᴺ-1.\noperation Main() : Result[] {\n // Generate a 5-bit random number.\n GenerateNRandomBits(5)\n}\n\n/// # Summary\n/// Generates N random bits in the form of `Zero` or `One` results.\noperation GenerateNRandomBits(nBits : Int) : Result[] {\n // Array for the results\n mutable results = [];\n for _ in 1..nBits {\n // Append next random result to the array\n results += [GenerateRandomBit()];\n }\n results\n}\n\n/// # Summary\n/// Generates a random bit in the form of `Zero` or `One` result.\noperation GenerateRandomBit() : Result {\n // Allocate a qubit\n use q = Qubit();\n // Set the qubit into uniform superposition of |0〉 and |1〉\n H(q);\n // Now the qubit has 50% chance of being measured as `One`\n // and 50% chance of being measured as `Zero`.\n // Measure and reset the qubit. Return the result.\n MResetZ(q)\n}\n"
|
|
46
46
|
},
|
|
47
47
|
{
|
|
48
|
-
"title": "Teleportation (Simple)
|
|
48
|
+
"title": "Teleportation (Simple)",
|
|
49
49
|
"shots": 100,
|
|
50
50
|
"code": "/// # Summary\n/// Simple quantum teleportation sample\n///\n/// # Description\n/// This Q# program demonstrates how to teleport quantum state\n/// by communicating two classical bits and using previously entangled qubits.\n/// This code teleports one specific state, but any state can be teleported.\noperation Main() : Bool {\n // Allocate `qAlice`, `qBob` qubits\n use (qAlice, qBob) = (Qubit(), Qubit());\n\n // Entangle `qAlice`, `qBob` qubits\n H(qAlice);\n CNOT(qAlice, qBob);\n\n // From now on qubits `qAlice` and `qBob` will not interact directly.\n\n // Allocate `qToTeleport` qubit and prepare it to be |𝜓⟩≈0.9394|0⟩−0.3429𝑖|1⟩\n use qToTeleport = Qubit();\n Rx(0.7, qToTeleport);\n\n // Prepare the message by entangling `qToTeleport` and `qAlice` qubits\n CNOT(qToTeleport, qAlice);\n H(qToTeleport);\n\n // Obtain classical measurement results b1 and b2 at Alice's site.\n let b1 = M(qToTeleport) == One;\n let b2 = M(qAlice) == One;\n\n // At this point classical bits b1 and b2 are \"sent\" to the Bob's site.\n\n // Decode the message by applying adjustments based on classical data b1 and b2.\n if b1 {\n Z(qBob);\n }\n if b2 {\n X(qBob);\n }\n\n // Make sure that the obtained message is |𝜓⟩≈0.9394|0⟩−0.3429𝑖|1⟩\n Rx(-0.7, qBob);\n let correct = Std.Diagnostics.CheckZero(qBob);\n Message($\"Teleportation successful: {correct}.\");\n\n // Reset all qubits to |0⟩ state.\n ResetAll([qAlice, qBob, qToTeleport]);\n\n // Return indication if the measurement of the state was correct\n correct\n}\n"
|
|
51
51
|
},
|
|
Binary file
|
package/lib/web/qsc_wasm_bg.wasm
CHANGED
|
Binary file
|