コード例 #1
0
        /// <summary>
        /// Transforme un circuit du module SerialisableClass en un circuit de la librairie QCS afin de pouvoir l'utiliser correctement.
        /// Celui-ci a besoin, pour être transformer, de la liste des portes par défauts, et des portes customs représenté sous la forme d'un dictionnaire.
        /// </summary>
        public static QCS.Circuit ToUsableCircuit(Circuit circuitSerialised, Dictionary <string, QCS.Gate> defaultGates, Dictionary <string, QCS.Gate> customGates)
        {
            QCS.Circuit circuitUsuable = new QCS.Circuit();

            int nbCols = circuitSerialised.entries.Count;
            int nbRows = circuitSerialised.rows.Count;


            for (int indexEntry = 0; indexEntry < nbCols; indexEntry++)
            {
                QCS.Qubit usuableQubit = ToUsableQubit(circuitSerialised.entries [indexEntry]);

                QCS.Circuit.EntryStruct entryStruct = new QCS.Circuit.EntryStruct(indexEntry, usuableQubit);

                circuitUsuable.entries.Add(entryStruct);
            }

            for (int indexRow = 0; indexRow < nbRows; indexRow++)
            {
                circuitUsuable.rows.Add(new List <QCS.Circuit.GateStruct> ());

                QCS.Gate gateUsuable;

                for (int indexCol = 0; indexCol < nbCols; indexCol += gateUsuable.NbEntries)
                {
                    string nameGate = circuitSerialised.rows [indexRow].cols [indexCol];

                    if (defaultGates.ContainsKey(nameGate))
                    {
                        gateUsuable = defaultGates [nameGate];
                    }

                    else if (customGates.ContainsKey(nameGate))
                    {
                        gateUsuable = customGates [nameGate];
                    }

                    else
                    {
                        gateUsuable = QCS.Gate.IDENTITY;
                    }


                    QCS.Circuit.GateStruct gateStruct = new QCS.Circuit.GateStruct(indexRow, indexCol, gateUsuable);

                    for (int indexEntry = 0; indexEntry < gateUsuable.NbEntries; indexEntry++)
                    {
                        circuitUsuable.rows [indexRow].Add(gateStruct);
                    }
                }
            }


            return(circuitUsuable);
        }
コード例 #2
0
        /**
         * ######################################################################################################
         * ############################################ CIRCUIT #################################################
         * ######################################################################################################
         */

        /// <summary>
        /// Transforme un circuit de la libraire QCS en un circuit du module SerializableClass, permettant ça serialisation
        /// </summary>
        public static Circuit ToCircuitSerialisable(QCS.Circuit circuit)
        {
            Circuit circuitSerialised = new Circuit();

            foreach (QCS.Circuit.EntryStruct entryStruct in circuit.entries)
            {
                Qubit qubitSerialised = ToQubitSerialisable(entryStruct.qubit);

                circuitSerialised.entries.Add(qubitSerialised);
            }

            foreach (List <QCS.Circuit.GateStruct> rows in circuit.rows)
            {
                circuitSerialised.rows.Add(new Circuit.Row());

                foreach (QCS.Circuit.GateStruct gate in rows)
                {
                    circuitSerialised.rows.Last().cols.Add(gate.gate.Name);
                }
            }

            return(circuitSerialised);
        }