Skip to content

Commit

Permalink
More corrections for documenting
Browse files Browse the repository at this point in the history
  • Loading branch information
gonfeco committed Nov 2, 2023
1 parent 3c9d252 commit f91b24e
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 362 deletions.
14 changes: 11 additions & 3 deletions tnbs/BTC_04_PH/PH/notebooks/02_Using_PH_Class.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,7 @@
},
{
"cell_type": "markdown",
"id": "a95ab5cc",
"id": "e4cdf3b2",
"metadata": {},
"source": [
"## 4. run_parent_hamiltonian function\n",
Expand All @@ -944,7 +944,7 @@
},
{
"cell_type": "markdown",
"id": "f97d6e0f",
"id": "1cae3e40",
"metadata": {},
"source": [
"## 5. Command Line execution\n",
Expand All @@ -963,7 +963,7 @@
},
{
"cell_type": "markdown",
"id": "016545ec",
"id": "0d4604b0",
"metadata": {},
"source": [
"## 6. Massive PH computations\n",
Expand All @@ -982,6 +982,14 @@
" * **--print**: for printing the parent hamiltonian configuration.\n",
" * **--exe**: for executing the parent hamiltonian execution indicated by **--all** or by **-id ID**."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d665bba2",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
98 changes: 88 additions & 10 deletions tnbs/BTC_04_PH/PH/notebooks/03_ParentHamiltonian_execution.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"source": [
"# Using PH_EXE class\n",
"\n",
"This notebook explains how to use the **PH_EXE** class inside *execution_ph* module. \n",
"This notebook explains how to use the **PH\\_EXE** class inside **vqe\\_step** module. \n",
"\n",
"This class, given an ansatz and its parent hamiltonian, provided as a string Pauli decomposition, computes the asociated ground state energy (that should be near zero)."
]
Expand Down Expand Up @@ -84,19 +84,28 @@
"source": [
"Before doing the siumulation we need to perform several steps:\n",
"\n",
"1. Ansatz Definition\n",
"2. Ansatz Solving\n",
"3. Parent Hamiltonian Computation"
"1. Ansatz Definition and Solving (doing with functions from **ansatzes** module).\n",
"2. Parent Hamiltonian Computation (doing with functions from **parent\\_hamiltonian** module)"
]
},
{
"cell_type": "markdown",
"id": "206806ed",
"metadata": {},
"source": [
"## 1. Ansatz Definition\n",
"## 1. Ansatz Definition and Solving\n",
"\n",
"First we need to create the myqlm cirucit implementation of the desired ansatz (see notebook **01_Ansatzes.ipynb**) "
"We neeed to define an ansatz circuit and solving it for getting its state (see **01_Ansatzes.ipynb**. We can use the functions from **ansatzes** module"
]
},
{
"cell_type": "markdown",
"id": "fe58f7a8",
"metadata": {},
"source": [
"### Ansatz definition\n",
"\n",
"First we define an ansatz circuit"
]
},
{
Expand Down Expand Up @@ -175,7 +184,7 @@
"id": "1dfdb9e4",
"metadata": {},
"source": [
"## 2. Ansatz Solution\n",
"### Ansatz Solution\n",
"\n",
"Now we need to fix the parameters of the ansatz and solving it(see notebook **01_Ansatzes.ipynb**)"
]
Expand Down Expand Up @@ -238,9 +247,9 @@
"id": "31ee289c",
"metadata": {},
"source": [
"## 3. Parent Hamiltonian Computation\n",
"## 2. Parent Hamiltonian Computation\n",
"\n",
"With the obtained state of the ansatz we need to compute the Parent Hamiltonian and get its Pauli string decomposition."
"With the obtained state of the ansatz we need to compute the Parent Hamiltonian and get its Pauli string decomposition. Here we use the **parent\\_hamiltonian** module (see notebook **02_Using_PH_Class.ipynb** for more information)"
]
},
{
Expand Down Expand Up @@ -323,7 +332,7 @@
"metadata": {},
"outputs": [],
"source": [
"from execution_ph import PH_EXE"
"from vqe_step import PH_EXE"
]
},
{
Expand Down Expand Up @@ -403,6 +412,75 @@
"source": [
"If save was required the complete information (axis 1 concatenation of *exe_ph.pdf_result* and *exe_ph.pdf_result*) will be saved as: folder + filename+*_phexe.csv*"
]
},
{
"cell_type": "markdown",
"id": "55bd78eb",
"metadata": {},
"source": [
"## 5. run_ph_execution\n",
"\n",
"Inside the module **vqe_step** the **run_ph_execution** function can be found. This function uses typical **CSV** files from **ansatzes** and **parent_hamiltonian** modules for executing a **VQE** step. The input of this function is a **kwargs** (called **configuration**) where following keywords are processed:\n",
"\n",
"* base_fn: Base name for the files generated by **ansatzes** and **parent_hamiltonian**. The pattern of the name must be the following: **ansatz\\_{}\\_nqubits\\_{}\\_depth\\_{}\\_qpu_ansatz\\_{}**. It is mandatory that following files exist:\n",
" * **ansatz\\_{}\\_nqubits\\_{}\\_depth\\_{}\\_qpu_ansatz\\_{}\\_parameter.csv**: with the angles of the ansatz\n",
" * **ansatz\\_{}\\_nqubits\\_{}\\_depth\\_{}\\_qpu_ansatz\\_{}\\_pauli.csv**: with the Pauli decomposition of the **PH**.\n",
" * From the *base_fn* following variables are extracted: \n",
" * ansatz\n",
" * nqubits\n",
" * depth\n",
"* qpu_ph: name with the qpu for executing the **VQE** step simulation. Valid names: [qlmass, python, c].\n",
"* nb_shots: for setting the number of shots for the **VQE** step. Only valid for **nb_shots=qlmass**\n",
"* t_inv: True if the ansatz is transaltional invariant.\n",
"* truncation: integer for tuncating the Pauli coefficients\n",
"* save: for saving the results. The results will be saved with the followi9ng pattern:\n",
" * **ansatz\\_{}\\_nqubits\\_{}\\_depth\\_{}\\_qpu_ansatz\\_{}\\_ph\\_exe.csv**"
]
},
{
"cell_type": "markdown",
"id": "1950d87c",
"metadata": {},
"source": [
"## 6. Command Line execution\n",
"\n",
"The **run_ph_execution** function from module **vqe_step** can be executed from command line. Several arguments can be passed for configuring the **VQE** step computation. A help can be obtained by:\n",
"\n",
"**python vqe_step.py -h**\n",
"\n",
"Arguments can be:\n",
"\n",
"* -basefn BASE_FN: Base Filename for Loading Files\n",
"* -nb_shots NB_SHOTS Number of shots\n",
"* -truncation TRUNCATION: Truncation for Pauli coeficients.\n",
"* -qpu_ph QPU_PH: QPU for **VQE** simulation: [qlmass, python, c]\n",
"* --t_inv: Setting translational invariant of the ansatz\n",
"* --save: For storing results"
]
},
{
"cell_type": "markdown",
"id": "1eea57b0",
"metadata": {},
"source": [
"## 7. Massive VQE step computations\n",
"\n",
"As for the case of masive ansatz state and parent hamiltonian computations (see Notebook 01_Ansatzes.ipynb and 02_Using_PH_Class.ipynb) we can execute masive **VQE** step computations.For this the 2 following files can be used:\n",
"\n",
"* **vqe\\_step.json**: JSON file with the configuration for the **VQE** step computations. For each desired computation a complete dictionary should be provided. The keys are:\n",
" * save: for saving or not the results\n",
" * t_inv: for setting if the ansatz is, or not, translational invariant.\n",
" * base_fn: base name for the inputs files.\n",
" * nb_shots: number of shots for **VQE** step.\n",
" * qpu_ph: qpu for executing **VQE** step.\n",
" * truncation: for tuncating Pauli coefficients.\n",
"* **launch_vqe_step.py**: This scripts procces the before **JSON** file creating a complete list of all posible **VQE** calculations. By providing different arguments a selected configuration (or all of them) can be chosen. For getting help use: **launch_vqe_step.py -h**. Following arguments can be provided:\n",
" * **--count**: Getting the number of posible **VQE** steps from the **vqe\\_stepjson** JSON file.\n",
" * **--all**: for selecting all the posible **VQE** steps from the **vqe\\_stepjson** JSON file.\n",
" * **-id ID**: for selecting a single (the **ID** one) **VQE** step from the **vqe\\_stepjson** JSON file.\n",
" * **--print**: for printing the **VQE** step configuration.\n",
" * **--exe**: for executing the **VQE** execution indicated by **--all** or by **-id ID**."
]
}
],
"metadata": {
Expand Down
8 changes: 0 additions & 8 deletions tnbs/BTC_04_PH/PH/vqe_step.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[
{
"save": [true],
"t_inv": [true],
"base_fn" : ["Test/ansatz_simple01_nqubits_12_depth_1_qpu_ansatz_c"],
"nb_shots": [null],
"truncation": [null],
Expand All @@ -11,7 +10,6 @@
},
{
"save": [true],
"t_inv": [true],
"base_fn" : ["Test/ansatz_simple01_nqubits_12_depth_2_qpu_ansatz_c"],
"nb_shots": [null],
"truncation": [null],
Expand All @@ -21,7 +19,6 @@
},
{
"save": [true],
"t_inv": [true],
"base_fn" : ["Test/ansatz_simple01_nqubits_12_depth_3_qpu_ansatz_c"],
"nb_shots": [null],
"truncation": [null],
Expand All @@ -31,7 +28,6 @@
},
{
"save": [true],
"t_inv": [true],
"base_fn" : ["Test/ansatz_simple01_nqubits_12_depth_4_qpu_ansatz_c"],
"nb_shots": [null],
"truncation": [null],
Expand All @@ -41,7 +37,6 @@
},
{
"save": [true],
"t_inv": [true],
"base_fn" : ["Test/ansatz_simple01_nqubits_14_depth_1_qpu_ansatz_c"],
"nb_shots": [null],
"truncation": [null],
Expand All @@ -51,7 +46,6 @@
},
{
"save": [true],
"t_inv": [true],
"base_fn" : ["Test/ansatz_simple01_nqubits_14_depth_2_qpu_ansatz_c"],
"nb_shots": [null],
"truncation": [null],
Expand All @@ -61,7 +55,6 @@
},
{
"save": [true],
"t_inv": [true],
"base_fn" : ["Test/ansatz_simple01_nqubits_14_depth_3_qpu_ansatz_c"],
"nb_shots": [null],
"truncation": [null],
Expand All @@ -71,7 +64,6 @@
},
{
"save": [true],
"t_inv": [true],
"base_fn" : ["Test/ansatz_simple01_nqubits_14_depth_4_qpu_ansatz_c"],
"nb_shots": [null],
"truncation": [null],
Expand Down
7 changes: 0 additions & 7 deletions tnbs/BTC_04_PH/PH/vqe_step_fromfile.json

This file was deleted.

Loading

0 comments on commit f91b24e

Please sign in to comment.