Skip to content

Commit

Permalink
Merge pull request #567 from Avimita-amc8313/hamlib-changes
Browse files Browse the repository at this point in the history
now we can work with all parameters of hamlib
  • Loading branch information
rtvuser1 authored Jul 10, 2024
2 parents fddfab5 + fa54eba commit 9f41ddf
Show file tree
Hide file tree
Showing 8 changed files with 5,241 additions and 542 deletions.
2 changes: 1 addition & 1 deletion hamlib/_common/hamiltonian_simulation_exact.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def HamiltonianSimulationExact(n_spins: int, init_state=None):
dict: The distribution of the evolved state.
"""
_, hamiltonian_sparse, _ = create_circuit(n_spins=n_spins, init_state=init_state)
time_problem = TimeEvolutionProblem(hamiltonian_sparse, 0.2, initial_state=initial_state(n_spins, init_state))
time_problem = TimeEvolutionProblem(hamiltonian_sparse, 1, initial_state=initial_state(n_spins, init_state))
result = SciPyRealEvolver(num_timesteps=1).evolve(time_problem)

# if verbose:
Expand Down
1,166 changes: 642 additions & 524 deletions hamlib/qiskit/benchmarks-qiskit.ipynb

Large diffs are not rendered by default.

289 changes: 289 additions & 0 deletions hamlib/qiskit/benchmarks-qiskit_hamlib_parameter.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,289 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### QED-C Application-Oriented Benchmarks - Qiskit Version\n",
"The notebook contains a suite of application-oriented benchmarks for the Qiskit API.\n",
"Configure and run the cell below with the desired execution settings.\n",
"Then execute the remaining cells, each containing one benchmark program."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"%reload_ext autoreload\n",
"%autoreload 2"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"min_qubits=2\n",
"max_qubits=10\n",
"skip_qubits=1\n",
"max_circuits=1\n",
"num_shots=1000\n",
"\n",
"backend_id=\"qasm_simulator\"\n",
"#backend_id=\"statevector_simulator\"\n",
"\n",
"hub=\"ibm-q\"; group=\"open\"; project=\"main\"\n",
"provider_backend = None\n",
"exec_options = {}\n",
"\n",
"# # ==========================\n",
"# # *** If using IBMQ hardware, run this once to authenticate\n",
"# from qiskit import IBMQ\n",
"# IBMQ.save_account('YOUR_API_TOKEN_HERE')\n",
"\n",
"# # *** If you are part of an IBMQ group, set hub, group, and project name here\n",
"# hub=\"YOUR_HUB_NAME\"; group=\"YOUR_GROUP_NAME\"; project=\"YOUR_PROJECT_NAME\"\n",
"\n",
"# # *** This example shows how to specify an IBMQ backend using a known \"backend_id\"\n",
"# exec_options = { \"optimization_level\":3, \"use_sessions\":True, \"resilience_level\":1}\n",
"# backend_id=\"ibmq_belem\"\n",
"\n",
"# # ==========================\n",
"# # *** If using Azure Quantum, use this hub identifier and specify the desired backend_id\n",
"# # Identify your resources with env variables AZURE_QUANTUM_RESOURCE_ID and AZURE_QUANTUM_LOCATION\n",
"# hub=\"azure-quantum\"; group=\"open\"; project=\"QED-C App-Oriented Benchmarks - Qiskit Version\"\n",
"# backend_id=\"<YOUR_BACKEND_NAME_HERE>\"\n",
"\n",
"# # ==========================\n",
"# The remaining examples illustrate other backend execution options\n",
"\n",
"# # An example using IonQ provider\n",
"# from qiskit_ionq import IonQProvider\n",
"# provider = IonQProvider() # Be sure to set the QISKIT_IONQ_API_TOKEN environment variable\n",
"# provider_backend = provider.get_backend(\"ionq_qpu\")\n",
"# backend_id=\"ionq_qpu\"\n",
"\n",
"# # An example using BlueQubit provider (backend_id=CPU/QPU, device=cpu/qpu)\n",
"# import sys\n",
"# sys.path.insert(1, \"../..\")\n",
"# import os, bluequbit, _common.executors.bluequbit_executor as bluequbit_executor\n",
"# provider_backend = bluequbit.init()\n",
"# backend_id=\"BlueQubit-CPU\"\n",
"# exec_options = { \"executor\": bluequbit_executor.run, \"device\":\"cpu\" }\n",
"\n",
"# # An example using a typical custom provider backend (e.g. AQT simulator)\n",
"# import os\n",
"# from qiskit_aqt_provider import AQTProvider\n",
"# provider = AQTProvider(os.environ.get('AQT_ACCESS_KEY')) # get your key from environment\n",
"# provider_backend = provider.backends.aqt_qasm_simulator_noise_1\n",
"# backend_id=\"aqt_qasm_simulator_noise_1\"\n",
"\n",
"# # Fire Opal can be used to manage executions on other backends, as illustrated here\n",
"# import _common.executors.fire_opal_executor as fire_opal_executor\n",
"# from _common.executors.fire_opal_executor import FireOpalBackend\n",
"# ibm_backend_id = \"ibmq_jakarta\"\n",
"# backend_id = f\"fire_opal_{ibm_backend_id}\"\n",
"# provider_backend = FireOpalBackend(ibm_backend_id=ibm_backend_id, hub=hub, group=group, project=project, token=token)\n",
"# exec_options = {\"executor\": fire_opal_executor.run}\n"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"# Custom optimization options can be specified in this cell (below is an example)\n",
"\n",
"# # Example of pytket Transformer\n",
"# import _common.transformers.tket_optimiser as tket_optimiser\n",
"# exec_options.update({ \"optimization_level\": 0, \"layout_method\":'sabre', \"routing_method\":'sabre', \"transformer\": tket_optimiser.high_optimisation })\n",
"\n",
"# # Define a custom noise model to be used during execution\n",
"# import _common.custom.custom_qiskit_noise_model as custom_qiskit_noise_model\n",
"# exec_options.update({ \"noise_model\": custom_qiskit_noise_model.my_noise_model() })\n",
"\n",
"# # Example of mthree error mitigation\n",
"# import _common.postprocessors.mthree.mthree_em as mthree_em\n",
"# exec_options.update({ \"postprocessor\": mthree_em.get_mthree_handlers(backend_id, provider_backend) })\n"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"import hamlib_simulation_benchmark, hamlib_simulation_kernel, hamlib_utils\n",
"import execute\n",
"import metrics\n",
"\n",
"execute.verbose = False\n",
"execute.verbose_time = False\n",
"hamlib_simulation_benchmark.verbose = False\n",
"hamlib_simulation_kernel.verbose = False\n",
"hamlib_utils.verbose = False\n",
"\n",
"hamlib_simulation_kernel.global_U = None\n",
"hamlib_simulation_kernel.global_enc = None\n",
"hamlib_simulation_kernel.global_ratio = None\n",
"hamlib_simulation_kernel.global_rinst = None\n",
"hamlib_simulation_kernel.global_h = None\n",
"hamlib_simulation_kernel.global_pbc_val = None"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Hamiltonian Simulation - All Methods"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Hamiltonian Simulation - tfim or hisenberg"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import sys\n",
"sys.path.insert(1, \"hamlib/qiskit\")\n",
"# exec_options = {\"noise_model\" : None}\n",
"\n",
"# Set the hamiltonian_name: 'TFIM', 'Fermi-Hubbard-1D', 'Bose-Hubbard-1D', 'Heisenberg' or 'Max3Sat'\n",
"i = 1\n",
"for method in [2]:\n",
" for hamiltonian_name in ['tfim']:\n",
" for pbc_val in ['pbc','nonpbc']:\n",
" for h in [4,6]:\n",
" exec_options = {\"noise_model\" : None}\n",
" hamlib_simulation_kernel.global_h = h\n",
" hamlib_simulation_kernel.global_pbc_val = pbc_val\n",
" print('Circuit Set', i, 'out of 4')\n",
" print('Method, Hamiltonian, h, pbc_val = ',method, hamiltonian_name, h, pbc_val)\n",
" print('=======================================================')\n",
" metrics.data_suffix = f'_method_{method}_{hamiltonian_name}_{pbc_val}_h_{h}_noiseless'\n",
"\n",
" hamlib_simulation_benchmark.run(min_qubits=min_qubits, max_qubits=max_qubits, skip_qubits=skip_qubits,\n",
" max_circuits=max_circuits, num_shots=num_shots,\n",
" method=method, hamiltonian = hamiltonian_name, init_state=None,\n",
" backend_id=backend_id, provider_backend=provider_backend,\n",
" hub=hub, group=group, project=project, exec_options=exec_options\n",
" )\n",
" i = i + 1"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Hamiltonian Simulation - fermi-hubbard or bose-hubbard"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import sys\n",
"sys.path.insert(1, \"hamlib/qiskit\")\n",
"# exec_options = {\"noise_model\" : None}\n",
"\n",
"# Set the hamiltonian_name: 'TFIM', 'Fermi-Hubbard-1D', 'Bose-Hubbard-1D', 'Heisenberg' or 'Max3Sat'\n",
"i = 1\n",
"for method in [2]:\n",
" for hamiltonian_name in ['Fermi-Hubbard-1D']:\n",
" for pbc_val in ['pbc','nonpbc']:\n",
" for U in [8]:\n",
" for enc in ['bk', 'jw', 'parity']:\n",
" exec_options = {\"noise_model\" : None}\n",
" hamlib_simulation_kernel.global_U = U\n",
" hamlib_simulation_kernel.global_enc = enc\n",
" hamlib_simulation_kernel.global_pbc_val = pbc_val\n",
" print('Circuit Set', i, 'out of 6')\n",
" print('Method, Hamiltonian, pbc_val, U, enc = ',method, hamiltonian_name, pbc_val, U, enc)\n",
" print('=======================================================')\n",
" metrics.data_suffix = f'_method_{method}_fh_{pbc_val}_U_{U}_enc_{enc}_noiseless'\n",
"\n",
" hamlib_simulation_benchmark.run(min_qubits=min_qubits, max_qubits=max_qubits, skip_qubits=skip_qubits,\n",
" max_circuits=max_circuits, num_shots=num_shots,\n",
" method=method, hamiltonian = hamiltonian_name, init_state=None,\n",
" backend_id=backend_id, provider_backend=provider_backend,\n",
" hub=hub, group=group, project=project, exec_options=exec_options\n",
" )\n",
" i = i + 1"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Hamiltonian Simulation - Max3Sat"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import sys\n",
"sys.path.insert(1, \"hamlib/qiskit\")\n",
"# exec_options = {\"noise_model\" : None}\n",
"\n",
"# Set the hamiltonian_name: 'TFIM', 'Fermi-Hubbard-1D', 'Bose-Hubbard-1D', 'Heisenberg' or 'Max3Sat'\n",
"i = 1\n",
"for method in [2]:\n",
" for hamiltonian_name in ['Max3Sat']:\n",
" for ratio in [2,3,4,5]:\n",
" for rinst in ['00', '01', '02', '03', '04', '05', '06', '07', '08', '09']:\n",
" exec_options = {\"noise_model\" : None}\n",
" hamlib_simulation_kernel.global_ratio = ratio\n",
" hamlib_simulation_kernel.global_rinst = rinst\n",
" print('Circuit Set', i, 'out of 40')\n",
" print('Method, Hamiltonian, ration, rinst = ',method, hamiltonian_name, ratio, rinst)\n",
" print('=======================================================')\n",
" metrics.data_suffix = f'_method_{method}_max3sat_ratio_{ratio}_rinst_{rinst}_noiseless'\n",
"\n",
" hamlib_simulation_benchmark.run(min_qubits=min_qubits, max_qubits=max_qubits, skip_qubits=skip_qubits,\n",
" max_circuits=max_circuits, num_shots=num_shots,\n",
" method=method, hamiltonian = hamiltonian_name, init_state=None,\n",
" backend_id=backend_id, provider_backend=provider_backend,\n",
" hub=hub, group=group, project=project, exec_options=exec_options\n",
" )\n",
" i = i + 1"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.3"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
24 changes: 12 additions & 12 deletions hamlib/qiskit/hamlib_parameter_use_input.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
{
"FH_D-1.hdf5": {
"fh": "graph-1D-grid-nonpbc-qubitnodes",
"fh": "graph-1D-grid-{pbc_val}-qubitnodes",
"Lx": "{n_qubits/2}",
"U": "0",
"enc": "jw"
"U": "{U}",
"enc": "{enc}"
},
"tfim.hdf5": {
"graph": "1D-grid-nonpbc-qubitnodes",
"graph": "1D-grid-{pbc_val}-qubitnodes",
"Lx": "{n_qubits}",
"h": "0.1"
"h": "{h}"
},
"random_max3sat-hams.hdf5": {
"max3sat_n": "{n_qubits}",
"ratio": "2",
"rinst": "00"
"ratio": "{ratio}",
"rinst": "{rinst}"
},
"heis.hdf5": {
"graph": "1D-grid-nonpbc-qubitnodes",
"graph": "1D-grid-{pbc_val}-qubitnodes",
"Lx": "{n_qubits}",
"h": "0"
"h": "{h}"
},
"BH_D-1_d-4.hdf5": {
"bh_graph": "1D-grid-nonpbc-qubitnodes",
"bh_graph": "1D-grid-{pbc_val}-qubitnodes",
"Lx": "{n_qubits/2}",
"U": "10",
"enc": "gray",
"U": "{U}",
"enc": "{enc}",
"d": "4"
}
}
Loading

0 comments on commit 9f41ddf

Please sign in to comment.