Commit 5c5030d0 authored by Nguyen, Thien Minh's avatar Nguyen, Thien Minh
Browse files

Added a VQE-style example



Signed-off-by: default avatarThien Nguyen <nguyentm@ornl.gov>
parent 0a3bc70b
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -49,3 +49,7 @@ __pycache__/
# IDE files
.vscode/*
.theia/*

# LLVM files
*.ll 
*.bc
 No newline at end of file
+16 −0
Original line number Diff line number Diff line
@@ -11,6 +11,9 @@ namespace Microsoft.Quantum.Instructions {
        body intrinsic;
    }

    operation Ry (theta : Double, qb : Qubit) : Unit {
        body intrinsic;
    }
    operation Rz (theta : Double, qb : Qubit) : Unit {
        body intrinsic;
    }
@@ -106,6 +109,19 @@ namespace Microsoft.Quantum.Intrinsic {
		}
	}

    @Inline()
    operation Ry(theta : Double, qb : Qubit) : Unit
    is Adj {
        body  (...)
        {
            Phys.Ry(theta, qb);  
		}
        adjoint (...)
        {
            Phys.Ry(-theta, qb);  
		}
	}

    @Inline()
    operation Rz(theta : Double, qb : Qubit) : Unit
    is Adj + Ctl {
+12 −3
Original line number Diff line number Diff line
@@ -4,17 +4,26 @@ open Microsoft.Quantum.Intrinsic;
operation TestBell(count : Int) : Int {
    // Simple bell test
    mutable numOnes = 0;
    mutable agree = 0;
    use q = Qubit[2];
    for test in 1..count {
        H(q[0]);
        CNOT(q[0],q[1]);
        let res = M(q[0]);
        let res0 = M(q[0]);
        let res1 = M(q[1]);
        if res0 == res0 {
            set agree += 1;
        }

        // Count the number of ones we saw:
        if res == One {
        if res0 == One {
            set numOnes += 1;
            // Reset
            X(q[0]);
        }
        if res1 == One {
            // Reset
            X(q[0]);
            X(q[1]);
        }
    }
    return numOnes;
+1 −1
Original line number Diff line number Diff line
@@ -9,7 +9,7 @@ qcor_include_qsharp(XACC__TestBell__body, int64_t, int64_t)
// Compile with:
// Include both the qsharp source and this driver file 
// in the command line.
// $ qcor source.qs driver.cpp
// $ qcor bell.qs bell_driver.cpp
// Run with:
// $ ./a.out
int main() {
+30 −0
Original line number Diff line number Diff line
namespace XACC 
{
open Microsoft.Quantum.Intrinsic;
operation Deuteron(theta : Double, shots: Int) : Double {
    mutable numParityOnes = 0;
    use (qubits = Qubit[2])
    {
        for test in 1..shots {
            X(qubits[0]);
            Ry(theta, qubits[1]);
            CNOT(qubits[1], qubits[0]);
            // Let's measure <X0X1>
            H(qubits[0]);
            H(qubits[1]);
            if M(qubits[0]) != M(qubits[1]) 
            {
                set numParityOnes += 1;
            }
            if M(qubits[0]) == One {
                X(qubits[0]);
            }
            if M(qubits[1]) == One {
                X(qubits[1]);
            }
        }
    }
    let res =  IntAsDouble(shots - numParityOnes)/IntAsDouble(shots) - IntAsDouble(numParityOnes)/IntAsDouble(shots);
    return res;
}
}
 No newline at end of file
Loading