/// <summary>
 /// Applies the controlled partial rotation (in radian) to some of the qubits of the quantum circuit. The controlqubits decide if the gate 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 rotation is applied</param>
 /// <param name="rotation">The applied rotation. Rotation is in radian (so 2PI is a full rotation)</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 ApplyControledQtoFraction(QuantumCircuit circuit, float rotation, int modulo = 2, int reminderControl = 0, int reminderTarget = 1)
 {
     for (int i = 0; i < circuit.NumberOfQubits; i += modulo)
     {
         circuit.CRX(i + reminderControl, i + reminderTarget, rotation);
     }
 }
Exemple #2
0
        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);
        }