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

Quantum Chromodynamics Notebook #62

Merged
merged 26 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
8282d78
wrote some down and added block of code for state prep
JonhasSC Aug 5, 2024
0e4d251
wrote more on background of application and initial state
JonhasSC Aug 6, 2024
19159b0
finished writing background for qcd problem
JonhasSC Aug 7, 2024
02c295d
dynamics implemented for qcd
JonhasSC Aug 7, 2024
36a8083
cleaned up nb
JonhasSC Aug 8, 2024
3d6c563
getting resource estimates now from qcd that actually includes correc…
JonhasSC Aug 9, 2024
79850f4
cleaned up qcd notebook
JonhasSC Aug 9, 2024
8b23324
cleaned up qcd notebook
JonhasSC Aug 9, 2024
3e93d9e
fixed bug for normalization factor
JonhasSC Aug 9, 2024
15f6c83
made changes to random variables to grab random numbers from a normal…
Oct 8, 2024
605af5b
modified grabbing params for hamiltonian generation
JonhasSC Oct 8, 2024
1c463b7
adding script file to generate resource estimates for QCD
JonhasSC Oct 8, 2024
b3e8585
modified gitignore to account for DS_STORE files
JonhasSC Oct 10, 2024
1ed6c97
tweaks to qcd script
JonhasSC Oct 10, 2024
2ea511a
added files and section for analysis of resource estimates from perfo…
JonhasSC Oct 10, 2024
8e71e9f
Updated pylint badge
github-actions[bot] Oct 10, 2024
b803799
merged with dev
JonhasSC Oct 10, 2024
b3fcf09
Updated pylint badge
github-actions[bot] Oct 10, 2024
a3db774
improve readability and fix typos
zain2864 Oct 12, 2024
5f99e18
fixed qcd notebook
JonhasSC Nov 4, 2024
27e9a84
updated qcd notebook to this branch
JonhasSC Nov 4, 2024
1adf401
added params for qcd script
JonhasSC Nov 12, 2024
411bd88
added new figures and allowed trotter order to be variable. For the m…
JonhasSC Nov 12, 2024
26bf368
made simpler process for constructing edges for neutrinos
JonhasSC Nov 14, 2024
b05ea3a
modified QCD script to pass in arguments positionally and added in be…
JonhasSC Nov 14, 2024
5f7186c
removed useless expr for qcd script
JonhasSC Nov 14, 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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ __pycache__/
# C extensions
*.so

# Mac attribute files
.DS_Store
.DS_Store?

# Distribution / packaging
.Python
build/
Expand Down
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.42-yellow?logo=python&logoColor=white)
![pylint](https://img.shields.io/badge/PyLint-9.29-yellow?logo=python&logoColor=white)

# Quantum Computing Application Specifications

Expand Down
Binary file added notebooks/EmbeddedFigures/gate_count_total.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added notebooks/EmbeddedFigures/t_count_total.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
419 changes: 419 additions & 0 deletions notebooks/QuantumChromoDynamicsExample.ipynb

Large diffs are not rendered by default.

124 changes: 124 additions & 0 deletions scripts/QCD-RE.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
from argparse import ArgumentParser

import numpy as np

import networkx as nx

from qca.utils.algo_utils import estimate_trotter
from qca.utils.hamiltonian_utils import flatten_nx_graph, pyliqtr_hamiltonian_to_openfermion_qubit_operator

from pyLIQTR.utils.Hamiltonian import Hamiltonian as pyH

def parse_args():
parser = ArgumentParser(prog='QCD Resource Estimate Generator')
parser.add_argument('-N', '--n_neutrinos', type=int, help='Number of neutrinos in the forward scattering model')
parser.add_argument('-T', '--trotter_steps', type=int, default=None, help='Number of trotter steps')
parser.add_argument('-d', '--directory', type=str, default='./', help='output file directory')
parser.add_argument('-S', '--site_inter', type=float, default=0.0, help='site interaction terms')
parser.add_argument('-P', '--energy_precision', type=float, required=True, help='acceptable shift in state energy')
return parser.parse_args()

def generate_spherical_momentum() -> list[float]:
rng = np.random.default_rng()
x = rng.normal(0, 1)
y = rng.normal(0, 1)
z = rng.normal(0, 1)
constant = 1/(np.sqrt(x**2 + y**2 + z**2))
ith_momentum = [
constant*x,
constant*y,
constant*z
]
return ith_momentum

def define_forward_scattering_term(n_neutrinos, curr_momentum, neighbor_momentum) -> float:
normalization_factor = 1/(np.sqrt(2)*n_neutrinos)
couplings = 1 - np.inner(curr_momentum, neighbor_momentum)
normalized_couplings = normalization_factor*couplings
return normalized_couplings

def gen_couplings(n_neutrinos: int, curr_id: int, neighbor_id: int, momentum: dict) -> float:
curr_momentum = momentum[curr_id]
neighbor_momentum = momentum[neighbor_id]
return define_forward_scattering_term(
n_neutrinos=n_neutrinos,
curr_momentum=curr_momentum,
neighbor_momentum=neighbor_momentum
)

def nx_heisenberg_terms(g:nx.Graph) -> list:
hamiltonian = []
n = len(g.nodes)
for (n1, n2, d) in g.edges(data=True):
weight = d['weight']
pauli_string = n * 'I'
for pauli in ['X', 'Y', 'Z']:
for i in range(len(g)):
if i == n1 or i == n2:
pauli_string = f'{pauli_string[:i]}{pauli}{pauli_string[i+1:]}'
hamiltonian.append((pauli_string, weight))

return hamiltonian

def generate_heisenberg_graph(n_neutrinos: int, site_interaction:float=0) -> nx.Graph:
graph = nx.Graph()
momentum = {}
seen = {}
node_id = 0
for _ in range(n_neutrinos):
graph.add_node(node_id, weight=site_interaction)
momentum[node_id] = generate_spherical_momentum()
seen[node_id] = []
node_id += 1

for node in graph.nodes:
curr_id = node
for neighbor in graph.nodes:
neighbor_id = neighbor
if neighbor != node and curr_id not in seen[neighbor_id] and neighbor_id not in seen[curr_id]:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see above comment on same function in python notebook.

coupling_terms = gen_couplings(
n_neutrinos = n_neutrinos,
curr_id = curr_id,
neighbor_id = neighbor_id,
momentum=momentum
)
graph.add_edge(node, neighbor, weight=coupling_terms)
seen[curr_id].append(neighbor_id)
seen[neighbor_id].append(curr_id)
return graph

def generate_forward_scattering(n_neutrinos: int, site_interactions:float=0):
graph = generate_heisenberg_graph(
n_neutrinos=n_neutrinos,
site_interaction=site_interactions
)
flat_graph = flatten_nx_graph(graph)
scattering_hamiltonian = nx_heisenberg_terms(flat_graph)
return scattering_hamiltonian


def main():
args = parse_args()
n_neutrinos = args.n_neutrinos
num_steps = args.trotter_steps
site_interactions = args.site_inter
hamiltonian = generate_forward_scattering(n_neutrinos, site_interactions)

evolution_time = np.sqrt(n_neutrinos)
h_neutrino_pyliqtr = pyH(hamiltonian)
qb_op_hamiltonian = pyliqtr_hamiltonian_to_openfermion_qubit_operator(h_neutrino_pyliqtr)

fname = f'{num_steps}_step_fs_{n_neutrinos}' if num_steps else f'estimated_fs_{n_neutrinos}'
outdir = args.directory
energy_precision = args.energy_precision
estimate_trotter(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See corresponding comment in python notebook

qb_op_hamiltonian,
evolution_time,
energy_precision,
outdir,
hamiltonian_name=fname,
nsteps=num_steps
)

if __name__ == '__main__':
main()
7 changes: 4 additions & 3 deletions src/qca/utils/algo_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,11 @@ def estimate_trotter(
evolution_time: float,
energy_precision: float,
outdir:str,
metadata: EstimateMetaData=None,
metadata: EstimateMetaData | None =None,
hamiltonian_name:str='hamiltonian',
write_circuits:bool=False,
nsteps:int=None,
nsteps:int | None =None,
trotter_order: int | None = 2,
include_nested_resources:bool=True
) -> Circuit:

Expand All @@ -137,7 +138,7 @@ def estimate_trotter(

t0 = time.perf_counter()
trotter_circuit_of = trotterize_exp_qubop_to_qasm(openfermion_hamiltonian,
trotter_order=2,
trotter_order=trotter_order,
evolution_time=evolution_time/nsteps,
term_ordering=term_ordering)
t1 = time.perf_counter()
Expand Down
Loading