operation BellTest (count : Int, initial: Result) : (Int,Int,Int)
{
body
{
mutable numOnes = 0;
mutable agree = 0;
using (qubits = Qubit[2])
{
for (test in 1..count)
{
Set (initial, qubits[0]);
Set (Zero, qubits[1]);
H(qubits[0]);
CNOT(qubits[0],qubits[1]);
let res = M (qubits[0]);
if (M (qubits[1]) == res)
{
set agree = agree + 1;
}
// Count the number of ones we saw:
if (res == One)
{
set numOnes = numOnes + 1;
}
}
Set(Zero, qubits[0]);
Set(Zero, qubits[1]);
}
// Return number of times we saw a |0&> and number of times we saw a |1&>
return (count-numOnes, numOnes, agree);
}
}
circuit = qp.get_circuit("Circuit")# get the Quantum Register by Namequantum_r = qp.get_quantum_register("qr")# get the Classical Register by Nameclassical_r = qp.get_classical_register("cr")
定義電路行為:
# Pauli X gate to qubit 1 in the Quantum Register "qr"
circuit.x(quantum_r[1])
# Pauli Y gate to qubit 2 in the Quantum Register "qr"
circuit.y(quantum_r[2])
# Pauli Z gate to qubit 3 in the Quantum Register "qr"
circuit.z(quantum_r[3])
Open up Visual Studio 2017. Go to the File menu and select New &> Project.... In the project template explorer, under Installed &> Visual C#, select the Q# Application template. Give your project the name Bell.
……
Step 3: Enter the Q# Code
……
Visual Studio should have two files open: Driver.cs, which will hold the C# driver for your quantum code, and Operation.qs, which will hold the quantum code itself.