コード例 #1
0
        /// <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 double[] GetProbabilities(QuantumCircuit circuit)
        {
            //TODO Optimization re/abuse amplitude for probabilities?

            ComplexNumber[] amplitudes = Simulate(circuit);
            return(base.GetProbabilities(amplitudes));
        }
コード例 #2
0
ファイル: QiskitSimulator.cs プロジェクト: degerli/QCU
        public string RunPythonFile(QuantumCircuit circuit)  //, ref double[] probabilities) {
        {
            Process process    = new Process();
            string  pythonPath = Application.streamingAssetsPath + pythonEXE;
            string  filePath   = Application.streamingAssetsPath + pythonScripts + exchange + pythonFileName;

            Debug.Log("reading pythonfile from: " + pythonPath);
            //Debug.Log("filePath is: " + filePath);


            process.StartInfo.FileName       = pythonPath;
            process.StartInfo.Arguments      = filePath;
            process.StartInfo.WindowStyle    = ProcessWindowStyle.Hidden;
            process.StartInfo.CreateNoWindow = true;

            process.StartInfo.UseShellExecute        = false;
            process.StartInfo.RedirectStandardOutput = true;

            process.Start();

            StreamReader reader = process.StandardOutput;
            string       output = reader.ReadToEnd();

            //UnityEngine.Debug.Log(output);

            process.WaitForExit();
            UnityEngine.Debug.Log(process.ExitCode);
            process.Close();
            return(output);
            //ReadProbabilities(ref probabilities, output);
        }
コード例 #3
0
ファイル: QiskitSimulator.cs プロジェクト: VoicuTomut/QCU
        public void WritePythonFile(QuantumCircuit circuit)
        {
            string filePath    = Application.streamingAssetsPath + pythonScripts + exchange + pythonFileName;
            string fileContent = "";

            if (useSimulator)
            {
                fileContent = pythonStartSimulator + circuit.GetQiskitString(true) + pythonEndSimulator + numberOfSimulations + pythonEnd;
            }
            else
            {
                if (!internalUser)
                {
                    fileContent = pythonBackendStart + circuit.GetQiskitString(true) + pythonBackendMid + token + pythonBackendEnd1 + backend + pythonBackendEnd2 + numberOfSimulations + pythonEndBackend;
                }
                else
                {
                    fileContent = pythonBackendStart + circuit.GetQiskitString(true) + pythonBackendMid + token + pythonBackendEndInternal1 + backend + pythonBackendEnd2 + numberOfSimulations + pythonEndBackend;
                }
            }

            Debug.Log("Writing python file to: " + filePath);


            File.WriteAllText(filePath, fileContent);
        }
コード例 #4
0
ファイル: QiskitSimulator.cs プロジェクト: degerli/QCU
        public override double[] GetProbabilities(QuantumCircuit circuit)
        {
            if (circuit.AmplitudeLength == 0)
            {
                circuit.AmplitudeLength = MathHelper.IntegerPower(2, circuit.NumberOfQubits);
            }

            double[] returnValue = new double[circuit.AmplitudeLength];

            WritePythonFile(circuit);
            string probString = RunPythonFile(circuit);

            ReadProbabilities(ref returnValue, probString);

            return(returnValue);
        }
コード例 #5
0
        /// <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 ComplexNumber[] Simulate(QuantumCircuit circuit)
        {
            MathHelper.InitializePower2Values(circuit.NumberOfQubits + 2);


            ComplexNumber[] amplitudes = base.Simulate(circuit);


            for (int i = 0; i < circuit.Gates.Count; i++)
            {
                Gate 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);
        }
コード例 #6
0
ファイル: QuantumCircuit.cs プロジェクト: VoicuTomut/QCU
 public void AddCircuit(QuantumCircuit circuit)
 {
     if (circuit.NumberOfQubits > NumberOfQubits)
     {
         LogWarning("Number of qubits is bigger " + circuit.NumberOfQubits + " vs " + NumberOfQubits);
         NumberOfQubits = circuit.NumberOfQubits;
         ComplexNumber[] newQubits = new ComplexNumber[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);
 }
コード例 #7
0
        public override void SilumateInPlace(QuantumCircuit circuit, ref ComplexNumber[] amplitudes)
        {
            //Check Length
            base.SilumateInPlace(circuit, ref amplitudes);

            for (int i = 0; i < circuit.Gates.Count; i++)
            {
                Gate 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;
                }
            }
        }
コード例 #8
0
 /// <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(QuantumCircuit circuit, ref double[] probabilities, ref ComplexNumber[] amplitudes)
 {
     //Trying to optimize not needing to return arrays
     SimulateInPlace(circuit, ref amplitudes);
     base.CalculateProbabilities(amplitudes, ref probabilities);
 }
コード例 #9
0
 /// <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 double[] GetProbabilities(QuantumCircuit circuit)
 {
     ComplexNumber[] amplitudes = Simulate(circuit);
     return(base.GetProbabilities(amplitudes));
 }
コード例 #10
0
 /// <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 double[] GetProbabilities(QuantumCircuit circuit)
 {
     return(base.GetProbabilities(Simulate(circuit)));
 }