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()); }
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()); } }
/// <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)); } }
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()); }
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())); }
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()); } }
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()); } }
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); }
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); }