diff --git a/tnbs/BTC_01_PL/PL/notebooks/01_ProbabilityLoadingKernel.ipynb b/tnbs/BTC_01_PL/PL/notebooks/01_ProbabilityLoadingKernel.ipynb index 085cdfc..3c6dbf2 100644 --- a/tnbs/BTC_01_PL/PL/notebooks/01_ProbabilityLoadingKernel.ipynb +++ b/tnbs/BTC_01_PL/PL/notebooks/01_ProbabilityLoadingKernel.ipynb @@ -568,9 +568,7 @@ { "cell_type": "markdown", "id": "38bef876-ea3a-41e9-a1bc-ec0c527c5388", - "metadata": { - "jp-MarkdownHeadingCollapsed": true - }, + "metadata": {}, "source": [ "## 05. Generating the JSON file.\n", "\n", @@ -588,7 +586,7 @@ "source": [ "## 06. Complete Workflow.\n", "\n", - "The bash script **benchmark_exe.sh** allows to automatize the execution of the benchamrk and the JSON file generation (once the *my_benchmark_execution.py* and the *neasqc_benchmark.py* are properly configured).\n", + "The bash script **benchmark_exe.sh** allows to automatize the execution of the benchmark and the JSON file generation (once the *my_benchmark_execution.py* and the *neasqc_benchmark.py* are properly configured).\n", "\n", " bash benchmark_exe.sh" ] diff --git a/tnbs/BTC_03_QPE/QPE/notebooks/01_BTC_03_QPE_for_rzn_rz_library.ipynb b/tnbs/BTC_03_QPE/QPE/notebooks/01_BTC_03_QPE_for_rzn_rz_library.ipynb index 6a304d0..12cd498 100644 --- a/tnbs/BTC_03_QPE/QPE/notebooks/01_BTC_03_QPE_for_rzn_rz_library.ipynb +++ b/tnbs/BTC_03_QPE/QPE/notebooks/01_BTC_03_QPE_for_rzn_rz_library.ipynb @@ -34,7 +34,7 @@ "source": [ "# rz_lib\n", "\n", - "In order to develop the **Benchmark Test Case** for **QPE** we have developed the **rz_library** python package that have all mandatory functions for computing eigenvalues of a $Rz^{\\otimes n} (\\vec{\\theta})$ operator theoretically and usign Atos myqlm simulation library. In this notbook we explain the **QPE** for the $Rz^{\\otimes n} (\\vec{\\theta})$ and shows how to use the **rz_library** package" + "In order to develop the **Benchmark Test Case** for **QPE** we have developed the **rz_library** python package that has all mandatory functions for computing eigenvalues of a $Rz^{\\otimes n} (\\vec{\\theta})$ operator theoretically and using *myqlm* simulation library. In this notebook we explain the **QPE** for the $Rz^{\\otimes n} (\\vec{\\theta})$ and shows how to use the **rz_library** package" ] }, { @@ -61,13 +61,13 @@ "\n", "$$\\lambda_j = \\frac{y_j}{2^m}$$\n", "\n", - "It can be shown that if the eigenvalue $\\lambda_j$ can be mapped to $\\frac{y_j}{2^m}$ then the probability of getting the correct eigenvalue is 100%. If this is not posible then it can be shown that the measured $\\lambda^{Meas}_j$ have an error with respect to the true value $\\lambda^{True}_j$ of:\n", + "It can be shown that if the eigenvalue $\\lambda_j$ can be mapped to $\\frac{y_j}{2^m}$ then the probability of getting the correct eigenvalue is 100%. If this is not possible then it can be shown that the measured $\\lambda^{Meas}_j$ have an error concerning the true value $\\lambda^{True}_j$ of:\n", "\n", "$$|\\lambda^{Meas}_j - \\lambda^{True}_j| \\leq \\frac{1}{2^m}$$\n", "\n", "with a probability higher than $80\\%$. \n", "\n", - "If all eigenstates of the operator $\\mathcal{Q}$ are know we can compute all the correspondent eigenvalues using the aforementioned circuit for each eigenstate." + "If all eigenstates of the operator $\\mathcal{Q}$ are known we can compute all the correspondent eigenvalues using the aforementioned circuit for each eigenstate." ] }, { @@ -145,10 +145,9 @@ "### n qubit \n", "\n", "\n", - "\n", "This can be easily generalizable for a $n$ qbits kronecker product: $R_z^{\\otimes n} (\\vec{\\theta})$.\n", "\n", - "Additionally the eigenvalues for each eigenvector have an easy computation recipe: for a system with $n$ qubits the eigenvalue for an eigenstate $\\ket{i_0i_1i_2 \\cdots i_n}$, with $i_j=\\{0,1\\}$, of a $Rz^{\\otimes n} (\\vec{\\theta})$ operator have following eigenvalue:\n", + "Additionally, the eigenvalues for each eigenvector have an easy computation recipe: for a system with $n$ qubits the eigenvalue for an eigenstate $\\ket{i_0i_1i_2 \\cdots i_n}$, with $i_j=\\{0,1\\}$, of a $Rz^{\\otimes n} (\\vec{\\theta})$ operator have following eigenvalue:\n", "\n", "$$2\\pi \\lambda_{\\ket{i_0, i_1, \\cdots , i_n}} = - \\frac{\\sum_{j=0}^{n} (-1)^{i_j} \\theta_j}{2}$$\n", "\n", @@ -175,7 +174,7 @@ "outputs": [], "source": [ "import sys\n", - "sys.path.append('../../QPE')\n", + "sys.path.append('../')\n", "import rz_lib" ] }, @@ -186,7 +185,7 @@ "source": [ "### 3.1. Theoretical Eigenvalues\n", "\n", - "The **rz_eigv** function from *rz_lib* allows to compute the complete eigenvalues of a generic $R_z^{\\otimes n} (\\vec{\\theta})$ operator for an input list of angles. In order to understand the package we are going to use two types of list of angles:\n", + "The **rz_eigv** function from *rz_lib* allows to compute the complete eigenvalues of a generic $R_z^{\\otimes n} (\\vec{\\theta})$ operator for an input list of angles. In order to understand the package we are going to use two types of lists of angles:\n", "\n", "1. A list with the same angle for all the qubits, set to $\\frac{\\pi}{2}$.\n", "2. A list of different random angles" @@ -261,12 +260,12 @@ "id": "9a792b69", "metadata": {}, "source": [ - "Once the theoretical eigenvalues are found we need to create the correspondent histogram of the eigenvalues between $[0, 1]$ and with fixed discretization that will be given by the number of auxiliary qubits that will be used for computing the **QPE** (the $m$ qubit register in the **QPE** showed at the begining of the notebook). This should be done for a direct comparing between the theoretical results and the results of the **QPE**.\n", + "Once the theoretical eigenvalues are found we need to create the correspondent histogram of the eigenvalues between $[0, 1]$ and with fixed discretization that will be given by the number of auxiliary qubits that will be used for computing the **QPE** (the $m$ qubit register in the **QPE** showed at the beginning of the notebook). This should be done for a direct comparison between the theoretical results and the results of the **QPE**.\n", "\n", "\n", - "In the **QPE** we can measure the different eigenvalues of the input unitary operator but the precision of the meaturement will be given by the $m$ auxiliar qbit register. So the output of the **QPE** will be a histogram between $[0,1]$ with $2^m$ bins. In each bin the histogram will give us the frecuency of eigenvalues that will be inside it. \n", + "In the **QPE** we can measure the different eigenvalues of the input unitary operator but the precision of the measurement will be given by the $m$ auxiliary qbit register. So the output of the **QPE** will be a histogram between $[0,1]$ with $2^m$ bins. In each bin, the histogram will give us the frequency of eigenvalues that will be inside it. \n", "\n", - "For computing the correspondet histogram the **make_histogram** from *rz_library* can be used. The inputs will be the therotical computed eigenvalues and a discretization parameter (that must be equal to the $m$ that we are going to use for the **QPE**)\n" + "For computing the corresponding histogram the **make_histogram** from *rz_library* can be used. The inputs will be the theoretical computed eigenvalues and a discretization parameter (that must be equal to the $m$ that we are going to use for the **QPE**)\n" ] }, { @@ -373,18 +372,18 @@ "source": [ "#### Computing the number of shots.\n", "\n", - "The main problem is computing the number of shots. In general, we want to have for each measured eigenvalue a number of shots enough for having a good statistic. But if the eigenvalues are degenerated it could happend that the most degeneracy eigenvalues will be obtained more frequently than others. Main problem is for eigenvalues with lower degeneracy the number of shots can be not enough for having a good statistic. \n", + "The main problem is computing the number of shots. In general, we want to have for each measured eigenvalue a number of shots enough for having a good statistic. But if the eigenvalues are degenerated it could happen that the most degeneracy eigenvalues will be obtained more frequently than others. The main problem is for eigenvalues with lower degeneracy the number of shots can be not enough to have a good statistic. \n", "\n", - "So we are going to execute following strategy:\n", + "So we are going to execute the following strategy:\n", "\n", - "1. We are going to compute the probability of getting the lowest degeneracy eigenvalue from all the posible theoretical eigenvalues: $p_{lde}$.\n", + "1. We are going to compute the probability of getting the lowest degeneracy eigenvalue from all the possible theoretical eigenvalues: $p_{lde}$.\n", "2. The number of shots will be equal:\n", "\n", "$$\\text{shots} = \\lceil\\frac{1000}{0.81 * p_{lde}}\\rceil$$\n", "\n", - "This is because we want to have for each obtained eigenvalue near of 1000 measures such that the error with respect to the theoretical value will be lower than the discretization ($\\frac{1}{2^{m}}$).\n", + "This is because we want to have for each obtained eigenvalue near 1000 measures such that the error concerning the theoretical value will be lower than the discretization ($\\frac{1}{2^{m}}$).\n", "\n", - "This computation can be done with *computing_shots* function" + "This computation can be done with the *computing_shots* function" ] }, { @@ -415,22 +414,36 @@ "source": [ "The *qpe_rz_qlm* function from **rz_qlm** script creates the atos qlm implementation of the **QPE** circuit for a $R_z^{\\otimes n}$ operator and solves the circuit providing the different eigenvalues ($\\lambda_j$). The mandatory inputs are:\n", "\n", - "* angles : list. List with the angles that are applied to each qubit of the circuit\n", - "* auxiliar_qbits_number : int. Number of auxiliar qubits for doing QPE.\n", + "* angles: list. List with the angles that are applied to each qubit of the circuit\n", + "* auxiliar_qbits_number: int. The number of auxiliary qubits for doing QPE.\n", "\n", - "The function returns a pandas dataframe with the distribution of eigenvalues obtained.\n", + "The function returns a pandas DataFrame with the distribution of eigenvalues obtained.\n", "\n", "\n", "* lambda : lamda eigenvalue of the correspondent state\n", - "* Probability : Probability of getting the correspondent state\n", + "* Probability: Probability of getting the correspondent state\n", "\n", - "The format of the pandas is compatible with the pandas dataframe returned by *make_histogram* for doing direct comparison!\n", + "The format of the pandas is compatible with the pandas DataFrame returned by *make_histogram* for doing direct comparison!\n", "\n", "**BE AWARE**\n", "\n", "The ordering of the **States** columns is the least significant bit at the right (it corresponds to the column labelled as **Int_lsb**)" ] }, + { + "cell_type": "code", + "execution_count": null, + "id": "24aab959-d5e1-40cc-afdc-427be1e618a7", + "metadata": {}, + "outputs": [], + "source": [ + "# For getting the QPU\n", + "sys.path.append(\"../../\")\n", + "from get_qpu import get_qpu\n", + "\n", + "qpu = get_qpu(\"c\")" + ] + }, { "cell_type": "code", "execution_count": null, @@ -446,7 +459,8 @@ "pdf_qlm_rz_same, qpe_object_ = rz_lib.qpe_rz_qlm(\n", " theta_same, \n", " auxiliar_qbits_number=auxiliar_qbuits, \n", - " shots=same_shots\n", + " shots=same_shots,\n", + " qpu=qpu\n", ")" ] }, @@ -459,7 +473,7 @@ }, "outputs": [], "source": [ - "# QPE circuito\n", + "# QPE circuit\n", "c = qpe_object_.circuit\n", "%qatdisplay c --svg" ] @@ -505,7 +519,9 @@ "pdf_qlm_rz_diff, qpe_object = rz_lib.qpe_rz_qlm(\n", " theta_diff, \n", " auxiliar_qbits_number=auxiliar_qbuits, \n", - " shots=diff_shots)" + " shots=diff_shots, \n", + " qpu=qpu\n", + ")" ] }, { @@ -536,9 +552,7 @@ "cell_type": "code", "execution_count": null, "id": "20697520", - "metadata": { - "scrolled": true - }, + "metadata": {}, "outputs": [], "source": [ "plt.plot(pdf_qlm_rz_diff['lambda'], pdf_qlm_rz_diff['Probability'] * diff_shots , 'o-')\n", @@ -599,7 +613,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.9" + "version": "3.11.7" } }, "nbformat": 4, diff --git a/tnbs/BTC_03_QPE/QPE/notebooks/02_BTC_03_QPE_for_rzn_Procedure.ipynb b/tnbs/BTC_03_QPE/QPE/notebooks/02_BTC_03_QPE_for_rzn_Procedure.ipynb index 9323109..3985331 100644 --- a/tnbs/BTC_03_QPE/QPE/notebooks/02_BTC_03_QPE_for_rzn_Procedure.ipynb +++ b/tnbs/BTC_03_QPE/QPE/notebooks/02_BTC_03_QPE_for_rzn_Procedure.ipynb @@ -5,9 +5,9 @@ "id": "a5bcd51f", "metadata": {}, "source": [ - "# Class for Benchmar Step\n", + "# Class for Benchmark Step\n", "\n", - "We have developed a python class that implements the complete benchmark step procedure for **QPE** for a $R_z^n(\\vec{\\theta})$ operator for a fixed number of: *qubits*, *auxiliar number of qubits* and a *type of angle selection*: the **QPE_RZ** class from package *qpe_rz*.\n", + "We have developed a python class that implements the complete benchmark step procedure for **QPE** for a $R_z^n(\\vec{\\theta})$ operator for a fixed number of: *qubits*, *auxiliary number of qubits* and a *type of angle selection*: the **QPE_RZ** class from the *QPE/qpe_rz* module.\n", "\n", "This notebook shows how this class works" ] @@ -22,20 +22,7 @@ "import numpy as np\n", "import pandas as pd\n", "import matplotlib.pyplot as plt\n", - "%matplotlib notebook" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "4077767e", - "metadata": {}, - "outputs": [], - "source": [ - "# myQLM qpus\n", - "from qat.qpus import PyLinalg, CLinalg\n", - "qpu_c = CLinalg()\n", - "qpu_p = PyLinalg()" + "%matplotlib inline" ] }, { @@ -46,8 +33,11 @@ "outputs": [], "source": [ "import sys\n", - "sys.path.append('../../QPE')\n", - "from qpe_rz import QPE_RZ" + "sys.path.append('../')\n", + "from qpe_rz import QPE_RZ\n", + "sys.path.append('../../')\n", + "from get_qpu import get_qpu\n", + "qpu = get_qpu(\"c\")" ] }, { @@ -55,16 +45,16 @@ "id": "e0be743a", "metadata": {}, "source": [ - "We need to initialize the class. This should be done with a python dictionary that configures the step benchmark execution. Mandatory keywords for the dictionary are:\n", + "We need to initialize the class. This should be done with a Python dictionary that configures the step benchmark execution. Mandatory keywords for the dictionary are:\n", "\n", - "* **number_of_qbits**: the number of qubits for apply the Kronecker products of $R_z$\n", - "* **auxiliar_qbits_number**: auxiliar number of qubits for performing **QPE**\n", + "* **number_of_qbits**: the number of qubits for applying the Kronecker products of $R_z$\n", + "* **auxiliar_qbits_number**: auxiliary number of qubits for performing **QPE**\n", "* **angles**: the angles for the $R_z^n(\\vec{\\theta})$ operator. It can be:\n", " * float number: the same angle to all $R_z$\n", - " * list with angles: Each angle will be apply to a $R_z$. Number of elements MUST be equal to number of qubits.\n", + " * list with angles: Each angle will be applied to a $R_z$. The number of elements MUST be equal to the number of qubits.\n", " * string: Two different strings can be provided:\n", - " * *random* : random angles will be provide to each $R_z$\n", - " * *exact* : In this case random angles will be provided to each $R_z$ but the final result it will have a precision realted with the number of auxiliar number of qbuits for the **QPE**\n" + " * *random*: random angles will be provided to each $R_z$\n", + " * *exact*: In this case, random angles will be provided to each $R_z$ but the final result will have a precision related with the number of auxiliary number of qubits for the **QPE**\n" ] }, { @@ -81,12 +71,12 @@ "angles = [np.pi / 2.0 for i in range(n_qbits)]\n", "# Dictionary for configuring the class\n", "qpe_dict = {\n", - " 'number_of_qbits' : n_qbits,\n", - " 'auxiliar_qbits_number' : aux_qbits,\n", - " 'angles' : angles,\n", + " 'number_of_qbits': n_qbits,\n", + " 'auxiliar_qbits_number': aux_qbits,\n", + " 'angles': angles,\n", " #'angles' : 'random', \n", - " 'qpu' : qpu_c,\n", - " 'shots' : 0\n", + " 'qpu': qpu,\n", + " 'shots': 0\n", "}" ] }, @@ -108,12 +98,12 @@ "source": [ "When the computation is performed (*exe* method) 2 different metrics are computed:\n", "\n", - "* Kolmogorov-Smirnov distance (**ks** attribute): it is a metric for comparing probability distributions. If it is near zero then the 2 distribution are very similar.\n", - "* Fidelity: (**fidelity** attribute): assumes that the 2 obtained eigenvalues distribution (the theorical and the quantum one) are vectors and computes the cosine of the angle between them. For **fidelity** near one then the vectors are more equal. \n", + "* Kolmogorov-Smirnov distance (**ks** attribute): it is a metric for comparing probability distributions. If it is near zero then the 2 distributions are very similar.\n", + "* Fidelity: (**fidelity** attribute): assumes that the 2 obtained eigenvalues distribution (the theoretical and the quantum one) are vectors and computes the cosine of the angle between them. For **fidelity** near one then the vectors are more equal. \n", "\n", - "Meanwhile the **Kolmogorov-Smirnov** is the good metric for any configuration of **QPE** of the $R_z^{\\otimes n}(\\vec{\\theta})$ operator. The **fidelity** gives a very good metric when the configuration is such that the eigenvalues can be obtained exactly with the **QPE**.\n", + "Meanwhile, the **Kolmogorov-Smirnov** is the good metric for any configuration of **QPE** of the $R_z^{\\otimes n}(\\vec{\\theta})$ operator. The **fidelity** gives a very good metric when the configuration is such that the eigenvalues can be obtained exactly with the **QPE**.\n", "\n", - "Make some test for understanding how this metrics works in different configurations." + "In the following sections we use som examples for comparing the 2 metrics behaviour.\n" ] }, { @@ -131,10 +121,9 @@ "id": "b62fa3b8", "metadata": {}, "source": [ - "The class provide acces to other attributes that can be useful like:\n", - "\n", + "The class provide access to other attributes that can be useful like:\n", "\n", - "* *theorical_eigv_dist*: pandas DataFrame with the theorical eigenvalue distribution\n", + "* *theorical_eigv_dist*: pandas DataFrame with the theoretical eigenvalue distribution\n", "* *quantum_eigv_dist*: pandas DataFrame with the QPE eigenvalue distribution" ] }, @@ -167,9 +156,9 @@ "source": [ "### General QPE configuration\n", "\n", - "Here we are going to executes the **QPE** of the $R_z^{\\otimes n}(\\vec{\\theta})$ operator for a random selection of the angles. In this case the eigenvalues of the operator can not be obtained exactly using the QPE (we would need inifinite number of qubits for have the correct precision for obtained exactly the eigenvalues). In this case the **fidelity** metric does not work properly, even in the exact simulation execution, but the **Kolmogorov-Smirnov** will work.\n", + "Here we are going to execute the **QPE** of the $R_z^{\\otimes n}(\\vec{\\theta})$ operator for a random selection of the angles. In this case, the eigenvalues of the operator can not be obtained exactly using the QPE (we would need an infinite number of qubits to have the correct precision for obtaining exactly the eigenvalues). In this case, the **fidelity** metric does not work properly, even in the exact simulation execution, but the **Kolmogorov-Smirnov** will work.\n", "\n", - "For this case we set the variable angles to *random* for selecting random angles for each $R_z$" + "For this case, we set the variable angles to *random* for selecting random angles for each $R_z$" ] }, { @@ -190,7 +179,7 @@ " 'auxiliar_qbits_number' : aux_qbits,\n", " #'angles' : angles,\n", " 'angles' : 'random', \n", - " 'qpu' : qpu_c,\n", + " 'qpu' : qpu,\n", " #'shots' : 0\n", "}" ] @@ -221,7 +210,7 @@ "id": "75734cee", "metadata": {}, "source": [ - "As can be seen the **Kolmogorov-Smirnov** will give us a value near of 0, but the **fidelity** is far away from zero. We can plot the distributions for comparing the results" + "As can be seen the **Kolmogorov-Smirnov** will give us a value near of 0, but the **fidelity** is far away from zero. We can plot the distributions to compare the results" ] }, { @@ -312,7 +301,7 @@ " 'auxiliar_qbits_number' : aux_qbits,\n", " 'angles' : angles,\n", " #'angles' : 'random', \n", - " 'qpu' : qpu_c,\n", + " 'qpu' : qpu,\n", " #'shots' : 0\n", "}" ] @@ -363,7 +352,7 @@ "metadata": {}, "outputs": [], "source": [ - "%matplotlib notebook\n", + "%matplotlib inline\n", "plt.plot(qpe_rz_b.theorical_eigv_dist['lambda'], qpe_rz_b.theorical_eigv_dist['Probability'], '-')\n", "plt.plot(qpe_rz_b.quantum_eigv_dist['lambda'], qpe_rz_b.quantum_eigv_dist['Probability'], '-o')\n", "plt.xlabel('$\\lambda$')\n", @@ -391,20 +380,64 @@ ] }, { - "cell_type": "code", - "execution_count": null, - "id": "136d7f5a", + "cell_type": "markdown", + "id": "e8aa2868-5152-4dee-9a07-3f4a82f4f735", "metadata": {}, - "outputs": [], - "source": [] + "source": [ + "## Command line execution\n", + "\n", + "The module *QPE/qpe_rz* can be executed from the command line to get a complete execution of a QPE step. The following command provides help for using it:\n", + "\n", + " python qpe_rz.py -h\n", + "\n", + "For computing the case for the 4 qubits operator with 8 auxiliary qubits for the exact angles case using the **C** linear algebra QPU the following command can be executed:\n", + "\n", + " python qpe_rz.py -n_qbits 4 -aux_qbits 8 -qpu c -angles 0\n", + "\n", + "For computing the case for the 4 qubits operator with 8 auxiliary qubits for the random angles case using the **C** linear algebra QPU the following command can be executed:\n", + "\n", + " python qpe_rz.py -n_qbits 4 -aux_qbits 8 -qpu c -angles 1" + ] }, { - "cell_type": "code", - "execution_count": null, - "id": "d30f85b6", + "cell_type": "markdown", + "id": "3cb12dc9-054b-4a85-a7e3-5070d849cdba", "metadata": {}, - "outputs": [], - "source": [] + "source": [ + "## my\\_benchmark\\_execution\n", + "\n", + "A complete benchmark execution following the **TNBS** guidelines can be performed by using the **my\\_benchmark\\_execution.py** module in the **BTC_03_QPE** folder.\n", + "\n", + "In the **kernel_configuration** dictionary (at the end of the module) the case and the kernel can be configured. In general, the key to edit is the *auxiliar_qbits_number* where the user can provide a list with a different number of auxiliary qubits for changing the precision of the eigenvalues estimation. \n", + "\n", + "For changing the folder where all the files generated by the benchmark are stored the path can be provided to the key *saving_folder* of the *benchmark_arguments*. The number of qubits for the unitary operator can be provided as a list to the key *list_of_qbits* of the *benchmark_arguments* dictionary." + ] + }, + { + "cell_type": "markdown", + "id": "f631de04-2905-4595-9264-7fbfa8edbf48", + "metadata": {}, + "source": [ + "## Generating the JSON file.\n", + "\n", + "Once the files from a complete benchmark execution are generated the information should be formated following the **NEASQC JSON schema**. For doing this the **neasqc_benchmark.py** module can be used. At the end of the file the path to the folder where all the files from benchmark are stored should be provided to the variable **folder**.\n", + "\n", + "For creating the JSON file following command should eb executed:\n", + "\n", + " python neasqc_benchmark.py" + ] + }, + { + "cell_type": "markdown", + "id": "a7e7908b-17b2-45cf-a0e3-d666d56d6136", + "metadata": {}, + "source": [ + "## Complete Workflow.\n", + "\n", + "The bash script **benchmark_exe.sh** allows to automatize the execution of the benchmark and the JSON file generation (once the *my_benchmark_execution.py* and the *neasqc_benchmark.py* are properly configured).\n", + "\n", + " bash benchmark_exe.sh" + ] } ], "metadata": { @@ -423,7 +456,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.9" + "version": "3.11.7" } }, "nbformat": 4, diff --git a/tnbs/BTC_03_QPE/QPE/rz_lib.py b/tnbs/BTC_03_QPE/QPE/rz_lib.py index 15753a1..1ba2cae 100644 --- a/tnbs/BTC_03_QPE/QPE/rz_lib.py +++ b/tnbs/BTC_03_QPE/QPE/rz_lib.py @@ -4,7 +4,7 @@ Author: Gonzalo Ferro """ - +import sys import numpy as np import pandas as pd import qat.lang.AQASM as qlm @@ -12,51 +12,51 @@ from qpe import CQPE -def get_qpu(qpu=None): - """ - Function for selecting solver. - - Parameters - ---------- - - qpu : str - * qlmass: for trying to use QLM as a Service connection to CESGA QLM - * python: for using PyLinalg simulator. - * c: for using CLinalg simulator - - Returns - ---------- - - linal_qpu : solver for quantum jobs - """ - - if qpu is None: - raise ValueError( - "qpu CAN NOT BE NONE. Please select one of the three" + - " following options: qlmass, python, c") - if qpu == "qlmass": - try: - from qlmaas.qpus import LinAlg - linalg_qpu = LinAlg() - except (ImportError, OSError) as exception: - raise ImportError( - "Problem Using QLMaaS. Please create config file" + - "or use mylm solver") from exception - elif qpu == "python": - from qat.qpus import PyLinalg - linalg_qpu = PyLinalg() - elif qpu == "c": - from qat.qpus import CLinalg - linalg_qpu = CLinalg() - elif qpu == "default": - from qat.qpus import get_default_qpu - linalg_qpu = get_default_qpu() - else: - raise ValueError( - "Invalid value for qpu. Please select one of the three "+ - "following options: qlmass, python, c") - #print("Following qpu will be used: {}".format(linalg_qpu)) - return linalg_qpu +#def get_qpu(qpu=None): +# """ +# Function for selecting solver. +# +# Parameters +# ---------- +# +# qpu : str +# * qlmass: for trying to use QLM as a Service connection to CESGA QLM +# * python: for using PyLinalg simulator. +# * c: for using CLinalg simulator +# +# Returns +# ---------- +# +# linal_qpu : solver for quantum jobs +# """ +# +# if qpu is None: +# raise ValueError( +# "qpu CAN NOT BE NONE. Please select one of the three" + +# " following options: qlmass, python, c") +# if qpu == "qlmass": +# try: +# from qlmaas.qpus import LinAlg +# linalg_qpu = LinAlg() +# except (ImportError, OSError) as exception: +# raise ImportError( +# "Problem Using QLMaaS. Please create config file" + +# "or use mylm solver") from exception +# elif qpu == "python": +# from qat.qpus import PyLinalg +# linalg_qpu = PyLinalg() +# elif qpu == "c": +# from qat.qpus import CLinalg +# linalg_qpu = CLinalg() +# elif qpu == "default": +# from qat.qpus import get_default_qpu +# linalg_qpu = get_default_qpu() +# else: +# raise ValueError( +# "Invalid value for qpu. Please select one of the three "+ +# "following options: qlmass, python, c") +# #print("Following qpu will be used: {}".format(linalg_qpu)) +# return linalg_qpu # Functions for generating theoretical eigenvalues of R_z^n def bitfield(n_int: int, size: int):