-
Notifications
You must be signed in to change notification settings - Fork 208
[DEMO] QML for Phase Detection #1335
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
Conversation
|
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.colors import ListedColormap, BoundaryNorm
# Kosterlitz-Thouless transition line
def kt_transition(k):
return 1.05 * np.sqrt((k - 0.5) * (k - 0.1))
# Ising transition line
def ising_transition(k):
return np.where(k == 0, 1, (1 - k) * (1 - np.sqrt((1 - 3 * k + 4 * k**2) / (1 - k))) / np.maximum(k, 1e-9))
# Floating Phase transition line
def bkt_transition(k):
return 1.05 * (k - 0.5)
# Get the phase from the DMRG transition lines
def get_phase(k, h):
if k < .5 and h < ising_transition(k):
return 0
elif k > .5 and h < kt_transition(k):
return 1
return 2
# Generate the phase diagram data from DMRG transition lines
ks100, hs100 = np.linspace(0, 1, 100), np.linspace(0, 2, 100)
K100, H100 = np.meshgrid(ks100, hs100)
img_dmrg = np.vectorize(get_phase)(K100, H100)
colors = ['#80bfff', '#fff2a8', '#80f090', '#da8080',]
phase_labels = ["Ferromagnetic", "Antiphase", "Paramagnetic", "Trash Class",]
cmap = ListedColormap(colors)
bounds = [-0.5, 0.5, 1.5, 2.5, 3.5]
norm = BoundaryNorm(bounds, cmap.N)
# Plot the phase diagram
plt.figure(figsize=(4, 4))
plt.imshow(img_dmrg, cmap=cmap, aspect="auto", origin="lower", extent=[0, 1, 0, 2], norm=norm)
# Plot the transition lines.
k_vals1 = np.linspace(0.0, 0.5, 50)
k_vals2 = np.linspace(0.5, 1.0, 50)
plt.plot(k_vals1, ising_transition(k_vals1), 'k', lw=2)
plt.plot(k_vals2, kt_transition(k_vals2), 'k', lw=2)
plt.plot(k_vals2, bkt_transition(k_vals2), 'k', ls = '--', lw=2)
# Create legend entries
for color, phase in zip(colors, phase_labels[:-1]):
plt.scatter([], [], color=color, label=phase, edgecolors='black')
plt.plot([], [], 'k', label='Transition Lines')
plt.text(0.15, 0.5, s=r'$h_I$', fontsize=12)
plt.text(0.70, 0.5, s=r'$h_C$', fontsize=12)
plt.text(0.8, 0.2, s=r'$h_{BKT}$', fontsize=12)
plt.legend(), plt.xlabel("k"), plt.ylabel("h"), plt.title("Phase diagram"), plt.show();
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.colors import ListedColormap, BoundaryNorm
# Kosterlitz-Thouless transition line
def kt_transition(k):
return 1.05 * np.sqrt((k - 0.5) * (k - 0.1))
# Ising transition line
def ising_transition(k):
return np.where(k == 0, 1, (1 - k) * (1 - np.sqrt((1 - 3 * k + 4 * k**2) / (1 - k))) / np.maximum(k, 1e-9))
# Floating Phase transition line
def bkt_transition(k):
return 1.05 * (k - 0.5)
# Get the phase from the DMRG transition lines
def get_phase(k, h):
if k < .5 and h < ising_transition(k):
return 0
elif k > .5 and h < kt_transition(k):
return 1
return 2
# Generate the phase diagram data from DMRG transition lines
ks100, hs100 = np.linspace(0, 1, 100), np.linspace(0, 2, 100)
K100, H100 = np.meshgrid(ks100, hs100)
img_dmrg = np.vectorize(get_phase)(K100, H100)
colors = ['#80bfff', '#fff2a8', '#80f090', '#da8080',]
phase_labels = ["Ferromagnetic", "Antiphase", "Paramagnetic", "Trash Class",]
cmap = ListedColormap(colors)
bounds = [-0.5, 0.5, 1.5, 2.5, 3.5]
norm = BoundaryNorm(bounds, cmap.N)
# Plot the phase diagram
plt.figure(figsize=(4, 4))
plt.imshow(img_dmrg, cmap=cmap, aspect="auto", origin="lower", extent=[0, 1, 0, 2], norm=norm)
# Plot the transition lines.
k_vals1 = np.linspace(0.0, 0.5, 50)
k_vals2 = np.linspace(0.5, 1.0, 50)
plt.plot(k_vals1, ising_transition(k_vals1), 'k', lw=2)
plt.plot(k_vals2, kt_transition(k_vals2), 'k', lw=2)
plt.plot(k_vals2, bkt_transition(k_vals2), 'k', ls = '--', lw=2)
# Create legend entries
for color, phase in zip(colors, phase_labels[:-1]):
plt.scatter([], [], color=color, label=phase, edgecolors='black')
plt.plot([], [], 'k', label='Transition Lines')
# Highlight analytical points (k = 0 and h = 0)
plt.scatter(np.zeros_like(hs100), hs100, color='red', s=20, label="Analytical Points") # y-axis points
plt.scatter(ks100, np.zeros_like(ks100), color='red', s=20) # x-axis point
plt.text(0.15, 0.5, s=r'$h_I$', fontsize=12)
plt.text(0.70, 0.5, s=r'$h_C$', fontsize=12)
plt.text(0.8, 0.2, s=r'$h_{BKT}$', fontsize=12)
plt.legend(), plt.xlabel("k"), plt.ylabel("h"), plt.title("Phase diagram"), plt.show(); |
Thank you for opening this pull request. You can find the built site at this link. Deployment Info:
Note: It may take several minutes for updates to this pull request to be reflected on the deployed site. |
…progress updates in the State Preparation section, assigned the circuit drawings to specific figures, updated the progress updates for the loss curves
, removed the progress bars and tqdm
Small changes in format like colons, comas, periods, and capital letters. Added two missing words.
Incorporating changes from Saverio's notebook to py file. The changes come from three different commits.
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.
Final touches:
- Acknowledgement to DESY
- Training of the QCNN with the full training set instead of sampling each epoch for a smoother loss curve
- Adapted hyperparameters of the training function of the QCNN
Co-authored-by: Saverio Monaco <[email protected]>
Co-authored-by: Saverio Monaco <[email protected]>
Co-authored-by: Saverio Monaco <[email protected]>
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.
Fix of a comment in the QAD training function
Co-authored-by: Saverio Monaco <[email protected]>
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.
Amazing job @SaverioMonaco !!!
I'm excited to see this demo go live.
Title:
Supervised and Unsupervised Quantum Machine Learning models for the phase detection of the ANNNI spin model
Summary:
Showcase of two foundational models in QML for Phase Detection for Spin Systems. One follows a supervised approach, the other follows an unsupervised approach.
Relevant references:
Possible Drawbacks:
QCNN models is considered now outdated.
Related GitHub Issues:
If you are writing a demonstration, please answer these questions to facilitate the marketing process.
GOALS — Why are we working on this now?
Eg. Promote a new PL feature or show a PL implementation of a recent paper.
Show a working example of the founding models in QML for Phase Detection. Show how MPS and QML can be used together.
AUDIENCE — Who is this for?
Eg. Chemistry researchers, PL educators, beginners in quantum computing.
Beginners in Quantum Computing, Chemistry researchers
KEYWORDS — What words should be included in the marketing post?
ANNNI, QCNN, QAD, Phase Detection
Which of the following types of documentation is most similar to your file?
(more details here)
[sc-80710]