Skip to content

Commit

Permalink
Updated BTC_02_AE with noisy qpu
Browse files Browse the repository at this point in the history
  • Loading branch information
gonfeco committed May 28, 2024
1 parent 36eb83e commit 18e2eeb
Show file tree
Hide file tree
Showing 10 changed files with 721 additions and 960 deletions.
145 changes: 78 additions & 67 deletions tnbs/BTC_01_PL/PL/notebooks/01_ProbabilityLoadingKernel.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,81 @@
"import pandas as pd"
]
},
{
"cell_type": "markdown",
"id": "133dc157-2c77-4525-bbcf-cbdf45dc4d45",
"metadata": {},
"source": [
"## 0. The QPU\n",
"\n",
"To simulate the quantum circuits generated by the functions presented in this notebook a configured myQLM (or QLM) **Quantum Process Unit (QPU)** is mandatory. The **QPU** can execute an ideal simulation or can simulate the quantum circuits under a noisy hardware model (noisy simulation). To easily deal with these 2 kinds of simulations the *select_qpu* function from **PL.qpu.select_qpu** was developed. The input of this function is a Python dictionary that allows to the user configure easily a **QPU**.\n",
"\n",
"In the present notebook, only ideal simulation is used. Please refer to the **PL/qpu/NoisyModels.ipynb** notebook for configuring noisy models and the corresponding noisy **QPU**s."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "555d3a6d-7b6a-4131-be8e-4173b341063d",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"from qpu.select_qpu import select_qpu"
]
},
{
"cell_type": "markdown",
"id": "957c04c6-d58f-471d-8134-80c7bc157d9b",
"metadata": {},
"source": [
"The minimum Python dictionary for configuring an ideal **QPU** is presented in the following cell. In this case, the user only has to provide a value to the *qpu_type* key. Depending on the type of simulator desired the following strings should be provided:\n",
"\n",
"* *qlmass_linalg*: to use the **LinAlg Quantum Learning Machine (QLM)** algebra simulator. In this case, the computation will be sent to the **QLM** by using the  Qaptiva QLM as a Service.\n",
"* *qlmass_mps*: to use **MPS QLM** simulator. In this case, the computation will be sent to the **QLM** by using the  Qaptiva QLM as a Service.\n",
"* *python*: to use the PyLinalg algebra simulator.\n",
"* *c*: to use the CLinalg alegbra simulator.\n",
"* *linalg*: to use the **LinAlg QLM**. In this case, the user should be inside a **EVIDEN QLM**\n",
"* *mps*: to use the **MPS QLM** simulator. In this case, the user should be inside a **EVIDEN QLM**"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d100c974",
"metadata": {},
"outputs": [],
"source": [
"# List with the strings taht should be provided for an ideal QPU\n",
"ideal_qpus = [\"c\", \"python\", \"linalg\", \"mps\", \"qlmass_linalg\", \"qlmass_mps\"]\n",
"qpu_config = {\n",
" #the following strings can be used:\n",
" #c,python, linalg, mps, qlmass_linalg, qlmass_mps\n",
" \"qpu_type\": ideal_qpus[2], \n",
" # The following keys are used for configuring noisy simulations\n",
" \"t_gate_1qb\" : None,\n",
" \"t_gate_2qbs\" : None,\n",
" \"t_readout\": None,\n",
" \"depol_channel\" : {\n",
" \"active\": False,\n",
" \"error_gate_1qb\" : None,\n",
" \"error_gate_2qbs\" : None\n",
" },\n",
" \"idle\" : {\n",
" \"amplitude_damping\": False,\n",
" \"dephasing_channel\": False,\n",
" \"t1\" : None,\n",
" \"t2\" : None\n",
" },\n",
" \"meas\": {\n",
" \"active\":False,\n",
" \"readout_error\": None\n",
" }\n",
"}\n",
"qpu = select_qpu(qpu_config)"
]
},
{
"cell_type": "markdown",
"id": "b5c3e552",
Expand Down Expand Up @@ -278,70 +353,6 @@
"from data_loading import get_qlm_probability"
]
},
{
"cell_type": "markdown",
"id": "342530eb-18bc-441c-881c-988848c54e30",
"metadata": {},
"source": [
"First, we need to instantiate the **QPU**. To do this the *select_qpu* from the **qpu.select_qpu** module can be used. This module allows the user to select a **QPU** by providing an input dictionary. \n",
"\n",
"With this *select_qpu* function a qpu for ideal or for a noisy simulation (only when connected to a **EVIDEN Quantum Learning Machine**) can be configured easily.\n",
"\n",
"For more information about how to use the function for noisy simulation, please refer to notebook: **qpu/NoisyModels.ipynb**.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "420abf44",
"metadata": {},
"outputs": [],
"source": [
"from qpu.select_qpu import select_qpu"
]
},
{
"cell_type": "markdown",
"id": "a5fdc167",
"metadata": {},
"source": [
"To configure an ideal simulation the input dictionary should be configured in the following way:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d100c974",
"metadata": {},
"outputs": [],
"source": [
"qpu_config = {\n",
" #the following strings can be used:\n",
" #c,python, linalg, mps, qlmass_linalg, qlmass_mps\n",
" \"qpu_type\": \"c\", \n",
" # The following keys are used for configuring noisy simulations\n",
" \"t_gate_1qb\" : None,\n",
" \"t_gate_2qbs\" : None,\n",
" \"t_readout\": None,\n",
" \"depol_channel\" : {\n",
" \"active\": False,\n",
" \"error_gate_1qb\" : None,\n",
" \"error_gate_2qbs\" : None\n",
" },\n",
" \"idle\" : {\n",
" \"amplitude_damping\": False,\n",
" \"dephasing_channel\": False,\n",
" \"t1\" : None,\n",
" \"t2\" : None\n",
" },\n",
" \"meas\": {\n",
" \"active\":False,\n",
" \"readout_error\": None\n",
" }\n",
"}\n",
"qpu = select_qpu(qpu_config)"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -884,9 +895,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "myqlm_tes",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "myqlm_tes"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -898,7 +909,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.14"
"version": "3.9.16"
}
},
"nbformat": 4,
Expand Down
18 changes: 9 additions & 9 deletions tnbs/BTC_02_AE/QQuantLib/ae_sine_integral.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,13 @@ def run_id(
default="qpu/qpu.json",
help="JSON with the qpu configuration",
)
parser.add_argument(
"-folder",
dest="folder_path",
type=str,
help="Path for storing folder",
default="./",
)
parser.add_argument(
"--count",
dest="count",
Expand All @@ -292,13 +299,6 @@ def run_id(
action="store_true",
help="For saving results",
)
parser.add_argument(
"--folder",
dest="folder_path",
type=str,
help="Path for storing folder",
default="./",
)
#Execution argument
parser.add_argument(
"--exe",
Expand Down Expand Up @@ -329,15 +329,15 @@ def run_id(

if args.execution:
if args.id is not None:
run_id(
print(run_id(
n_qbits=args.n_qbits,
interval=args.interval,
repetitions=args.repetitions,
ae_config=final_list[args.id],
folder_path=args.folder_path,
#qpu=args.qpu,
save_=args.save,
)
))
# if args.execution:
# list_of_pdfs = []
# for i in range(args.repetitions):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,6 @@
"* Iterative Quantum Amplitude Estimation (**IQAE**): based on *Grinko et al (2021) Iterative quantum amplitude estimation*. This algorithm uses the Grover operator $\\mathbf{G}(\\mathbf{A})$ in an iterative way. In each step a differing number of applications of $\\mathbf{G}(\\mathbf{A})$ is computed based on the results obtained in the step before. This algorithm returns a $\\alpha$ level confidence interval for the estimation of $a$. So algorithm provides a minimum and maximum of $a$. The length of the interval should be fixed a priori. For lower lengths, the algorithm needs more steps and deeper circuits. **Only estimates positives $a$**\n",
"* Real Quantum Amplitude Estimation (**RQAE**): based on *Manzano et al (2023) Real Quantum Amplitude Estimation*. An iterative algorithm where in each step the number of applications of the Grover operator $\\mathbf{G}(\\mathbf{A})$ is computed using the results from before steps. This algorithm returns a $\\alpha$ level confidence interval for the estimation of $a$. So algorithm provides a minimum and maximum of $a$. The length of the interval should be fixed a priori. For lower lengths, the algorithm needs more steps and deeper circuits. **This algorithm allows us to estimate non-positive $a$**."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f7bdbdbf",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -179,7 +171,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.9"
"version": "3.9.16"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit 18e2eeb

Please sign in to comment.