Exemple #1
0
        /// <summary>
        /// Connects given registers into one root register and returns that root.
        /// If registers was already connected, returns simply their root register.
        /// It is strongly required before doing any operation on qubits in different registers.
        /// This method is used at the begin of every operation from namespace <see cref="N:Quantum.Operations"/>, as these methods usually operate on more than one register.
        /// </summary>
        /// <param name="refs">Registers or references to single qubits. Registers could be passed here, because they are implicitly casted to RegisterRef type.</param>
        /// <returns>Root register, that contains connected registers given in arguments.</returns>
        public Register GetRootRegister(params RegisterRef[] refs)
        {
            if (refs.Length == 0)
            {
                return(null);
            }
            else if (refs.Length == 1)
            {
                return(refs[0].Register.Root);
            }
            else if (refs.Length == 2)
            {
                if (refs[0].Register.Root != refs[1].Register.Root)
                {
                    Register newRoot = new Register(_random);
                    newRoot.AddRegister(refs[1].Register);
                    newRoot.AddRegister(refs[0].Register);

                    return(newRoot);
                }
                else
                {
                    return(refs[0].Register.Root);
                }
            }
            else
            {
                Register      firstRoot = GetRootRegister(refs[0], refs[1]);
                RegisterRef[] newParams = new RegisterRef[refs.Length - 1];
                newParams[0] = firstRoot;
                Array.Copy(refs, 2, newParams, 1, refs.Length - 2);
                return(GetRootRegister(newParams));
            }
        }
 public void SetLevel(OperatorBase act, int level)
 {
     m_level.AddRegister(act, level);
 }