/// <summary> /// Applies a Hadamar gate to the specified qubit of a quantum circuit. /// </summary> /// <param name="circuit">The quantum circuit to which the Hadamar gate is applied</param> public static void ApplyHadamar(QuantumCircuit circuit, int qubit = 0) { if (circuit.NumberOfQubits > qubit) { circuit.H(qubit); } else { circuit.H(0); } }
private static void PlusState() { QuantumRegister register = new QuantumRegister(1); QuantumCircuit circuit = new QuantumCircuit(register); circuit.H(0); Console.WriteLine("PlusState Result: " + register[0].IsPlus); }
/// <summary> /// Applies a Hadamar gate to some ot the qubits of a quantum circuit. With normal parameters it will be applied to half /// </summary> /// <param name="circuit">The quantum circuit to which the Hadamar gates are applied</param> /// <param name="modulo">Defines the fraction of qubits to which the operation is applied if a high enough number is chosen it is only applied to a single qubit</param> /// <param name="reminder">Defines to which elements the operation is applied. (Goes from 0 to modulo-1)</param> public static void ApplyHadamarToFraction(QuantumCircuit circuit, int modulo = 2, int reminder = 0) { for (int i = 0; i < circuit.NumberOfQubits; i++) { if (i % modulo == reminder) { circuit.H(i); } } }
public static void Run() { Console.WriteLine("Running Bell Test"); //Set initial qubit QuantumRegister reg = new QuantumRegister(2); QuantumCircuit circuit = new QuantumCircuit(reg); circuit.ExecuteWithJob = true; circuit.H(0); circuit.X(1); //circuit.Y(1); circuit.H(1); circuit.Measure(); var result = circuit.Execute(1000); Console.WriteLine(result.ToJson()); Console.WriteLine("Running Bell Test ---- Done\n"); }
public static void Run() { Console.WriteLine("Running Teleportation example."); //Create a register with 2 Qubits QuantumRegister register = new QuantumRegister(2); //Create a blank circuit with the regiter initialised QuantumCircuit circuit = new QuantumCircuit(register); //Initialize the tranported counter int transported = 0; //Let try to teleport 25 quantum information for (int i = 0; i < 25; i++) { var send = GetRandom(); //Initial the first Qubit with the particle to be teleported circuit.INIT(0, send); //Hadamard gate to apply superposition to the first quantum bit which means the first qubit will have both 0 and 1 circuit.H(0); //Controlled not gate to entangle the two qubit circuit.CNOT(0, 1); //Measure the first will collapse the quantum state and bring it to reality which will be either one or zero circuit.Measure(0); //Store the first state var res1 = register[0].QState; //Now measue the second particle and store the value circuit.Measure(1); var res2 = register[1].QState; Console.WriteLine("Send: {0}, Received: {1}", res1, res2); //If you compare the result the two result will be same which states that the information is teleported. if (res1 == res2) { transported++; } register.Reset(); } Console.WriteLine("Teleported count: " + transported); Console.WriteLine("Running Teleportation example.---- done\n"); }
//Simple example to generate the 2 qubit state of a bell pair public void GenerateBellPair() { QuantumCircuit circuit = new QuantumCircuit(2, 2); MicroQiskitSimulator simulator = new MicroQiskitSimulator(); circuit.H(0); circuit.CX(0, 1); double[] probabilities = simulator.GetProbabilities(circuit); Console.WriteLine("The probability to measure 00 is: " + probabilities[0]); Console.WriteLine("The probability to measure 01 is: " + probabilities[1]); Console.WriteLine("The probability to measure 10 is: " + probabilities[2]); Console.WriteLine("The probability to measure 11 is: " + probabilities[3]); }
public static QuantumCircuit ParseCircuit(IList <object> pythonList, int numberOfQubits = 0, string dimensions = "") { QuantumCircuit circuit = new QuantumCircuit(numberOfQubits, numberOfQubits, true); object first = null; object second = null; object third = null; object forth = null; IList <object> elementList; for (int i = 0; i < pythonList.Count; i++) { elementList = (IList <object>)pythonList[i]; switch (elementList.Count) { case 0: Debug.LogError("Empty List"); break; case 1: first = elementList[0]; break; case 2: first = elementList[0]; second = elementList[1]; break; case 3: first = elementList[0]; second = elementList[1]; third = elementList[2]; break; case 4: first = elementList[0]; second = elementList[1]; third = elementList[2]; forth = elementList[3]; break; default: break; } switch (first.ToString()) { case "init": IList <object> doubleList = (IList <object>)second; for (int j = 0; j < doubleList.Count; j++) { circuit.Amplitudes[j].Real = (double)doubleList[j]; } break; case "x": circuit.X((int)second); break; case "h": circuit.H((int)second); break; case "rx": circuit.RX((int)third, (double)second); break; case "cx": circuit.CX((int)second, (int)third); break; case "crx": circuit.CRX((int)third, (int)forth, (double)second); break; default: Debug.Log("Not recognized"); break; } } if (dimensions.Length >= 5) { circuit.DimensionString = dimensions; } return(circuit); }