예제 #1
0
        void IIntrinsicExp.Body(IQArray <Pauli> paulis, double angle, IQArray <Qubit> targets)
        {
            this.CheckQubits(targets);
            CheckAngle(angle);

            if (paulis.Length != targets.Length)
            {
                throw new InvalidOperationException($"Both input arrays for Exp (paulis, targets), must be of same size.");
            }

            Exp(this.Id, (uint)paulis.Length, paulis.ToArray(), angle, targets.GetIds());
        }
예제 #2
0
 static void SafeControlled(IQArray <Qubit> ctrls, Action noControlsAction, Action <uint, uint[]> controlledAction)
 {
     if (ctrls == null || ctrls.Length == 0)
     {
         noControlsAction();
     }
     else
     {
         uint count = (uint)ctrls.Length;
         controlledAction(count, ctrls.GetIds());
     }
 }
예제 #3
0
 /// <summary>
 /// Entry method to get the dump of the wave function.
 /// </summary>
 public virtual bool Dump(IQArray <Qubit> qubits = null)
 {
     if (qubits == null)
     {
         sim_Dump(Simulator.Id, Callback);
         return(true);
     }
     else
     {
         var ids = qubits.GetIds();
         return(sim_DumpQubits(Simulator.Id, (uint)ids.Length, ids, Callback));
     }
 }
예제 #4
0
 Result IIntrinsicMeasure.Body(IQArray <Pauli> paulis, IQArray <Qubit> targets)
 {
     this.CheckQubits(targets);
     if (paulis.Length != targets.Length)
     {
         throw new InvalidOperationException($"Both input arrays for Measure (paulis, targets), must be of same size");
     }
     if (targets.Length == 1)
     {
         // When we are operating on a single qubit we will collapse the state, so mark
         // that qubit as measured.
         targets[0].IsMeasured = true;
     }
     return(Measure(this.Id, (uint)paulis.Length, paulis.ToArray(), targets.GetIds()).ToResult());
 }
예제 #5
0
        void IIntrinsicExp.ControlledBody(IQArray <Qubit> controls, IQArray <Pauli> paulis, double angle, IQArray <Qubit> targets)
        {
            this.CheckQubits(controls, targets);
            CheckAngle(angle);

            if (paulis.Length != targets.Length)
            {
                throw new InvalidOperationException($"Both input arrays for Exp (paulis, qubits), must be of same size.");
            }

            SafeControlled(controls,
                           () => ((IIntrinsicExp)this).Body(paulis, angle, targets),
                           (count, ids) => MCExp(this.Id, (uint)paulis.Length, paulis.ToArray(), angle, count, ids, targets.GetIds()));
        }
예제 #6
0
        void IIntrinsicIsingZZ.ControlledBody(IQArray <Qubit> controls, double angle, Qubit target1, Qubit target2)
        {
            if (controls == null || controls.Length == 0)
            {
                ((IIntrinsicIsingZZ)this).Body(angle, target1, target2);
            }
            else
            {
                var targets = new QArray <Qubit>(new Qubit[] { target1, target2 });
                var paulis  = new Pauli[] { Pauli.PauliZ, Pauli.PauliZ };
                CheckAngle(angle);
                this.CheckQubits(QArray <Qubit> .Add(controls, targets));

                MCExp(this.Id, (uint)targets.Length, paulis, angle * 2.0, (uint)controls.Length, controls.GetIds(), targets.GetIds());
            }
        }
예제 #7
0
        public virtual void IsingXX__ControlledBody(IQArray <Qubit> controls, double angle, Qubit target1, Qubit target2)
        {
            if (controls == null || controls.Length == 0)
            {
                IsingXX__Body(angle, target1, target2);
            }
            else
            {
                var targets = new QArray <Qubit>(new Qubit[] { target1, target2 });
                var paulis  = new Pauli[] { Pauli.PauliX, Pauli.PauliX };
                CheckAngle(angle);
                this.CheckQubits(QArray <Qubit> .Add(controls, targets));

                MCExp(this.Id, (uint)targets.Length, paulis, angle * 2.0, (uint)controls.Length, controls.GetIds(), targets.GetIds());
            }
        }
예제 #8
0
 public virtual void Ry__ControlledBody(IQArray <Qubit> controls, double angle, Qubit target)
 {
     this.CheckQubits(controls, target);
     CheckAngle(angle);
     MCR(this.Id, Pauli.PauliY, angle, (uint)controls.Length, controls.GetIds(), (uint)target.Id);
 }
예제 #9
0
 void IIntrinsicRx.ControlledBody(IQArray <Qubit> controls, double angle, Qubit target)
 {
     this.CheckQubits(controls, target);
     CheckAngle(angle);
     MCR(this.Id, Pauli.PauliX, angle, (uint)controls.Length, controls.GetIds(), (uint)target.Id);
 }