/// <summary> /// Applies the controlled not gate to some of the qubits of the quantum circuit. The controlqubits decide if the not is applied to the targetqubits. /// With the normal settings it is applied to half the qubits /// </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="reminderControl">Defines which elements are the control qubits. (Goes from 0 to modulo-1)</param> /// <param name="reminderTarget">Defines which elements are the target qubits. (Goes from 0 to modulo-1)</param> public static void ApplyControlledNotToFraction(QuantumCircuit circuit, int modulo = 2, int reminderControl = 0, int reminderTarget = 1) { for (int i = 0; i < circuit.NumberOfQubits; i += modulo) { circuit.CX(i + reminderControl, i + reminderTarget); } }
//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); }