Exemple #1
0
        /// <summary>
        /// Getting a grey scale texture for a given quantum circuit (which should represent 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="quantumCircuit">The quantum circuit with the grey scale image representation</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 GetGreyTextureDirect(QuantumCircuit quantumCircuit, int width, int height, bool renormalize = false, bool useLog = false)
        {
            //TODO Make version with only floats (being faster needing less memory)
            double[,] imageData = QuantumImageHelper.CircuitToHeight2D(quantumCircuit, width, height, renormalize);

            return(QuantumImageHelper.CalculateGreyTexture(imageData));
        }
Exemple #2
0
        public QuantumCircuitFloat(QuantumCircuit circuit)
        {
            Gates           = new List <GateFloat>();
            NumberOfQubits  = circuit.NumberOfQubits;
            NumberOfOutputs = circuit.NumberOfOutputs;
            AmplitudeLength = circuit.AmplitudeLength;

            Amplitudes = new ComplexNumberFloat[circuit.AmplitudeLength];

            for (int i = 0; i < circuit.Amplitudes.Length; i++)
            {
                if (circuit.Amplitudes[i].Real > 0)
                {
                    Amplitudes[i].Real = (float)circuit.Amplitudes[i].Real;
                }
                if (circuit.Amplitudes[i].Complex > 0)
                {
                    Amplitudes[i].Complex = (float)circuit.Amplitudes[i].Complex;
                }
            }

            for (int i = 0; i < circuit.Gates.Count; i++)
            {
                Gate      gate      = circuit.Gates[i];
                GateFloat floatGate = new GateFloat();
                floatGate.CircuitType = gate.CircuitType;
                floatGate.First       = gate.First;
                floatGate.Second      = gate.Second;
                if (gate.Theta != 0)
                {
                    floatGate.Theta = (float)gate.Theta;
                }
                Gates.Add(floatGate);
            }
        }
Exemple #3
0
        /// <summary>
        /// Directly creates a blured image out of the greyscale input texture using the quantum blur algorithm.
        /// The blur is done via rotating qubits (in radian). Supports logarithmic encoding.
        /// </summary>
        /// <param name="inputTexture">The image on which the blur should be applied.</param>
        /// <param name="rotation">The rotation which should be applied in radian.</param>
        /// <param name="useLog">If logarithmic encoding (and decoding) should be used</param>
        /// <param name="useDifferentDecoding">If the decoding used should be not the same as the encoding (for example if you only want to sue logarithmic decoding)</param>
        /// <param name="doFast">If the (most of the time) faster creation of color image should be used.</param>
        /// <returns></returns>
        public Texture2D CreateBlurTextureColor(Texture2D inputTexture, float rotation, bool useLog = false, bool useDifferentDecoding = false, bool doFast = false)
        {
            Texture2D OutputTexture;

            double[,] imageData = QuantumImageHelper.GetRedHeightArray(inputTexture);
            QuantumCircuit redCircuit = getBlurCircuitFromData(imageData, rotation, useLog);

            QuantumImageHelper.FillGreenHeighArray(inputTexture, imageData);
            QuantumCircuit greenCircuit = getBlurCircuitFromData(imageData, rotation, useLog);

            QuantumImageHelper.FillBlueHeighArray(inputTexture, imageData);
            QuantumCircuit blueCircuit = getBlurCircuitFromData(imageData, rotation, useLog);

            if (useDifferentDecoding)
            {
                useLog = !useLog;
            }

            if (doFast)
            {
                OutputTexture = GetColoreTextureFast(redCircuit, greenCircuit, blueCircuit, useLog);
            }
            else
            {
                OutputTexture = GetColoreTexture(redCircuit, greenCircuit, blueCircuit, useLog);
            }

            return(OutputTexture);
        }
Exemple #4
0
 /// <summary>
 /// Applies the controlled partial rotation (in radian) to some of the qubits of the quantum circuit. The controlqubits decide if the gate is applied to the targetqubits.
 /// With the normal settings it is applied to half the qubits
 /// </summary>
 /// <param name="circuit">The quantum circuit to which the rotation is applied</param>
 /// <param name="rotation">The applied rotation. Rotation is in radian (so 2PI is a full rotation)</param>
 /// <param name="modulo">Defines the fraction of qubits to which the operation is applied if a high enough number is chosen it is only applied to a single qubit</param>
 /// <param name="reminderControl">Defines which elements are the control qubits. (Goes from 0 to modulo-1)</param>
 /// <param name="reminderTarget">Defines which elements are the target qubits. (Goes from 0 to modulo-1)</param>
 public static void ApplyControledQtoFraction(QuantumCircuit circuit, float rotation, int modulo = 2, int reminderControl = 0, int reminderTarget = 1)
 {
     for (int i = 0; i < circuit.NumberOfQubits; i += modulo)
     {
         circuit.CRX(i + reminderControl, i + reminderTarget, rotation);
     }
 }
Exemple #5
0
        public virtual ComplexNumber[] Simulate(QuantumCircuit circuit)
        {
            double sum = circuit.ProbabilitySum();

            if (sum > MathHelper.Eps)
            {
                if (sum < 1 - MathHelper.Eps || sum > 1 + MathHelper.Eps)
                {
                    circuit.Normalize(sum);
                }

                ComplexNumber[] amplitudes = new ComplexNumber[circuit.AmplitudeLength];

                for (int i = 0; i < amplitudes.Length; i++)
                {
                    amplitudes[i] = circuit.Amplitudes[i];
                }
                return(amplitudes);
            }
            else
            {
                //Initialize the all 0 vector
                ComplexNumber[] amplitudes = new ComplexNumber[circuit.AmplitudeLength];
                amplitudes[0].Real = 1;
                return(amplitudes);
            }
        }
Exemple #6
0
 /// <summary>
 /// Applies a partial rotation (in radian) to each qubit of a quantum circuit.
 /// </summary>
 /// <param name="circuit">The quantum circuit to which the rotation is applied</param>
 /// <param name="rotation">The applied rotation. Rotation is in radian (so 2PI is a full rotation)</param>
 public static void ApplyPartialQ(QuantumCircuit circuit, float rotation)
 {
     for (int i = 0; i < circuit.NumberOfQubits; i++)
     {
         circuit.RX(i, rotation);
     }
 }
Exemple #7
0
 /// <summary>
 /// Applies the controlled not gate to some of the qubits of the quantum circuit. The controlqubits decide if the not is applied to the targetqubits.
 /// With the normal settings it is applied to half the qubits
 /// </summary>
 /// <param name="circuit">The quantum circuit to which the Hadamar gates are applied</param>
 /// <param name="modulo">Defines the fraction of qubits to which the operation is applied if a high enough number is chosen it is only applied to a single qubit</param>
 /// <param name="reminderControl">Defines which elements are the control qubits. (Goes from 0 to modulo-1)</param>
 /// <param name="reminderTarget">Defines which elements are the target qubits. (Goes from 0 to modulo-1)</param>
 public static void ApplyControlledNotToFraction(QuantumCircuit circuit, int modulo = 2, int reminderControl = 0, int reminderTarget = 1)
 {
     for (int i = 0; i < circuit.NumberOfQubits; i += modulo)
     {
         circuit.CX(i + reminderControl, i + reminderTarget);
     }
 }
Exemple #8
0
    /// <summary>
    /// A placeholder for creating your own image effect. Keep it static this way you can use it for mesh creation
    /// </summary>
    /// <param name="inputTexture">The Texture of which one wants a blurred image</param>
    /// <returns>A texture with your own image effect applied</returns>
    public static Texture2D CalculateMyOwnEffect(Texture2D inputTexture, float parameter1 = 0, float parameter2 = 0, float parameter3 = 0)
    {
        Texture2D outputTexture;

        // Since we do not need python we do not need to intialize the creator and we can use the static functions of the QuantumImageCreator

        //generating the quantum circuits encoding the color channels of the image
        QuantumCircuit red   = QuantumImageCreator.GetCircuitDirect(inputTexture, ColorChannel.R);
        QuantumCircuit green = QuantumImageCreator.GetCircuitDirect(inputTexture, ColorChannel.G);
        QuantumCircuit blue  = QuantumImageCreator.GetCircuitDirect(inputTexture, ColorChannel.B);

        //Add your own quantum circuit manipulation here!
        //You can use the functions in the region "Effects" bellow

        //ApplyHadamar(red,7);
        //ApplyHadamar(green,7);
        //ApplyHadamar(blue,7);

        //ApplyControlledNotToFraction(red,4);
        //ApplyControlledNotToFraction(green,4);
        //ApplyControlledNotToFraction(blue,4);

        //ApplyControledQtoFraction(red, 0.25f);
        //ApplyControledQtoFraction(green, 0.25f);
        //ApplyControledQtoFraction(blue, 0.25f);

        //Generating the texture after the quantum circuits were modified.
        outputTexture = QuantumImageCreator.GetColoreTextureDirect(red, green, blue, inputTexture.width, inputTexture.height);

        return(outputTexture);
    }
Exemple #9
0
        public virtual void SilumateInPlace(QuantumCircuit circuit, ref ComplexNumber[] amplitudes)
        {
            int length = circuit.AmplitudeLength;

            if (amplitudes == null || amplitudes.Length != length)
            {
                //Post message
                amplitudes = new ComplexNumber[length];
            }

            double sum = circuit.ProbabilitySum();

            //if
            if (sum > MathHelper.Eps)
            {
                if (sum < 1 - MathHelper.Eps || sum > 1 + MathHelper.Eps)
                {
                    circuit.Normalize(sum);
                }

                for (int i = 0; i < amplitudes.Length; i++)
                {
                    amplitudes[i] = circuit.Amplitudes[i];
                }
            }
            else
            {
                //Initialize the all 0 vector
                amplitudes[0].Real = 1;
            }
        }
Exemple #10
0
        IronPython.Runtime.PythonDictionary getTeleportDictionaryFromData(out string heightDimensions, double[,] imageData, double[,] imageData2, double mixture, double normalization = 0, bool useLog = false)
        {
            dynamic teleportationHelper = pythonFile.TeleportationHelper("TeleportationHelper");

            bool normalizeManually = normalization > 0;

            teleportationHelper.SetHeights(imageData, imageData2, imageData.GetLength(0), imageData.GetLength(1));
            teleportationHelper.ApplySwap(mixture, useLog, normalizeManually);
            dynamic circuit = teleportationHelper.GetCircuit();


            int numberofQubits = circuit.num_qubits;

            heightDimensions = circuit.name;

            QuantumCircuit       quantumCircuit = QuantumImageHelper.ParseCircuit(circuit.data, numberofQubits);
            MicroQiskitSimulator simulator      = new MicroQiskitSimulator();

            quantumCircuit.Normalize();

            double[] doubleArray = new double[0];
            string[] stringArray = new string[0];

            double[] probs = simulator.GetProbabilities(quantumCircuit);


            QuantumImageHelper.GetProbabilityArrays(probs, numberofQubits, ref doubleArray, ref stringArray);

            IronPython.Runtime.PythonDictionary dictionary = pythonFile.CombinedHeightFromProbabilities(stringArray, doubleArray, doubleArray.Length, numberofQubits, heightDimensions, useLog, normalization);
            return(dictionary);
        }
Exemple #11
0
 //A simple quantumBlur is applied to the circuit
 void applyPartialQ(QuantumCircuit circuit, float rotation)
 {
     for (int i = 0; i < circuit.NumberOfQubits; i++)
     {
         //Making a "blur" effect by applying a (small) rotation to each qubit.
         circuit.RX(i, rotation);
     }
 }
        private static void PlusState()
        {
            QuantumRegister register = new QuantumRegister(1);
            QuantumCircuit  circuit  = new QuantumCircuit(register);

            circuit.H(0);
            Console.WriteLine("PlusState Result: " + register[0].IsPlus);
        }
        private static void UnequalSuperposition()
        {
            QuantumRegister register = new QuantumRegister(1);
            QuantumCircuit  circuit  = new QuantumCircuit(register);

            circuit.Rx(0, 1.78);
            Console.WriteLine("Superposition State: " + (register[0].QState == QubitState.Superposition));
        }
Exemple #14
0
        /// <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));
        }
Exemple #15
0
        public static double[,] CircuitToHeight2D(QuantumCircuit circuit, int width, int height, bool renormalize = false)
        {
            double[,] heights2D = new double[width, height];

            int widthLog  = Mathf.CeilToInt(Mathf.Log(width) / Mathf.Log(2));
            int heightLog = widthLog;

            int[] widthLines  = MakeLinesInt(widthLog);
            int[] heightLines = widthLines;

            if (height != width)
            {
                heightLog   = Mathf.CeilToInt(Mathf.Log(height) / Mathf.Log(2));
                heightLines = MakeLinesInt(heightLog);
            }

            MicroQiskitSimulator simulator = new MicroQiskitSimulator();

            double[] probs = simulator.GetProbabilities(circuit);

            int length = heights2D.Length;


            double normalization = 0;

            if (!renormalize && circuit.OriginalSum > 0)
            {
                normalization = circuit.OriginalSum;
            }
            else
            {
                for (int i = 0; i < width; i++)
                {
                    for (int j = 0; j < height; j++)
                    {
                        int pos = widthLines[i] * height + heightLines[j];
                        if (probs[pos] > normalization)
                        {
                            normalization = probs[pos];
                        }
                    }
                }
                normalization = 1.0 / normalization;
            }

            int posX = 0;

            for (int i = 0; i < width; i++)
            {
                posX = widthLines[i] * height;
                for (int j = 0; j < height; j++)
                {
                    heights2D[i, j] = probs[posX + heightLines[j]] * normalization;
                }
            }

            return(heights2D);
        }
 /// <summary>
 /// Applies a Hadamar gate to some ot the qubits of a quantum circuit. With normal parameters it will be applied to half
 /// </summary>
 /// <param name="circuit">The quantum circuit to which the Hadamar gates are applied</param>
 /// <param name="modulo">Defines the fraction of qubits to which the operation is applied if a high enough number is chosen it is only applied to a single qubit</param>
 /// <param name="reminder">Defines to which elements the operation is applied. (Goes from 0 to modulo-1)</param>
 public static void ApplyHadamarToFraction(QuantumCircuit circuit, int modulo = 2, int reminder = 0)
 {
     for (int i = 0; i < circuit.NumberOfQubits; i++)
     {
         if (i % modulo == reminder)
         {
             circuit.H(i);
         }
     }
 }
 /// <summary>
 /// Applies a partial rotation (in radian) to some ot the qubits of a quantum circuit. With normal parameters it will be applied to half
 /// </summary>
 /// <param name="circuit">The quantum circuit to which the rotation is applied</param>
 /// <param name="rotation">The applied rotation. Rotation is in radian (so 2PI is a full rotation)</param>
 /// <param name="modulo">Defines the fraction of qubits to which the operation is applied if a high enough number is chosen it is only applied to a single qubit</param>
 /// <param name="reminder">Defines to which elements the operation is applied. (Goes from 0 to modulo-1)</param>
 public static void ApplyPartialQToFraction(QuantumCircuit circuit, float rotation, int modulo = 2, int reminder = 0)
 {
     for (int i = 0; i < circuit.NumberOfQubits; i++)
     {
         if (i % modulo == reminder)
         {
             circuit.RX(i, rotation);
         }
     }
 }
        QuantumCircuit getBlurCircuitFromData(double[,] imageData, float rotation, bool useLog = false)
        {
            blurHelper.SetHeights(imageData, imageData.GetLength(0), imageData.GetLength(1), useLog);
            //Applying rotation
            blurHelper.ApplyPartialX(rotation);
            dynamic circuit = blurHelper.GetCircuit();

            QuantumCircuit quantumCircuit = QuantumImageHelper.ParseCircuit(circuit.data, circuit.num_qubits, circuit.name);

            return(quantumCircuit);
        }
 /// <summary>
 /// Applies a Hadamar gate to the specified qubit of a quantum circuit.
 /// </summary>
 /// <param name="circuit">The quantum circuit to which the Hadamar gate is applied</param>
 public static void ApplyHadamar(QuantumCircuit circuit, int qubit = 0)
 {
     if (circuit.NumberOfQubits > qubit)
     {
         circuit.H(qubit);
     }
     else
     {
         circuit.H(0);
     }
 }
Exemple #20
0
    public Texture2D CircuitToTexture()
    {
        Texture2D outPutTexture;

        //generating the quantum circuits encoding the color channels of the image

        QuantumCircuit red;

        //QuantumCircuit green;
        //QuantumCircuit blue;


        double[,] imageData = QuantumImageHelper.GetHeightArrayDouble(startTexture, ColorChannel.R);
        if (UseSimpleEncoding)
        {
            red = QuantumImageHelper.ImageToCircuit(imageData);
        }
        else
        {
            red = QuantumImageHelper.HeightToCircuit(imageData);
        }


        Circuit = red;


        red.Gates = Gates;
        //blue.Gates = Gates;
        //green.Gates = Gates;

        double[,] redData;//,  greenData, blueData;

        if (UseSimpleEncoding)
        {
            redData = QuantumImageHelper.CircuitToImage(red, size, size, RenormalizeImage);
            //greenData = QuantumImageHelper.CircuitToImage(green, size, size);
            //blueData = QuantumImageHelper.CircuitToImage(blue, size, size);
        }
        else
        {
            redData = QuantumImageHelper.CircuitToHeight2D(red, size, size, RenormalizeImage);
            //greenData = QuantumImageHelper.CircuitToHeight2D(green, size, size);
            //blueData = QuantumImageHelper.CircuitToHeight2D(blue, size, size);
        }

        //outPutTexture = QuantumImageHelper.CalculateColorTexture(redData, greenData, blueData);
        outPutTexture            = QuantumImageHelper.CalculateColorTexture(redData, redData, redData, PaintColor.r, PaintColor.g, PaintColor.b);
        outPutTexture.filterMode = FilterMode.Point;
        outPutTexture.wrapMode   = TextureWrapMode.Clamp;
        QiskitString             = red.GetQiskitString(true);

        return(outPutTexture);
    }
        /// <summary>
        /// Constructing a greyscale image from a single quantumCircuit (which should represent a greyscale image).
        /// Used after image effect are applied to the image (the circuit) to get the modified picture.
        /// </summary>
        /// <param name="quantumCircuit">The circuit representing the (modified) image.</param>
        /// <param name="useLog">If logarithmic decoding should be used to decode the image.</param>
        /// <returns></returns>
        public Texture2D GetGreyTexture(QuantumCircuit quantumCircuit, bool useLog = false)
        {
            MicroQiskitSimulator simulator = new MicroQiskitSimulator();

            double[] doubleArray = new double[0];
            string[] stringArray = new string[0];

            QuantumImageHelper.GetProbabilityArrays(simulator.GetProbabilities(quantumCircuit), quantumCircuit.NumberOfQubits, ref doubleArray, ref stringArray);
            IronPython.Runtime.PythonDictionary dictionary = pythonFile.HeightFromProbabilities(stringArray, doubleArray, doubleArray.Length, quantumCircuit.DimensionString, useLog);

            return(QuantumImageHelper.CalculateGreyTexture(dictionary, quantumCircuit.DimensionString));
        }
    private void TestHGate28Q()
    {
        QuantumCircuit qc = new QuantumCircuit(28);

        qc.Apply(Gates.H(0));

        System.DateTime t = System.DateTime.Now;
        qc.Apply(Gates.H(0));
        Debug.Log($"H: {(System.DateTime.Now - t).TotalMilliseconds / 1000f}s");

        StateVector sv = qc.stateVector;
    }
        public static void Run()
        {
            Console.WriteLine("Running Teleportation example.");
            //Create a register with 2 Qubits
            QuantumRegister register = new QuantumRegister(2);

            //Create a blank circuit with the regiter initialised
            QuantumCircuit circuit = new QuantumCircuit(register);

            //Initialize the tranported counter
            int transported = 0;

            //Let try to teleport 25 quantum information
            for (int i = 0; i < 25; i++)
            {
                var send = GetRandom();

                //Initial the first Qubit with the particle to be teleported
                circuit.INIT(0, send);

                //Hadamard gate to apply superposition to the first quantum bit which means the first qubit will have both 0 and 1
                circuit.H(0);

                //Controlled not gate to entangle the two qubit
                circuit.CNOT(0, 1);

                //Measure the first will collapse the quantum state and bring it to reality which will be either one or zero
                circuit.Measure(0);

                //Store the first state
                var res1 = register[0].QState;

                //Now measue the second particle and store the value
                circuit.Measure(1);
                var res2 = register[1].QState;

                Console.WriteLine("Send: {0}, Received: {1}", res1, res2);

                //If you compare the result the two result will be same which states that the information is teleported.
                if (res1 == res2)
                {
                    transported++;
                }

                register.Reset();
            }

            Console.WriteLine("Teleported count: " + transported);

            Console.WriteLine("Running Teleportation example.---- done\n");
        }
Exemple #24
0
        public static void TextureToColorCircuit(Texture2D inputTexture, out QuantumCircuit redCircuit, out QuantumCircuit greenCircuit, out QuantumCircuit blueCircuit, bool useLog = false)
        {
            int width  = inputTexture.width;
            int height = inputTexture.height;


            int dimX = Mathf.CeilToInt(Mathf.Log(width) / Mathf.Log(2));

            int[] linesWidth = MakeLinesInt(dimX);

            int dimY = dimX;

            int[] linesHeight = linesWidth;

            if (width != height)
            {
                dimY        = Mathf.CeilToInt(Mathf.Log(height) / Mathf.Log(2));
                linesHeight = MakeLinesInt(dimY);
            }

            int maxHeight      = MathHelper.IntegerPower(2, dimY);
            int numberOfQubits = dimX + dimY;

            redCircuit   = new QuantumCircuit(numberOfQubits, numberOfQubits, true);
            greenCircuit = new QuantumCircuit(numberOfQubits, numberOfQubits, true);
            blueCircuit  = new QuantumCircuit(numberOfQubits, numberOfQubits, true);


            Color color;
            int   index;
            int   posX;

            for (int x = 0; x < width; x++)
            {
                posX = linesWidth[x] * maxHeight;
                for (int y = 0; y < height; y++)
                {
                    index = posX + linesHeight[y];
                    color = inputTexture.GetPixel(x, y);

                    redCircuit.Amplitudes[index].Real   = Math.Sqrt(color.r);
                    greenCircuit.Amplitudes[index].Real = Math.Sqrt(color.g);
                    blueCircuit.Amplitudes[index].Real  = Math.Sqrt(color.b);
                }
            }

            redCircuit.Normalize();
            greenCircuit.Normalize();
            blueCircuit.Normalize();
        }
        /// <summary>
        /// Directly creates a blured image out of the greyscale input texture using the quantum blur algorithm.
        /// The blur is done via rotating qubits (in radian). Supports logarithmic encoding.
        /// </summary>
        /// <param name="inputTexture">The image on which the blur should be applied.</param>
        /// <param name="rotation">The rotation which should be applied in radian.</param>
        /// <param name="useLog">If logarithmic encoding (and decoding) should be used</param>
        /// <param name="useDifferentDecoding">If the decoding used should be not the same as the encoding (for example if you only want to sue logarithmic decoding)</param>
        /// <returns></returns>
        public Texture2D CreateBlurTextureGrey(Texture2D inputTexture, float rotation, bool useLog = false, bool useDifferentDecoding = false)
        {
            Texture2D OutputTexture;

            double[,] imageData = QuantumImageHelper.GetGreyHeighArray(inputTexture);
            QuantumCircuit quantumCircuit = getBlurCircuitFromData(imageData, rotation, useLog);

            if (useDifferentDecoding)
            {
                useLog = !useLog;
            }

            OutputTexture = GetGreyTexture(quantumCircuit, useLog);
            return(OutputTexture);
        }
Exemple #26
0
    //Simple example to generate the 2 qubit state of a bell pair
    public void GenerateBellPair()
    {
        QuantumCircuit circuit = new QuantumCircuit(2, 2);

        MicroQiskitSimulator simulator = new MicroQiskitSimulator();

        circuit.H(0);
        circuit.CX(0, 1);

        double[] probabilities = simulator.GetProbabilities(circuit);

        Console.WriteLine("The probability to measure 00 is: " + probabilities[0]);
        Console.WriteLine("The probability to measure 01 is: " + probabilities[1]);
        Console.WriteLine("The probability to measure 10 is: " + probabilities[2]);
        Console.WriteLine("The probability to measure 11 is: " + probabilities[3]);
    }
Exemple #27
0
        public void NewQCStateVectorLengthTest()
        {
            // Arrange
            QuantumCircuit qc;
            int            expectLenght = 4;

            // Act
            qc = new QuantumCircuit(2);
            int actualLenght = qc.stateVector.length;

            // Assert
            Assert.IsTrue(expectLenght == actualLenght,
                          $"Initial QuantumCircuit with 2 qubit has a StateVector length, " +
                          $"expected {expectLenght}" +
                          $"but found {actualLenght}.");
        }
    private void TestHGate10Q()
    {
        QuantumCircuit qc = new QuantumCircuit(10);

        qc.Apply(Gates.H(0));

        const int it = 100;

        System.DateTime t = System.DateTime.Now;
        for (int i = 0; i < it; i++)
        {
            qc.Apply(Gates.H(0));
        }
        Debug.Log($"H: {(System.DateTime.Now - t).TotalMilliseconds / it}ms");

        StateVector sv = qc.stateVector;
    }
Exemple #29
0
        public static QuantumCircuit HeightToCircuit(float[] height)
        {
            int numberOfQubits = Mathf.CeilToInt(Mathf.Log(height.Length) / Mathf.Log(2));

            int[] lines = MakeLinesInt(numberOfQubits);

            QuantumCircuit circuit = new QuantumCircuit(numberOfQubits, numberOfQubits, true);

            int length = height.Length;

            for (int i = 0; i < length; i++)
            {
                circuit.Amplitudes[lines[i]].Real = Math.Sqrt(height[i]);
            }

            circuit.Normalize();
            return(circuit);
        }
    private void TestH0Gate()
    {
        QuantumCircuit qc = new QuantumCircuit(3);

        System.DateTime t = System.DateTime.Now;
        qc.Apply(Gates.H(0));
        Debug.Log($"H: {(System.DateTime.Now - t).TotalMilliseconds / 1000f}s");

        StateVector sv = qc.stateVector;

        string s = "";

        for (int i = 0; i < sv.length; i++)
        {
            s += $"[{sv[i].Real:N2} :: {sv[i].Imaginary:N2}i]\n";
        }
        Debug.Log(s);
    }