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

New notebook + pyLIQTR update + QOL changes #58

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
![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

This projct focuses on the documentation of applications for Quantum Computers. Currently, we have four notebooks exploring four different applications, which can be found in
the notebooks/ directory. For taking a look at notebooks that are going through ongoing development, one can take a look at the `notebook/exotic-phases-nb` and `notebook/dicke-model-nb`
branches.
This projct focuses on the documentation of applications for Quantum Computers.

# Citation

Expand Down
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/GateSingleTrotter.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/TCountSingleTrotter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
465 changes: 465 additions & 0 deletions notebooks/QuantumChromoDynamicsExample.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "qca"
version = "0.1.0"
version = "0.2.0"
dynamic = ["dependencies"]
requires-python = ">=3.9, <=3.12"
description = "Documentation of Applications for Quantum Computers"
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pyLIQTR == 1.2.1
pyLIQTR == 1.3.0
matplotlib
networkx
numpy
Expand Down
121 changes: 121 additions & 0 deletions scripts/QCD-RE.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
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')
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}'
estimate_trotter(
qb_op_hamiltonian,
evolution_time,
1e-3,
'QCD/',
hamiltonian_name=fname,
nsteps=num_steps
)

if __name__ == '__main__':
main()
Loading