Exemplo n.º 1
0
 protected RegisterPartModel incRegPart(RegisterPartModel regRef, RegisterModel register, int afterOffset, int delta = 1)
 {
     if (regRef.Register == register)
     {
         if (regRef.Width + delta == register.Qubits.Count)
         {
             return new RegisterPartModel()
             {
                 Register = regRef.Register,
                 Offset = regRef.Offset,
                 Width = regRef.Width + delta
             };
         }
         else if (regRef.Offset > afterOffset)
         {
             return new RegisterPartModel()
             {
                 Register = regRef.Register,
                 Offset = regRef.Offset + delta,
                 Width = regRef.Width
             };
         }
         else if (regRef.Offset + regRef.Width - 1 > afterOffset)
         {
             return new RegisterPartModel()
             {
                 Register = regRef.Register,
                 Offset = regRef.Offset,
                 Width = regRef.Width + delta
             };
         }
     }
     return regRef;
 }
Exemplo n.º 2
0
 internal Register(ComputerModel compModel, Quantum.Register reg, RegisterModel regModel, int offsetToModel = 0)
 {
     _compModel = compModel;
     _register = reg;
     _model = regModel;
     _offsetToModel = offsetToModel;
 }
Exemplo n.º 3
0
 private string GetRegName(RegisterModel reg, string defaultRegName)
 {
     if (reg != null)
     {
         return reg.Name;
     }
     if (defaultRegName != null)
     {
         return defaultRegName;
     }
     _rootNeeded = true;
     return "root";
 }
Exemplo n.º 4
0
 private string GenerateRegisterCode(RegisterModel reg, string indent)
 {
     IDictionary<ulong, Complex> initStates = reg.InitStates;
     if (initStates.Count > 1)
     {
         string initStatesName = reg.Name + "_initStates";
         string initStatesDef = GenerateStatesDefinition(initStatesName, initStates, indent);
         return String.Format("{0}{1}Register {2} = comp.NewRegister({3}, {4});", initStatesDef, indent, reg.Name, initStatesName, reg.Qubits.Count);
     }
     else if (initStates != null && initStates.Count > 0)
     {
         ulong initState = initStates.Keys.First<ulong>();
         return String.Format("{0}Register {1} = comp.NewRegister({2}, {3});", indent, reg.Name, initState, reg.Qubits.Count);
     }
     else
     {
         return String.Format("{0}Register {1} = comp.NewRegister(0, {2});", indent, reg.Name, reg.Qubits.Count);
     }
 }
Exemplo n.º 5
0
 public override void IncrementRow(RegisterModel register, int afterOffset, int delta = 1)
 {
     if (_target.Register == register && _target.Offset > afterOffset)
     {
         _target.Offset += delta;
     }
     if (_control.HasValue)
     {
         if (_control.Value.Register == register && _control.Value.Offset > afterOffset)
         {
             _control = new RegisterRefModel() { Register = register, Offset = _control.Value.Offset + delta };
         }
     }
 }
Exemplo n.º 6
0
 public override void IncrementRow(RegisterModel register, int afterOffset, int delta = 1)
 {
     if (_beginRow.Register == register && _beginRow.Offset > afterOffset)
     {
         _beginRow.Offset += delta;
     }
     if (_endRow.Register == register && _endRow.Offset > afterOffset)
     {
         _endRow.Offset += delta;
     }
 }
Exemplo n.º 7
0
        public override void IncrementRow(RegisterModel register, int afterOffset, int delta = 1)
        {
            Func<RegisterRefModel, RegisterRefModel> incRegRef = regRef =>
            {
                if (regRef.Register == register && regRef.Offset > afterOffset)
                {
                    return new RegisterRefModel()
                    {
                        Register = regRef.Register,
                        Offset = regRef.Offset + delta
                    };
                }
                return regRef;
            };

            for (int i = 0; i < _parameters.Length; i++)
            {
                if (_parameters[i] is RegisterRefModel)
                {
                    _parameters[i] = incRegRef((RegisterRefModel)_parameters[i]);
                }
                else if (_parameters[i] is RegisterPartModel)
                {
                    _parameters[i] = incRegPart((RegisterPartModel)_parameters[i], register, afterOffset, delta);
                }
                else if (_parameters[i] is RegisterRefModel[])
                {
                    _parameters[i] = (_parameters[i] as RegisterRefModel[])
                        .Select<RegisterRefModel, RegisterRefModel>(x => incRegRef(x)).ToArray();
                }
                else if (_parameters[i] is RegisterPartModel[])
                {
                    _parameters[i] = (_parameters[i] as RegisterPartModel[])
                        .Select<RegisterPartModel, RegisterPartModel>(x => incRegPart(x, register, afterOffset, delta)).ToArray();
                }
            }
            UpdateRefs();
        }
 public override void IncrementRow(RegisterModel register, int afterOffset, int delta = 1)
 {
     if (_target.Register == register && _target.Offset > afterOffset)
     {
         _target.Offset += delta;
     }
     for (int i = 0; i < _controls.Length; i++)
     {
         if (_controls[i].Register == register && _controls[i].Offset > afterOffset)
         {
             _controls[i].Offset += delta;
         }
     }
 }
Exemplo n.º 9
0
 public abstract void IncrementRow(RegisterModel register, int afterOffset, int delta = 1);
Exemplo n.º 10
0
 private void CreateRegisters()
 {
     _registers = new ObservableCollection<RegisterModel>();
     int offsetToRoot = 0;
     for (int i = 0; i < InitialRegistersCount; i++)
     {
         RegisterModel newReg = new RegisterModel(InitialRegistersCount - i - 1, offsetToRoot);
         _registers.Insert(0, newReg);
         offsetToRoot += newReg.Qubits.Count;
     }
 }
Exemplo n.º 11
0
        public void InsertRegisterAbove(int registerIndex, int width, Dictionary<ulong, Complex> initValues)
        {
            if (_currentStep != 0)
            {
                return;
            }

            SelectedItems = null;

            int offsetToRoot = 0;
            for (int i = _registers.Count - 1; i > registerIndex - 1; i--)
            {
                offsetToRoot += _registers[i].Qubits.Count;

                //increment registerIndex => updateName
                _registers[i].UpdateIndex(i + 1);
            }
            RegisterModel register = new RegisterModel(registerIndex, offsetToRoot, width, initValues);
            _registers.Insert(registerIndex, register);

            // update offset to Root
            int offsetChange = register.Qubits.Count;
            for (int i = 0; i < registerIndex; i++)
            {
                _registers[i].IncrementOffset(offsetChange);
            }

            foreach (StepModel step in Steps)
            {
                if (offsetToRoot > 0 && step.Gates[offsetToRoot - 1].End >= offsetToRoot)
                {
                    //multiqubit gate
                    for (int i = 0; i < offsetChange; i++)
                    {
                        step.Gates.Insert(offsetToRoot + i, step.Gates[offsetToRoot - 1]);
                    }
                }
                else
                {
                    for (int i = 0; i < offsetChange; i++)
                    {
                        step.Gates.Insert(offsetToRoot + i, new EmptyGate(new RegisterRefModel() { Register = register, Offset = i }));
                    }
                }
            }
        }
Exemplo n.º 12
0
        public void AddRegister(RegisterModel register)
        {
            // for parser, if registerModel is not null

            // update offset to Root
            int offsetChange = register.Qubits.Count;
            foreach (RegisterModel reg in _registers)
            {
                reg.IncrementOffset(offsetChange);
            }

            _registers.Add(register);

            foreach (StepModel step in Steps)
            {
                for (int i = 0; i < offsetChange; i++)
                {
                    step.Gates.Insert(i, new EmptyGate(new RegisterRefModel() { Register = register, Offset = i }));
                }
            }
        }
Exemplo n.º 13
0
 public override void IncrementRow(RegisterModel register, int afterOffset, int delta = 1)
 {
     if (_target.Register == register && _target.Offset > afterOffset)
     {
         _target.Offset += delta;
     }
     if (_control.Register == register && _control.Offset > afterOffset)
     {
         _control.Offset += delta;
     }
 }
Exemplo n.º 14
0
 public override void IncrementRow(RegisterModel register, int afterOffset, int delta = 1)
 {
     _targetRegister = incRegPart(_targetRegister, register, afterOffset, delta);
 }