Skip to content

Commit

Permalink
Updated BTC_04_PH
Browse files Browse the repository at this point in the history
  • Loading branch information
gonfeco committed Sep 7, 2023
1 parent 6f69d36 commit ea51ba4
Show file tree
Hide file tree
Showing 8 changed files with 648 additions and 96 deletions.
50 changes: 43 additions & 7 deletions tnbs/BTC_04_PH/PH/btc_ph.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import time
import uuid
import sys
import os
import numpy as np
import pandas as pd
from qat.core import Observable, Term
Expand All @@ -24,6 +25,35 @@
logger = logging.getLogger('__name__')


def create_folder(folder_name):
"""
Check if folder exist. If not the function creates it
Parameters
----------
folder_name : str
Name of the folder
Returns
----------
folder_name : str
Name of the folder
"""

# Check if the folder already exists
if not os.path.exists(folder_name):
# If it does not exist, create the folder
os.mkdir(folder_name)
print(f"Folder '{folder_name}' created.")
else:
print(f"Folder '{folder_name}' already exists.")
if folder_name.endswith('/') != True:
folder_name = folder_name + "/"
return folder_name


def get_qpu(qpu=None):
"""
Function for selecting solver.
Expand All @@ -32,7 +62,8 @@ def get_qpu(qpu=None):
----------
qpu : str
* qlmass: for trying to use QLM as a Service connection to CESGA QLM
* qlmass: for trying to use QLM as a Service connection
to CESGA QLM
* python: for using PyLinalg simulator.
* c: for using CLinalg simulator
* mps: for using mps
Expand Down Expand Up @@ -141,13 +172,15 @@ def ph_btc(**kwargs):
quantum_time = tock - tick_q
elapsed_time = tock - tick
text = ['gse', 'elapsed_time', 'quantum_time']
res = pd.DataFrame(
pdf_info = pd.DataFrame(kwargs, index=[0])
result = pd.DataFrame(
[gse, elapsed_time, quantum_time],
index=text
).T
result = pd.concat([pdf_info, result], axis =1 )
if save:
res.to_csv(folder + filename_base+'_result.csv', sep=';')
return res
result.to_csv(folder + filename_base+'_result.csv', sep=';')
return result

if __name__ == "__main__":
import argparse
Expand Down Expand Up @@ -207,7 +240,10 @@ def ph_btc(**kwargs):
args = parser.parse_args()
print(args)
dict_ph = vars(args)
dict_ph.update({"qpu_ansatz": get_qpu(dict_ph['qpu_ansatz'])})
dict_ph.update({"qpu_ph": get_qpu(dict_ph['qpu_ph'])})
dict_ph.update({"qpu_ansatz": get_qpu(dict_ph["qpu_ansatz"])})
dict_ph.update({"qpu_ph": get_qpu(dict_ph["qpu_ph"])})
print(dict_ph)
ph_btc(**dict_ph)
if dict_ph["save"]:
dict_ph.update({"folder": create_folder(dict_ph["folder"])})
result = ph_btc(**dict_ph)
print(result)
95 changes: 94 additions & 1 deletion tnbs/BTC_04_PH/PH/notebooks/01_Ansatzes.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,16 @@
"lda_circ = make_ldca_circ(nqubit, depth)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "acfdd011",
"metadata": {},
"outputs": [],
"source": [
"make_ldca_circ?"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -466,7 +476,7 @@
"metadata": {},
"outputs": [],
"source": [
"hwe_circ = make_general_hwe_circ(nqubit, n_cycles=3)"
"hwe_circ = make_general_hwe_circ(nqubit, n_cycles=1)"
]
},
{
Expand Down Expand Up @@ -494,6 +504,89 @@
"solv_hwe.run()\n",
"solv_hwe.state"
]
},
{
"cell_type": "markdown",
"id": "5ce2d533",
"metadata": {},
"source": [
"### 1.4 Ansatz selector\n",
"\n",
"In order to simplify the ansatz selection a function called **ansatz_selector** was built. "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "17a0fb89",
"metadata": {},
"outputs": [],
"source": [
"from PH.ansatzes import ansatz_selector"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8aa75dc0",
"metadata": {},
"outputs": [],
"source": [
"conf_dict = {\n",
" 'nqubits' : 8,\n",
" 'depth' : 3\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "37f06d87",
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"circuit = ansatz_selector('simple01', **conf_dict)\n",
"%qatdisplay circuit --svg"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "34780806",
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"circuit = ansatz_selector('simple02', **conf_dict)\n",
"%qatdisplay circuit --svg"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "efbcae81",
"metadata": {},
"outputs": [],
"source": [
"circuit = ansatz_selector('lda', **conf_dict)\n",
"%qatdisplay circuit --svg"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fa897cb6",
"metadata": {
"scrolled": false
},
"outputs": [],
"source": [
"circuit = ansatz_selector('hwe', **conf_dict)\n",
"%qatdisplay circuit --svg"
]
}
],
"metadata": {
Expand Down
Loading

0 comments on commit ea51ba4

Please sign in to comment.