Skip to content

Merge Ieee2024 tutorials #905

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

Draft
wants to merge 10 commits into
base: oldmain
Choose a base branch
from
Draft
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
1,357 changes: 1,357 additions & 0 deletions IEEE2024/The_Sub-Kernel_Method/Sub-Kernel_IEEE_QW_tutorial.ipynb

Large diffs are not rendered by default.

1,911 changes: 1,911 additions & 0 deletions IEEE2024/The_Sub-Kernel_Method/Sub-Kernel_IEEE_QW_tutorial_Master.ipynb

Large diffs are not rendered by default.

23,729 changes: 23,729 additions & 0 deletions IEEE2024/The_Sub-Kernel_Method/Subkernel_results.json

Large diffs are not rendered by default.

128 changes: 128 additions & 0 deletions IEEE2024/The_Sub-Kernel_Method/data/dataset_graph7.csv

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
127 changes: 127 additions & 0 deletions IEEE2024/The_Sub-Kernel_Method/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
anyio==4.4.0
appnope==0.1.4
argon2-cffi==23.1.0
argon2-cffi-bindings==21.2.0
arrow==1.3.0
asttokens==2.4.1
async-lru==2.0.4
attrs==24.2.0
babel==2.16.0
beautifulsoup4==4.12.3
bleach==6.1.0
certifi==2024.7.4
cffi==1.17.0
charset-normalizer==3.3.2
comm==0.2.2
contourpy==1.2.1
cycler==0.12.1
debugpy==1.8.5
decorator==5.1.1
defusedxml==0.7.1
dill==0.3.8
executing==2.0.1
fastdtw==0.3.4
fastjsonschema==2.20.0
fonttools==4.53.1
fqdn==1.5.1
h11==0.14.0
httpcore==1.0.5
httpx==0.27.0
idna==3.7
ipykernel==6.29.5
ipython==8.26.0
ipywidgets==8.1.3
isoduration==20.11.0
jedi==0.19.1
Jinja2==3.1.4
joblib==1.4.2
json5==0.9.25
jsonpointer==3.0.0
jsonschema==4.23.0
jsonschema-specifications==2023.12.1
jupyter==1.0.0
jupyter-console==6.6.3
jupyter-events==0.10.0
jupyter-lsp==2.2.5
jupyter_client==8.6.2
jupyter_core==5.7.2
jupyter_server==2.14.2
jupyter_server_terminals==0.5.3
jupyterlab==4.2.4
jupyterlab_pygments==0.3.0
jupyterlab_server==2.27.3
jupyterlab_widgets==3.0.11
kiwisolver==1.4.5
MarkupSafe==2.1.5
matplotlib==3.9.2
matplotlib-inline==0.1.7
mistune==3.0.2
mpmath==1.3.0
nbclient==0.10.0
nbconvert==7.16.4
nbformat==5.10.4
nest-asyncio==1.6.0
notebook==7.2.1
notebook_shim==0.2.4
numpy==2.0.1
overrides==7.7.0
packaging==24.1
pandas==2.2.2
pandocfilters==1.5.1
parso==0.8.4
pbr==6.0.0
pexpect==4.9.0
pillow==10.4.0
platformdirs==4.2.2
prometheus_client==0.20.0
prompt_toolkit==3.0.47
psutil==6.0.0
ptyprocess==0.7.0
pure_eval==0.2.3
pycparser==2.22
Pygments==2.18.0
pyparsing==3.1.2
python-dateutil==2.9.0.post0
python-json-logger==2.0.7
pytz==2024.1
PyYAML==6.0.2
pyzmq==26.1.0
qiskit==1.1.2
qiskit-algorithms==0.3.0
qiskit-machine-learning==0.7.2
qtconsole==5.5.2
QtPy==2.4.1
referencing==0.35.1
requests==2.32.3
rfc3339-validator==0.1.4
rfc3986-validator==0.1.1
rpds-py==0.20.0
rustworkx==0.15.1
scikit-learn==1.5.1
scipy==1.14.0
Send2Trash==1.8.3
setuptools==72.1.0
six==1.16.0
sniffio==1.3.1
soupsieve==2.5
stack-data==0.6.3
stevedore==5.2.0
symengine==0.11.0
sympy==1.13.2
terminado==0.18.1
threadpoolctl==3.5.0
tinycss2==1.3.0
tdqm==4.66.5
tornado==6.4.1
traitlets==5.14.3
types-python-dateutil==2.9.0.20240316
typing_extensions==4.12.2
tzdata==2024.1
uri-template==1.3.0
urllib3==2.2.2
wcwidth==0.2.13
webcolors==24.8.0
webencodings==0.5.1
websocket-client==1.8.0
wheel==0.43.0
widgetsnbextension==4.0.11
Binary file not shown.
145 changes: 145 additions & 0 deletions IEEE2024/qml-qcnn-hep-tutorial/lattice_schwinger_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
# This code is part of a Qiskit project.
#
# (C) Copyright IBM 2024.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
#
# Any modifications or derivative works of this code must retain this
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.

"""Lattice Schwinger model class."""

from qiskit.quantum_info import Pauli, SparsePauliOp


class LatticeSchwingerModel:
"""Lattice Schwinger model."""

def __init__(
self,
mass: float,
coupling: float,
num_sites: int,
spacing: float,
left_gauge: float = 0,
) -> None:
"""
Args:
mass: Particle mass.
coupling: Coupling constant (e.g., -e for QED).
num_sites: Number of lattice sites.
spacing: Lattice constant.
left_gauge: Left gauge.
"""
assert (
num_sites % 2 == 0
), f"Number of sites is {num_sites} but should be even for staggered fermions!"

self._mass = mass
self._couple = coupling
self._num_sites = num_sites
self._spacing = spacing
self._left_gauge = left_gauge

def _build_hopping_ops(self) -> tuple[list[SparsePauliOp], list[SparsePauliOp]]:
"""Constructs all hopping terms of the Hamiltonian after qubit-mapping.

These are (sigma^+
sigma^_ + h.c.) terms which simplify to (YY + XX) terms and are split into mutually
non-commuting even and odd sums of Paulis within which all terms commute.
"""
coeff = 1.0 / (4 * self._spacing)
ops: tuple[list[SparsePauliOp], list[SparsePauliOp]] = ([], [])
for parity in [0, 1]:
for j in range(parity, self._num_sites - 1, 2):
for pauli in ["X", "Y"]:
ops[parity].append(
SparsePauliOp(
[f"{'I' * (self._num_sites - 1 - j - 1)}{pauli}{pauli}{'I' * j}"],
[coeff],
)
)

return ops

def _build_z_ops(self) -> list[SparsePauliOp]:
"""
Constructs all Pauli operators constituting the mass term as well as the gauge-field term of
the Hamiltonian with staggered fermions. These operators consist of only I and Z.
"""
op_z = []

coeff_mass = 0.5 * self._mass
coeff_couple = 0.5 * self._couple * self._couple * self._spacing
n_mod2 = self._num_sites % 2
coeff_const = -coeff_mass * n_mod2 + coeff_couple * (
(self._num_sites - 1) * self._left_gauge * self._left_gauge
+ (0.125 - 0.5 * self._left_gauge) * (self._num_sites - n_mod2)
)

for j in range(self._num_sites - 1):
op_z_j = []

# Mass terms
op_z_j.append(
SparsePauliOp(
[f"{'I' * (self._num_sites - 1 - j)}{'Z'}{'I' * j}"],
[coeff_mass * (1 if j % 2 == 0 else -1)],
)
)

coeff_j = self._left_gauge + 0.5 * ((j + 1) % 2)

# Gauge terms from Gauss' law.
for l in range(j + 1): # need +1 as otherwise sum stops at N-3 instead of N-2.
op_z_j.append(
SparsePauliOp(
[f"{'I' * (self._num_sites - 1 - l)}{'Z'}{'I' * l}"],
[coeff_j * coeff_couple],
)
)
pauli1 = Pauli(f"{'I' * (self._num_sites - 1 - l)}{'Z'}{'I' * l}")

for ll in range(j + 1):
if l == ll:
coeff_const += 0.25 * coeff_couple
else:
pauli2 = Pauli(f"{'I' * (self._num_sites - 1 - ll)}{'Z'}{'I' * ll}")
op_z_j.append(SparsePauliOp([pauli1.dot(pauli2)], [0.25 * coeff_couple]))

op_z.append(op_z_j)

# j = N mass term
op_z.append(
SparsePauliOp(
[f"{'Z'}{'I' * (self._num_sites - 1)}"],
[coeff_mass * (1 if (self._num_sites - 1) % 2 == 0 else -1)],
)
)

# Constant term is left last, so it can be easily discarded.
# op_z.append(SparsePauliOp([self._num_sites*'I'], [coeff_const])

return op_z

def get_hamiltonian(self) -> list[SparsePauliOp]:
"""Returns the Hamiltonian as a list of sparse Pauli operators.

The operators are grouped such that within each sum, all Paulis commute but the elements of
the list (i.e., Pauli sums) do not commute mutually.
"""
hamiltonian = []

hopping_ops = self._build_hopping_ops()
coupling_ops = self._build_z_ops()

for op_list in hopping_ops:
hamiltonian.append(sum(op_list))

summed_coupling_op = sum(sum(op_list) for op_list in coupling_ops)
hamiltonian.append(summed_coupling_op)

return hamiltonian

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions IEEE2024/qml-qcnn-hep-tutorial/schwinger_vqe.ipynb

Large diffs are not rendered by default.

Loading