/// <summary> /// OLD VERSION use the faster version instead. /// Getting a colored texture for given quantum circuits (each one representing 1 color channel of an image) directly without using python. /// Is faster than python versions but does not support logarithmic encoding yet and may still contain some errors. /// </summary> /// <param name="redCircuit">The quantum circuit which represents the red channel of the image.</param> /// <param name="greenCircuit">The quantum circuit which represents the green channel of the image.</param> /// <param name="blueCircuit">The quantum circuit which represents the blue channel of the image.</param> /// <param name="width">The width of the image</param> /// <param name="height">The height of the image</param> /// <param name="renormalize">If the image (colors) should be renormalized. (Giving it the highest possible saturation / becomes most light) </param> /// <param name="useLog">If logarithmic encoding is chosen DOES NOTHING (at the moment)</param> /// <returns>A texture showing the encoded image.</returns> public static Texture2D GetColoreTextureDirect(QuantumCircuit redCircuit, QuantumCircuit greenCircuit, QuantumCircuit blueCircuit, int width, int height, bool renormalize = false, bool useLog = false) { double[,] redData = QuantumImageHelper.CircuitToHeight2D(redCircuit, width, height, renormalize); double[,] greenData = QuantumImageHelper.CircuitToHeight2D(greenCircuit, width, height, renormalize); double[,] blueData = QuantumImageHelper.CircuitToHeight2D(blueCircuit, width, height, renormalize); return(QuantumImageHelper.CalculateColorTexture(redData, greenData, blueData)); }
/// <summary> /// Constructing a colored image from 3 quantumCircuits, 1 per channel, (which should represent a colored image). /// Used after image effect are applied to the image (the circuit) to get the modified picture /// </summary> /// <param name="redCircuit">The circuit representing the red color channel of the (modified) image.</param> /// <param name="greenCircuit">The circuit representing the green color channel of the (modified) image</param> /// <param name="blueCircuit">The circuit representing the blue color channel of the (modified) image</param> /// <param name="useLog">If logarithmic decoding should be used to decode the image.</param> /// <returns></returns> public Texture2D GetColoreTexture(QuantumCircuit redCircuit, QuantumCircuit greenCircuit, QuantumCircuit blueCircuit, bool useLog = false) { MicroQiskitSimulator simulator = new MicroQiskitSimulator(); //TODO OPTIMIZATIOn initialize arrays only once double[] doubleArray = new double[0]; string[] stringArray = new string[0]; QuantumImageHelper.GetProbabilityArrays(simulator.GetProbabilities(redCircuit), redCircuit.NumberOfQubits, ref doubleArray, ref stringArray); IronPython.Runtime.PythonDictionary redDictionary = pythonFile.HeightFromProbabilities(stringArray, doubleArray, doubleArray.Length, redCircuit.DimensionString, useLog); QuantumImageHelper.GetProbabilityArrays(simulator.GetProbabilities(greenCircuit), greenCircuit.NumberOfQubits, ref doubleArray, ref stringArray); IronPython.Runtime.PythonDictionary greenDictionary = pythonFile.HeightFromProbabilities(stringArray, doubleArray, doubleArray.Length, greenCircuit.DimensionString, useLog); QuantumImageHelper.GetProbabilityArrays(simulator.GetProbabilities(blueCircuit), blueCircuit.NumberOfQubits, ref doubleArray, ref stringArray); IronPython.Runtime.PythonDictionary blueDictionary = pythonFile.HeightFromProbabilities(stringArray, doubleArray, doubleArray.Length, blueCircuit.DimensionString, useLog); return(QuantumImageHelper.CalculateColorTexture(redDictionary, greenDictionary, blueDictionary, redCircuit.DimensionString)); }
/// <summary> /// A slightly faster version to construct a colored image from 3 quantumCircuits, 1 per channel, (which should represent a colored image). /// Used after image effect are applied to the image (the circuit) to get the modified picture /// This version should produce less garbage, however, it only makes a small difference, since the python part is the same (and the slow part) /// </summary> /// <param name="redCircuit">The circuit representing the red color channel of the (modified) image.</param> /// <param name="greenCircuit">The circuit representing the green color channel of the (modified) image</param> /// <param name="blueCircuit">The circuit representing the blue color channel of the (modified) image</param> /// <param name="useLog">If logarithmic decoding should be used to decode the image.</param> /// <returns></returns> public Texture2D GetColoreTextureFast(QuantumCircuit redCircuit, QuantumCircuit greenCircuit, QuantumCircuit blueCircuit, bool useLog = false) { MicroQiskitSimulator simulator = new MicroQiskitSimulator(); //Trying optimazations (less garbage). Negative side is we need the full arrays // TODO make circuit initialization better double[] probabilities = new double[MathHelper.IntegerPower(2, redCircuit.NumberOfQubits)]; ComplexNumber[] amplitudes = null; string[] stringArray = QuantumImageHelper.CalculateNameStrings(probabilities.Length, redCircuit.NumberOfQubits); simulator.CalculateProbabilities(redCircuit, ref probabilities, ref amplitudes); IronPython.Runtime.PythonDictionary redDictionary = pythonFile.HeightFromProbabilities(stringArray, probabilities, probabilities.Length, redCircuit.DimensionString, useLog); simulator.CalculateProbabilities(greenCircuit, ref probabilities, ref amplitudes); IronPython.Runtime.PythonDictionary greenDictionary = pythonFile.HeightFromProbabilities(stringArray, probabilities, probabilities.Length, greenCircuit.DimensionString, useLog); simulator.CalculateProbabilities(blueCircuit, ref probabilities, ref amplitudes); IronPython.Runtime.PythonDictionary blueDictionary = pythonFile.HeightFromProbabilities(stringArray, probabilities, probabilities.Length, blueCircuit.DimensionString, useLog); return(QuantumImageHelper.CalculateColorTexture(redDictionary, greenDictionary, blueDictionary, redCircuit.DimensionString)); }
/// <summary> /// Getting a colored texture for given quantum circuits (each one representing 1 color channel of an image) directly without using python. /// Fast version is a lot faster than python versions but does not support logarithmic encoding yet and may still contain some errors. /// </summary> /// <param name="redCircuit">The quantum circuit which represents the red channel of the image.</param> /// <param name="greenCircuit">The quantum circuit which represents the green channel of the image.</param> /// <param name="blueCircuit">The quantum circuit which represents the blue channel of the image.</param> /// <param name="width">The width of the image</param> /// <param name="height">The height of the image</param> /// <param name="renormalize">If the image (colors) should be renormalized. (Giving it the highest possible saturation / becomes most light) </param> /// <param name="useLog">If logarithmic encoding is chosen DOES NOTHING (at the moment)</param> /// <returns>A texture showing the encoded image.</returns> public static Texture2D GetColoreTextureDirectFast(QuantumCircuitFloat redCircuit, QuantumCircuitFloat greenCircuit, QuantumCircuitFloat blueCircuit, int width, int height, bool renormalize = false, bool useLog = false) { return(QuantumImageHelper.CalculateColorTexture(redCircuit, greenCircuit, blueCircuit, width, height, renormalize)); }