Skip to content

Commit

Permalink
Begining notebook documentation of BTC_04_PH
Browse files Browse the repository at this point in the history
  • Loading branch information
gonfeco committed Jan 16, 2024
1 parent d5c759f commit 43f70e0
Show file tree
Hide file tree
Showing 5 changed files with 2,686 additions and 184 deletions.
1 change: 1 addition & 0 deletions tnbs/BTC_03_QPE/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ If you want a complete execution and create the complete **JSON** file with the
bash benchmark_exe.sh

All the results files and the corresponding JSON will be stored in the **Results** folder.
For more information about the code implementation and about the kernel, please refer to the jupyter notebooks inside the folder **QPE/notebooks**

95 changes: 46 additions & 49 deletions tnbs/BTC_04_PH/PH/notebooks/01_Ansatzes.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"outputs": [],
"source": [
"import sys\n",
"sys.path.append(\"../\")"
"sys.path.append(\"../../\")"
]
},
{
Expand All @@ -55,9 +55,7 @@
"outputs": [],
"source": [
"# myQLM qpus\n",
"from qat.qpus import PyLinalg, CLinalg\n",
"qpu_c = CLinalg()\n",
"qpu_p = PyLinalg()"
"from get_qpu import get_qpu"
]
},
{
Expand All @@ -68,10 +66,8 @@
"outputs": [],
"source": [
"# QLM qpus\n",
"from qlmaas.qpus import LinAlg\n",
"qpu_qaass = LinAlg()\n",
"from qlmaas.qpus import MPS\n",
"qpu_mps = MPS()"
"qpu_c = get_qpu(\"c\")\n",
"qpu_p = get_qpu(\"python\")"
]
},
{
Expand All @@ -81,9 +77,9 @@
"source": [
"## 1. ansatzes module\n",
"\n",
"One mandatory step for using the Parent Hamiltonian, **PH**, library (see nootebook **02_Using_PH_Class.ipynb**) is computing for a given ansatz its complete state. This is the amplitudes of the state in the computational *n* qubit basis. \n",
"One mandatory step for using the Parent Hamiltonian, **PH**, library (see notebook **02_Using_PH_Class.ipynb**) is computing for a given ansatz its complete state. This is the amplitudes of the state in the computational $n$ qubit basis. \n",
"\n",
"In the *ansatzes* module of the **PH** library several functions and classes for deling with this part of the computation was done.\n"
"In the *ansatzes* module of the **PH** library, several functions and classes for dealing with this part of the computation were done.\n"
]
},
{
Expand All @@ -93,7 +89,7 @@
"source": [
"### 1.1 SolveCircuit class\n",
"\n",
"The **SolveCircuit** takes a *Atos myqlm circuit* with an ansatz, fix their parameter and simulates using *Atos qpu* and return the state of the ansatz.\n",
"The **SolveCircuit** takes a *Atos myqlm circuit* with an ansatz, fixes their parameter, simulates using *Atos qpu* and returns the state of the ansatz.\n",
"\n",
"The main input of this class is a QLM circuit where the parameters were set. For showing how this class works we are going to use an ansatz example: the translational invariant circuit of the original Parent Hamiltonian paper."
]
Expand Down Expand Up @@ -148,9 +144,7 @@
"cell_type": "code",
"execution_count": null,
"id": "68de1184",
"metadata": {
"scrolled": true
},
"metadata": {},
"outputs": [],
"source": [
"n_qubits = 12\n",
Expand All @@ -177,14 +171,14 @@
"source": [
"#### 1.1.2 . Setting the parameters\n",
"\n",
"As can be seen the circuit has the parameters as variables. We can set the parameters calling the *angles_ansatz01* function. If $n_l$ is the number of layers of the circuit the formula for setting the parameters is:\n",
"As can be seen, the circuit has the parameters as variables. We can set the parameters by calling the *angles_ansatz01* function. If $n_l$ is the number of layers of the circuit the formula for setting the parameters is:\n",
"\n",
"\n",
"$$\\delta \\theta = \\frac{\\pi}{4*(n_l+1)}$$\n",
"\n",
"$$\\theta_i = (i+1) \\delta \\theta \\; i=0, 1, \\cdots 2n_l-1$$\n",
"\n",
"The output of the function are:\n",
"The outputs of the function are:\n",
"* circuit with the parameters fixed\n",
"* pandas DataFrame with the value of the parameters used"
]
Expand Down Expand Up @@ -238,8 +232,8 @@
"id": "aebbd82b",
"metadata": {},
"source": [
"In addition we can use the parameters of the circuit providing a pandas DataFrame to the function. In this case the function can be used for setting the parameters for any circuit! The parameters should be passes as a pandas DataFrame with 2 columns:\n",
"* key: string with the name of the parameter (the same name that has in the circuit)\n",
"In addition we can use the parameters of the circuit providing a pandas DataFrame to the function. In this case the function can be used for setting the parameters for any circuit! The parameters should be passed as a pandas DataFrame with 2 columns:\n",
"* key: string with the name of the parameter (the same name that is in the circuit)\n",
"* value: float value of the correspondent parameter"
]
},
Expand Down Expand Up @@ -296,8 +290,8 @@
"source": [
"#### 1.1.3 Solving the ansatz\n",
"\n",
"Now we can use the *SolveCircuit* class for solving the circuit. The main inputs are:\n",
"* circuit: QLM circuit were the parameter wer set\n",
"Now we can use the *SolveCircuit* class to solve the circuit. The main inputs are:\n",
"* circuit: QLM circuit where the parameters were set\n",
"* Input dictionary with the following keys:\n",
" * nqubits: number of qubits of the ansatz\n",
" * qpu: myqlm QPU used for solving the circuit\n",
Expand Down Expand Up @@ -389,8 +383,7 @@
"\n",
"Other ansatzes are implemented in the **ansatzes** module.\n",
"\n",
"\n",
"The function *ansatz_qlm_02* implements a generalization of the *ansatz_qlm_01* one. In the *ansatz_qlm_01* all the qubits has the same operations with the same parameters. In the *ansatz_qlm_02* each qubit has the same operations but each operation will have a different parameter.\n",
"The function *ansatz_qlm_02* implements a generalization of the *ansatz_qlm_01* one. In the *ansatz_qlm_01* all the qubits have the same operations with the same parameters. In the *ansatz_qlm_02* each qubit has the same operations but each operation will have a different parameter.\n",
"\n",
"The *SolveCircuit* class can be used for solving the ansatz"
]
Expand Down Expand Up @@ -703,9 +696,7 @@
"cell_type": "code",
"execution_count": null,
"id": "37f06d87",
"metadata": {
"scrolled": false
},
"metadata": {},
"outputs": [],
"source": [
"circuit = ansatz_selector('simple01', **conf_dict)\n",
Expand Down Expand Up @@ -770,9 +761,7 @@
"cell_type": "code",
"execution_count": null,
"id": "fa897cb6",
"metadata": {
"scrolled": false
},
"metadata": {},
"outputs": [],
"source": [
"circuit = ansatz_selector('hwe', **conf_dict)\n",
Expand All @@ -786,7 +775,7 @@
"source": [
"## 1.5 run_ansatz\n",
"\n",
"The complete ansatz solving procces can be done by using the function *run_ansatz* of the **ansatzes** module. A complete configuration dictionary should be provided and the function executes the complete steps for ansatz creation and solve."
"The complete ansatz-solving process can be done by using the function *run_ansatz* of the **ansatzes** module. A complete configuration dictionary should be provided and the function executes the complete steps for ansatz creation and solve."
]
},
{
Expand Down Expand Up @@ -884,7 +873,7 @@
"source": [
"## 2. Line command\n",
"\n",
"Additionally the **ansatzes** module can be used from command line and several parameters can be provided for congfiguring the ansatz. \n",
"Additionally, the **ansatzes** module can be used from the command line and several parameters can be provided for configuring the ansatz. \n",
"\n",
" For getting a help type: *python ansatzes.py -h*.\n",
"\n",
Expand Down Expand Up @@ -913,8 +902,8 @@
"source": [
"## 3. Submitting jobs to QLM (only for QLM users)\n",
"\n",
"If the ansatz has a great number of qubits or have high depths computations using **myQLM** can not be done (or need lot of time). In these cases computations can be executed in a **Eviden QLM hardware platform** (CESGA has one available for their users able to simultate until 35 qubits). In this case the computation can be submitted to the **QLM** and be retrieved when finished.\n",
"For submiting an ansatz computation to the **QLM**, in addtion with the arguments showed before, following argument should be provided:\n",
"If the ansatz has a great number of qubits or has high depths computations using **myQLM** can not be done (or need a lot of time). In these cases, computations can be executed in an **Eviden QLM hardware platform** (CESGA has one available for their users able to simulate until 35 qubits). In this case, the computation can be submitted to the **QLM** and retrieved when finished.\n",
"For submitting an ansatz computation to the **QLM**, in addition with the arguments shown before, the following argument should be provided:\n",
"\n",
"* --submit: For submiting ansatz to QLM\n",
"\n",
Expand All @@ -926,12 +915,12 @@
"id": "30543470",
"metadata": {},
"source": [
"Once the computation is submitted to QLM we need to retrieve the results from the **QLM**. Following arguments can be used for getting the state:\n",
"Once the computation is submitted to QLM we need to retrieve the results from the **QLM**. The following arguments can be used for getting the state:\n",
"\n",
"* --get_job: For getting a job from QLM\n",
"* -jobid JOB_ID: jobid of the QLM job. Only when provided --get_job\n",
"* -filename FILENAME: Base Filename for saving. Only Valid with get_job\n",
"* --save: For storing resutls\n",
"* --save: For storing results\n",
"\n",
"If **--save** is provided the *-filename* should be provided too. The state will be saved as a csv with the name: **FILENAME_state.csv**"
]
Expand All @@ -943,15 +932,15 @@
"source": [
"## 4. Masive ansatzes computations\n",
"\n",
"For sendig several ansatzes at the same time the following files can be used:\n",
"For sending several ansatzes at the same time the following files can be used:\n",
"\n",
"* ansatzes.json: JSON file with the configuration of the desired ansatzes. Each posible configuration parameter in the JSON file has associated a list with the desired values. The total number of ansatzes will be all the posible combinations of the values of all the parameters. \n",
" * Example: if *nqubits: [10, 14]* and *depth: [1, 2, 3, 4]* (and the otheres parameters has only a one element) then the posible ansatzes will be 2 * 4 = 8.\n",
"* launch_ansatzes.py: this script allows to configure the ansatzes taking the configuration from the **ansatzes.json** and executes them. Use **python launch\\_ansatzes -h** for getting a help. The following arguments can be provided:\n",
"* ansatzes.json: JSON file with the configuration of the desired ansatzes. Each possible configuration parameter in the JSON file has associated a list with the desired values. The total number of ansatzes will be all the possible combinations of the values of all the parameters. \n",
" * Example: if *nqubits: [10, 14]* and *depth: [1, 2, 3, 4]* (and the other parameters have only one element) then the possible ansatzes will be 2 * 4 = 8.\n",
"* launch_ansatzes.py: this script allows to configuration of the ansatzes taking the configuration from the **ansatzes.json** and executing them. Use **python launch\\_ansatzes -h** to get help. The following arguments can be provided:\n",
" * --all: for executing all the posible ansatzes resulting from **ansatzes.json** file.\n",
" * -id ID: for executing only one posible ansatz (the number given by ID) from all the posible ansatzes from **ansatzes.json** file.\n",
" * -id ID: for executing only one possible ansatz (the number given by ID) from all the possible ansatzes from **ansatzes.json** file.\n",
" * --print: for printing the configuration of the ansatz\n",
" * --count: give the number of all the posible combinations resulting from **ansatzes.json** file.\n",
" * --count: give the number of all the possible combinations resulting from the **ansatzes.json** file.\n",
" * --exe: for executing the complete ansatz computation program"
]
},
Expand All @@ -960,24 +949,32 @@
"id": "d62de278",
"metadata": {},
"source": [
"## 5. Masive retrieving QLM\n",
"## 5. Massive retrieving QLM\n",
"\n",
"When using the **launch_ansatzes.py** you can send all the computations to the QLM (**submit** to True in the **ansatzes.json**). You can retrieving all the jobs with its correspondient JobId. You can use the **launch\\_get\\_jobs.py** script for recovering all the jobs automatically. This file uses the JSON file **get\\_jobs.json**. In the JSON file the JobIDs should be provided in the **job\\_id** field of the JSON. In this case one dictionary for JobID should be configurated in the JSON file.\n",
"When using the **launch_ansatzes.py** you can send all the computations to the QLM (**submit** to True in the **ansatzes.json**). You can retrieve all the jobs with their corresponding JobId. You can use the **launch\\_get\\_jobs.py** script to recover all the jobs automatically. This file uses the JSON file **get\\_jobs.json**. In the JSON file, the JobIDs should be provided in the **job\\_id** field of the JSON. In this case, one dictionary for JobID should be configured in the JSON file.\n",
"\n",
"For getting the help use: **pyhton launch\\_get\\_jobs.py**. The following arguments can be provided:\n",
"To get the help use: **pyhton launch\\_get\\_jobs.py**. The following arguments can be provided:\n",
" * --all: for executing all the posible recoverings from **get\\_jobs.json** file.\n",
" * -id ID: for executing only one posible recovering (the number given by ID) from all the posible ones from **get\\_jobs.json** file.\n",
" * -id ID: for executing only one possible recovery (the number given by ID) from all the possible ones from **get\\_jobs.json** file.\n",
" * --print: for printing the configuration of the recovering\n",
" * --count: give the number of all the posible recoverings from **get\\_jobs.json** file.\n",
" * --exe: for executing the complete recovering.\n"
" * --count: give the number of all the possible recoverings from **get\\_jobs.json** file.\n",
" * --exe: for executing the complete recovery.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5061b17e-8031-4203-a6f7-ba3ced2c8fff",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python [conda env:tnbs2c] *",
"language": "python",
"name": "python3"
"name": "conda-env-tnbs2c-py"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -989,7 +986,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.9"
"version": "3.11.7"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit 43f70e0

Please sign in to comment.