Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: functionality for new json schema and for complete decomposition #34

Merged
merged 33 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
a94ab3a
functionality for new json schema and for complete decomposition. WIP
JonhasSC May 6, 2024
c3cd40a
Updated pylint badge
github-actions[bot] May 6, 2024
3d9cf2d
chemistry utils added
JonhasSC May 6, 2024
b51e713
meged with feature/new-json-schema
JonhasSC May 6, 2024
f940d61
adding script for resource generation for quantum chemistry notebook
JonhasSC May 6, 2024
ddaa541
Add support for new output format to HTSC notebook
zmorrell May 6, 2024
4d427f9
fixing chemistry utils for generatig resource estimates appropriately
JonhasSC May 6, 2024
d4f2569
modified molecular_info to keep track of more information for the jso…
JonhasSC May 7, 2024
8b38718
Merge branch 'enhancement/photosynthesis-utils' into feature/new-json…
JonhasSC May 7, 2024
06fa5c8
removed unnecessary file
JonhasSC May 7, 2024
767853b
added scripts directory
JonhasSC May 8, 2024
5fd5d96
added estimatemetadata for rucl notebook
JonhasSC May 8, 2024
3b33cfa
Updated pylint badge
github-actions[bot] May 8, 2024
53afcb4
fixed test cases to remove a key that no longer appears in resource e…
JonhasSC May 8, 2024
325baa3
Add Two Band HTSC Python script
May 9, 2024
1c1d61b
Add one band HTSC script for running from command line
May 9, 2024
284132a
removed duplicate decomposition
zain2864 May 9, 2024
9f9cc96
included the estimatemetadata for the quantum chemistry notebook
JonhasSC May 10, 2024
316a08f
making sure for metadata for qsp evaluation for rucl notebook is done
JonhasSC May 14, 2024
860c53f
wip improvemnts to rucl script
May 14, 2024
e39c947
modified RuCl-RE file to include lattice size as arg and not over a r…
JonhasSC May 14, 2024
7ecc488
fixed state prep cell for RuCl notebook to gen resource estimate appr…
JonhasSC May 14, 2024
999cdcf
making metadata optional for resource estimates
JonhasSC May 15, 2024
082b6f7
Updated pylint badge
github-actions[bot] May 15, 2024
1d6e46c
made the metadata for resource estimates optional and created a utili…
JonhasSC May 15, 2024
189d514
Merge branch 'feature/new-json-schema' of github.com:lanl-ansi/qc-app…
JonhasSC May 15, 2024
897cd43
removing utility estimates and defaulting utility estimates to None
JonhasSC May 18, 2024
47b13ef
Reran RuCl notebook with removed utility estimates
JonhasSC May 18, 2024
853ed20
Reran magnetic lattice notebook with removed utility estimates
JonhasSC May 18, 2024
8c1f91f
Reran quantum chem notebook with removed utility estimates
JonhasSC May 18, 2024
a7a5ef3
reran HTSC notebook with removed utility estimates
JonhasSC May 18, 2024
7716e65
Updated pylint badge
github-actions[bot] May 18, 2024
6c5584e
Reset default values for HTSC scripts
zmorrell May 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
![pylint](https://img.shields.io/badge/PyLint-9.60-yellow?logo=python&logoColor=white)
![pylint](https://img.shields.io/badge/PyLint-9.50-yellow?logo=python&logoColor=white)
# Quantum Computing Application Specifications

Documentation of Applications for Quantum Computers
Expand Down
276 changes: 136 additions & 140 deletions notebooks/HighTemperatureSuperConductorExample.ipynb

Large diffs are not rendered by default.

365 changes: 238 additions & 127 deletions notebooks/MagneticLattices.ipynb

Large diffs are not rendered by default.

330 changes: 164 additions & 166 deletions notebooks/PhotosynthesisExample.ipynb

Large diffs are not rendered by default.

102 changes: 69 additions & 33 deletions notebooks/RuClExample.ipynb

Large diffs are not rendered by default.

111 changes: 111 additions & 0 deletions scripts/AP-RE.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import os
from dataclasses import dataclass
from argparse import ArgumentParser, Namespace
from concurrent.futures import ThreadPoolExecutor, as_completed, ProcessPoolExecutor
from qca.utils.chemistry_utils import load_pathway, generate_electronic_hamiltonians, gsee_molecular_hamiltonian

@dataclass
class pathway_info:
pathway: list[int]
fname: str

def grab_arguments() -> Namespace:
parser = ArgumentParser('Perform a sweep over different pathways of varying active spaces')
parser.add_argument(
'-A',
'--active_space_reduction',
type=int,
help='Factor to reduce the active space',
default=10
)
args = parser.parse_args()
return args

def generate_ap_re(
catalyst_name:str,
num_processes:int,
hamiltonians: list,
gsee_args:dict,
trotter_steps:int,
bits_precision: int
):
results = []
with ProcessPoolExecutor(max_workers=num_processes) as executor:
for idx, hamiltonian in enumerate(hamiltonians):
future = executor.submit(
gsee_molecular_hamiltonian,
f'pathway({idx})_{catalyst_name}',
gsee_args,
trotter_steps,
bits_precision,
hamiltonian
)
results.append(future)
for future in as_completed(results):
print(f'completed')

def grab_molecular_hamiltonians_pool(
active_space_reduc:float,
num_processes:int,
pathways: list,
basis:str
) -> list:
hamiltonians = []
results = []
with ThreadPoolExecutor(max_workers=num_processes) as executor:
for coords in pathways:
future = executor.submit(
generate_electronic_hamiltonians,
basis, active_space_reduc, coords, 1
)
results.append(future)
for future in as_completed(results):
hamiltonians.append(future.result())
return hamiltonians


if __name__ == '__main__':
pid = os.getpid()
args = grab_arguments()
active_space_reduc = args.active_space_reduction
pathways = [
pathway_info(
pathway=[27, 1, 14, 15, 16, 24, 25, 26],
fname='water_oxidation_Co2O9H12.xyz'
),
pathway_info(
pathway=[3, 1, 14, 15, 16, 20, 21, 22, 23],
fname='water_oxidation_Co2O9H12.xyz'
),
pathway_info(
pathway=[2, 1, 14, 15, 16, 17, 18, 19],
fname='water_oxidation_Co2O9H12.xyz'
),
pathway_info(
pathway=[5, 10, 28, 29, 30, 31, 32, 33],
fname='water_oxidation_Co2O9H12.xyz'
)
]
coords_pathways = [
load_pathway(pathway.fname, pathway.pathway) for pathway in pathways
]
molecular_hamiltonians = grab_molecular_hamiltonians_pool(
active_space_reduc=active_space_reduc,
num_processes=len(pathways),
pathways=coords_pathways,
basis='sto-3g'
)
gsee_args = {
'trotterize' : True,
'ev_time' : 1,
'trot_ord' : 2,
'trot_num' : 1
}
generate_ap_re(
catalyst_name='Co2O9H12',
num_processes=len(pathways),
hamiltonians=molecular_hamiltonians,
gsee_args=gsee_args,
trotter_steps=1,
bits_precision=10
)
110 changes: 110 additions & 0 deletions scripts/HTSC-one-band-RE.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#!/usr/bin/env python
import os
import argparse
import time
import openfermion as of
import numpy as np
import math
from pyLIQTR.PhaseEstimation.pe import PhaseEstimation
from networkx import get_node_attributes, draw, draw_networkx_edge_labels
from qca.utils.utils import circuit_estimate, EstimateMetaData
from qca.utils.hamiltonian_utils import generate_two_orbital_nx, nx_to_two_orbital_hamiltonian

def main(args):
lattice_size = args.lattice_size
tunneling = args.param_t1
coulomb = args.param_mu

error_precision = args.error_precision
trotter_steps = args.trotter_steps
trotter_order = args.trotter_order
name = args.name
directory = args.directory
value = args.value
repetitions = args.repetitions
circuit_write = args.circuit_write

ham = of.fermi_hubbard(lattice_size, lattice_size, tunneling=tunneling, coulomb=coulomb, periodic=False) #returns an aperiodic fermionic hamiltonian

trotter_order = 2
trotter_steps = 1 #Using one trotter step for a strict lower bound with this method

#this scales the circuit depth proportional to 2 ^ bits_precision
bits_precision = estimate_bits_precision(error_precision)

E_min = -len(ham.terms) * max(abs(tunneling), abs(coulomb))
E_max = 0
omega = E_max-E_min
t = 2*np.pi/omega
phase_offset = E_max*t

args = {
'trotterize' : True,
'mol_ham' : ham,
'ev_time' : t,
'trot_ord' : trotter_order,
'trot_num' : 1 #handling adjustment in resource estimate to save time - scales circuit depth linearly.
}


init_state = [0] * lattice_size * lattice_size * 2 #TODO: use Fock state from Hartree-Fock as initial state

print('starting')
metadata = EstimateMetaData(
id=time.time_ns(),
name=name,
category='scientific',
size=f'{lattice_size}x{lattice_size}',
task='Ground State Energy Estimation',
implementations=f'GSEE, evolution_time={t}, bits_precision={bits_precision}, trotter_order={trotter_order}',
)

t0 = time.perf_counter()
gse_inst = PhaseEstimation(
precision_order=1, #actual precision bits accounted as scaling factors in the resource estimate
init_state=init_state,
phase_offset=phase_offset,
include_classical_bits=False, # Do this so print to openqasm works
kwargs=args)
gse_inst.generate_circuit()
t1 = time.perf_counter()
print(f'One band GSEE time to generate high level Circuit: {t1 - t0}')

gse_circuit = gse_inst.pe_circuit

print('Estimating one_band')
t0 = time.perf_counter()
estimate = circuit_estimate(
circuit=gse_circuit,
metadata = metadata,
outdir=directory,
circuit_name=name,
write_circuits=circuit_write,
bits_precision=bits_precision,
numsteps=trotter_steps
)
t1 = time.perf_counter()
print(f'Time to estimate one_band: {t1-t0}')
return estimate

def estimate_bits_precision(epsilon):
return math.ceil(math.log2(1.0/epsilon))

def parse_arguments():
parser = argparse.ArgumentParser(prog='HTSC-two-band-RE')
parser.add_argument('-l', '--lattice-size', type=int, default=20)
parser.add_argument('-e', '--error-precision', type=float, default=1e-5)
parser.add_argument('-t', '--trotter-steps', type=int, default=1)
parser.add_argument('-to', '--trotter-order', type=int, default=2)
parser.add_argument('-t1', '--param-t1', type=float, default=-1)
parser.add_argument('-mu', '--param-mu', type=float, default=1)
parser.add_argument('-n', '--name', type=str, default=f'FermiHubbard-OneBand', help='name of this circuit instance, becomes prefix for output file')
parser.add_argument('-d', '--directory', type=str, default='./', help='output file directory')
parser.add_argument('-v', '--value', type=float, default=0, help='value of the total application')
parser.add_argument('-r', '--repetitions', type=int, default=1, help='repetitions needed to achieve value of computatation (not runs of this script)')
parser.add_argument('-c', '--circuit_write', default=False, action='store_true')
return parser

if __name__ == "__main__":
parser = parse_arguments()
main(parser.parse_args())
116 changes: 116 additions & 0 deletions scripts/HTSC-two-band-RE.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
#!/usr/bin/env python

import os
import argparse
import time
import openfermion as of
import numpy as np
import math
from pyLIQTR.PhaseEstimation.pe import PhaseEstimation
from networkx import get_node_attributes, draw, draw_networkx_edge_labels
from qca.utils.utils import circuit_estimate, EstimateMetaData
from qca.utils.hamiltonian_utils import generate_two_orbital_nx, nx_to_two_orbital_hamiltonian

## Two band

def main(args):
t1 = args.param_t1
t2 = args.param_t2
t3 = args.param_t3
t4 = args.param_t4
mu = args.param_mu

trotter_steps = args.trotter_steps
trotter_order = args.trotter_order

lattice_size = args.lattice_size

value = args.value
repetitions = args.repetitions
directory = args.directory
name = args.name

bits_precision = estimate_bits_precision(args.error_precision)
g = generate_two_orbital_nx(lattice_size,lattice_size)
n_qubits = len(g)

ham = nx_to_two_orbital_hamiltonian(g,t1,t2,t3,t4,mu)

E_min = -len(ham.terms) * max(abs(t1), abs(t2), abs(t3), abs(t4), abs(mu))
E_max = 0
omega = E_max-E_min
t = 2*np.pi/omega
phase_offset = E_max*t

init_state = [0] * n_qubits

pe_args = {
'trotterize' : True,
'mol_ham' : ham,
'ev_time' : t,
'trot_ord' : trotter_order,
'trot_num' : 1 #Accounted for in a scaling argument later
}


print('starting')

metadata = EstimateMetaData(
id=time.time_ns(),
name=name,
category='scientific',
size=f'{lattice_size}x{lattice_size}',
task='Ground State Energy Estimation',
implementations=f'GSEE, evolution_time={t}, bits_precision={bits_precision}, trotter_order={trotter_order}',
)

t0 = time.perf_counter()
gse_inst = PhaseEstimation(
precision_order=1,
init_state=init_state,
phase_offset=phase_offset,
include_classical_bits=False, # Do this so print to openqasm works
kwargs=pe_args)
gse_inst.generate_circuit()
t1 = time.perf_counter()
print(f'time to generate high level: {t1 - t0}')

gse_circuit = gse_inst.pe_circuit

print('Estimating Circuit Resources')
t0 = time.perf_counter()
estimate = circuit_estimate(
circuit=gse_circuit,
metadata = metadata,
outdir=directory,
circuit_name=name,
write_circuits=args.circuit_write,
bits_precision=bits_precision,
numsteps=trotter_steps)
t1 = time.perf_counter()
return estimate

def estimate_bits_precision(epsilon):
return math.ceil(math.log2(1.0/epsilon))

def parse_arguments():
parser = argparse.ArgumentParser(prog='HTSC-two-band-RE')
parser.add_argument('-l', '--lattice-size', type=int, default=10)
parser.add_argument('-e', '--error-precision', type=float, default=1e-3)
parser.add_argument('-t', '--trotter-steps', type=int, default=1)
parser.add_argument('-to', '--trotter-order', type=int, default=2)
parser.add_argument('-t1', '--param-t1', type=float, default=-1)
parser.add_argument('-t2', '--param-t2', type=float, default=1.3)
parser.add_argument('-t3', '--param-t3', type=float, default=0.85)
parser.add_argument('-t4', '--param-t4', type=float, default=0.85)
parser.add_argument('-mu', '--param-mu', type=float, default=1)
parser.add_argument('-n', '--name', type=str, default=f'FermiHubbard-TwoBand', help='name of this circuit instance, becomes prefix for output file')
parser.add_argument('-d', '--directory', type=str, default='./', help='output file directory')
parser.add_argument('-v', '--value', type=float, default=0, help='value of the total application')
parser.add_argument('-r', '--repetitions', type=int, default=1, help='repetitions needed to achieve value of computatation (not runs of this script)')
parser.add_argument('-c', '--circuit_write', default=False, action='store_true')
return parser

if __name__ == "__main__":
parser = parse_arguments()
main(parser.parse_args())
Loading
Loading