-
Notifications
You must be signed in to change notification settings - Fork 2
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
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 0e4d251
wrote more on background of application and initial state
JonhasSC 19159b0
finished writing background for qcd problem
JonhasSC 02c295d
dynamics implemented for qcd
JonhasSC 36a8083
cleaned up nb
JonhasSC 3d6c563
getting resource estimates now from qcd that actually includes correc…
JonhasSC 79850f4
cleaned up qcd notebook
JonhasSC 8b23324
cleaned up qcd notebook
JonhasSC 3e93d9e
fixed bug for normalization factor
JonhasSC 15f6c83
made changes to random variables to grab random numbers from a normal…
605af5b
modified grabbing params for hamiltonian generation
JonhasSC 1c463b7
adding script file to generate resource estimates for QCD
JonhasSC b3e8585
modified gitignore to account for DS_STORE files
JonhasSC 1ed6c97
tweaks to qcd script
JonhasSC 2ea511a
added files and section for analysis of resource estimates from perfo…
JonhasSC 8e71e9f
Updated pylint badge
github-actions[bot] b803799
merged with dev
JonhasSC b3fcf09
Updated pylint badge
github-actions[bot] a3db774
improve readability and fix typos
zain2864 5f99e18
fixed qcd notebook
JonhasSC 27e9a84
updated qcd notebook to this branch
JonhasSC 1adf401
added params for qcd script
JonhasSC 411bd88
added new figures and allowed trotter order to be variable. For the m…
JonhasSC 26bf368
made simpler process for constructing edges for neutrinos
JonhasSC b05ea3a
modified QCD script to pass in arguments positionally and added in be…
JonhasSC 5f7186c
removed useless expr for qcd script
JonhasSC File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]: | ||
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( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.