/// <summary> /// Getting the probabilities of outcomes for a given circuit by simulating it. /// </summary> /// <param name="circuit">The quantum circuit which will be simulated.</param> /// <returns></returns> public override float[] GetProbabilities(QuantumCircuitFloat circuit) { //TODO Optimization re/abuse amplitude for probabilities? ComplexNumberFloat[] amplitudes = Simulate(circuit); return(base.GetProbabilities(amplitudes)); }
public void AddCircuit(QuantumCircuitFloat circuit) { if (circuit.NumberOfQubits > NumberOfQubits) { Debug.LogWarning("Number of qubits is bigger " + circuit.NumberOfQubits + " vs " + NumberOfQubits); NumberOfQubits = circuit.NumberOfQubits; ComplexNumberFloat[] newQubits = new ComplexNumberFloat[NumberOfQubits]; for (int i = 0; i < Amplitudes.Length; i++) { newQubits[i] = Amplitudes[i]; } for (int i = Amplitudes.Length; i < NumberOfQubits; i++) { newQubits[i] = circuit.Amplitudes[i]; } } //TODO different behavious when other is smaller? Gates.AddRange(circuit.Gates); }
/// <summary> /// Calculate the amplitude for a given circuit by simulating it directly in C# /// </summary> /// <param name="circuit">The quantum circuit which will be simulated</param> /// <returns></returns> public override ComplexNumberFloat[] Simulate(QuantumCircuitFloat circuit) { MathHelper.InitializePower2Values(circuit.NumberOfQubits + 2); ComplexNumberFloat[] amplitudes = base.Simulate(circuit); for (int i = 0; i < circuit.Gates.Count; i++) { GateFloat gate = circuit.Gates[i]; switch (gate.CircuitType) { case CircuitType.X: handleX(amplitudes, gate, circuit.NumberOfQubits); break; case CircuitType.RX: handleRX(amplitudes, gate, circuit.NumberOfQubits); break; case CircuitType.H: handleH(amplitudes, gate, circuit.NumberOfQubits); break; case CircuitType.CX: handleCX(amplitudes, gate, circuit.NumberOfQubits); break; case CircuitType.CRX: handleCRX(amplitudes, gate, circuit.NumberOfQubits); break; case CircuitType.M: handleM(amplitudes, gate, circuit.NumberOfQubits); break; default: break; } } return(amplitudes); }
public override void SimulateInPlace(QuantumCircuitFloat circuit, ref ComplexNumberFloat[] amplitudes) { //Check Length base.SimulateInPlace(circuit, ref amplitudes); MathHelper.InitializePower2Values(circuit.NumberOfQubits + 2); for (int i = 0; i < circuit.Gates.Count; i++) { GateFloat gate = circuit.Gates[i]; switch (gate.CircuitType) { case CircuitType.X: handleX(amplitudes, gate, circuit.NumberOfQubits); break; case CircuitType.RX: handleRX(amplitudes, gate, circuit.NumberOfQubits); break; case CircuitType.H: handleH(amplitudes, gate, circuit.NumberOfQubits); break; case CircuitType.CX: handleCX(amplitudes, gate, circuit.NumberOfQubits); break; case CircuitType.CRX: handleCRX(amplitudes, gate, circuit.NumberOfQubits); break; case CircuitType.M: handleM(amplitudes, gate, circuit.NumberOfQubits); break; default: break; } } }
/// <summary> /// Getting the probabilities of outcomes for a given circuit by simulating it. /// </summary> /// <param name="circuit">The quantum circuit which will be simulated.</param> /// <param name="probabilities">The probability array which will be filled.</param> /// <param name="amplitudes">The amplitude array needed for calculating the probabilities.</param> /// <returns></returns> public void CalculateProbabilities(QuantumCircuitFloat circuit, ref float[] probabilities, ref ComplexNumberFloat[] amplitudes) { //Trying to optimize not needing to return arrays SimulateInPlace(circuit, ref amplitudes); base.CalculateProbabilities(amplitudes, ref probabilities); }