// ------------------------------------------- // First, a few useful operators. Note that these will apply to all of // the qubits in the register "a". That is, if a = |000>, X(a) ==> |111>. operator X(qureg a) {Not(a);} // The inverse operator operator H(qureg a) {Mix(a);} // The Hadamard operator Z(qureg a) {H(a);X(a);H(a);} // Easy to compose operators // ------------------------------------------- // A less common operator. Rotate around an axis theta degrees from the // z-axis, in the direction of the x-axis (on the Bloch sphere). The // overall operation is (X*sin(theta) + Z*cos(theta)), but there is no way // to do that in QCL. operator XZ(qureg a,real theta) { // Complex type is (re, im), where re and im are real type (hence the // decimal point). Qcl doesn't handle complex numbers in the most // intuitive way! complex c = cos(theta) * (1., 0.); complex s = sin(theta) * (1., 0.); // Apply the operator to all elements of a. This could also be // written to apply to only the first element, or to trigger an error // if a has more than one element. int i; for i = 0 to #a - 1 { Matrix2x2(c, s, s, -c, a[i]); } } // ------------------------------------------- // clear a qubit register procedure Clear(qureg x) { int mx; int i; for i = 0 to #x - 1 { measure x[i], mx; if (mx == 1){ Not(x[i]); } } } // ------------------------------------------- // The "main" body of the code // Declare a register qureg a[2]; // Apply some operators X(a[0]); dump a; H(a[1]); dump a; Z(a); dump a; Clear(a); // Apply a Kane rotation with the "A"-electrode off (i.e., apply X and Z // simultaneously). The magnitude of the x rotation is 8/3 that of the z // rotation.... //XZ(a[0], atan(8./3.)); // Just kidding. QCL doesn't have an atan feature! I've calculated it // below, for convenience. XZ(a[0], 1.21202565652);