Skip to content

Commit

Permalink
plotter added as well. interpolater started
Browse files Browse the repository at this point in the history
  • Loading branch information
shanto268 committed Dec 21, 2023
1 parent 3d38c4d commit 52dc6d5
Show file tree
Hide file tree
Showing 7 changed files with 148 additions and 19 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
author_email='shanto@usc.edu',
include_package_data=True,
url='https://github.com/LFL-Lab/SQuADDS',
install_requires=required, # required for pypi installations
#install_requires=required, # required for pypi installations
classifiers=[
'Programming Language :: Python :: 3',
'License :: OSI Approved :: MIT License',
Expand Down
57 changes: 51 additions & 6 deletions squadds/core/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from pandasai.llm import OpenAI, Starcoder, Falcon
from dotenv import load_dotenv
from squadds.calcs import *
import seaborn as sns

from squadds.core.metrics import *
from squadds.core.db import SQuADDS_DB
Expand Down Expand Up @@ -60,8 +61,11 @@ def __init__(self, db):
self.selected_coupler = self.db.selected_coupler
self.selected_system = self.db.selected_system
self.df = self.db.selected_df
self.closest_design = None
self.closest_df_entry = None
self.closest_design = None
self.presimmed_closest_cpw_design = None
self.presimmed_closest_qubit_design = None
self.presimmed_closest_coupler_design = None
self.interpolated_design = None

self.metric_strategy = None # Will be set dynamically
Expand Down Expand Up @@ -228,6 +232,9 @@ def find_closest(self,
self.closest_df_entry = closest_df.iloc[0]
self.closest_design = closest_df.iloc[0]["design_options"]

if len(self.selected_system) == 2: #TODO: make this more general
self.presimmed_closest_cpw_design = self.closest_design["cavity_claw"]

return closest_df

def get_interpolated_design(self,
Expand All @@ -251,8 +258,46 @@ def get_param(self, design, param):
"""
raise NotImplementedError

def interpolate_design(self, updated_design1, updated_design2):
"""
Interpolates the design parameters of the resonator and qubit to the design dict.
"""
raise NotImplementedError

def show_chosen_points(self):
# Set Seaborn style and context
sns.set_style("whitegrid")
sns.set_context("paper", font_scale=1.4)

# Create a colormap for the scatter plot points
viridis_cmap = plt.cm.get_cmap('viridis')
color_sim = viridis_cmap(0.2)
color_presim = viridis_cmap(0.9)
color_database = viridis_cmap(0.6)

# Create the figure with two subplots
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(16, 6))

# First subplot: kappa_kHz vs fres
ax1.scatter(x=self.df['cavity_frequency_GHz'], y=self.df['kappa_kHz'], c=color_presim, marker=".", s=50, label="Pre-Simulated")
ax1.scatter(x=self.target_params["cavity_frequency_GHz"], y=self.target_params["kappa_kHz"], c='red', s=100, marker='x', label='Target')
closest_fres = self.closest_df_entry["cavity_frequency_GHz"]
closest_kappa_kHz = self.closest_df_entry["kappa_kHz"]
ax1.scatter(closest_fres, closest_kappa_kHz, c=[color_database], s=100, marker='s', alpha=0.7, label='Closest')
ax1.set_xlabel(r'$f_{res}$ (Hz)', fontweight='bold', fontsize=24)
ax1.set_ylabel(r'$\kappa / 2 \pi$ (Hz)', fontweight='bold', fontsize=24)
ax1.tick_params(axis='both', which='major', labelsize=20)
legend1 = ax1.legend(loc='upper left', fontsize=16)
for text in legend1.get_texts():
text.set_fontweight('bold')

# Second subplot: g vs alpha
ax2.scatter(x=self.df['anharmonicity_MHz'], y=self.df['g_MHz'], c=color_presim, marker=".", s=50, label="Pre-Simulated")
ax2.scatter(x=self.target_params["anharmonicity_MHz"], y=self.target_params["g_MHz"], c='red', s=100, marker='x', label='Target')
closest_alpha = [self.closest_df_entry["anharmonicity_MHz"]]
closest_g = [self.closest_df_entry["g_MHz"]]
ax2.scatter(closest_alpha, closest_g, c=[color_database], s=100, marker='s', alpha=0.7, label='Closest')
ax2.set_xlabel(r'$\alpha / 2 \pi$ (MHz)', fontweight='bold', fontsize=24)
ax2.set_ylabel(r'$g / 2 \pi$ (MHz)', fontweight='bold', fontsize=24)
ax2.tick_params(axis='both', which='major', labelsize=20)
legend2 = ax2.legend(loc='lower left', fontsize=16)
for text in legend2.get_texts():
text.set_fontweight('bold')

plt.tight_layout()
plt.show()
4 changes: 0 additions & 4 deletions squadds/database/reader.py

This file was deleted.

1 change: 1 addition & 0 deletions squadds/interpolations/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .interpolator import Interpolator
18 changes: 18 additions & 0 deletions squadds/interpolations/interpolator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from abc import ABC, abstractmethod
import pandas as pd

class Interpolator(ABC):
"""Abstract class for interpolators."""

def __init__(self, df: pd.DataFrame, target_params: dict):
self.df = df
self.target_params = target_params

@abstractmethod
def get_design(self) -> pd.DataFrame:
"""Interpolate based on the target parameters.
Returns:
pd.DataFrame: DataFrame with interpolated design options.
"""
pass
74 changes: 74 additions & 0 deletions squadds/interpolations/physics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
from squadds.interpolations import Interpolator
import pandas as pd

class ScalingInterpolator(Interpolator):
"""Concrete class for scaling based interpolation."""

def __init__(self, df: pd.DataFrame, target_params: dict):
super().__init__(df, target_params)

def get_design(self) -> pd.DataFrame:
"""Performs interpolation based on scaling logic.
Returns:
pd.DataFrame: DataFrame with interpolated design options.
"""
# Initialize lists to store the updated values
updated_design_options = []
required_LJs = []
presimmed_best_qubit_designs = []
presimmed_best_cpw_designs = []

# Extract target parameters
f_q_target = self.target_params['qubit_frequency_GHz']
g_target = self.target_params['g_MHz']
alpha_target = self.target_params['anharmonicity_MHz']
f_res_target = self.target_params['cavity_frequency_GHz']
kappa_target = self.target_params['kappa_kHz']
res_type = self.target_params['resonator_type']

# Placeholder for the calculate_target_quantities function
# C_q_target, C_C_target, E_J, E_C_target, EJ_over_EC = calculate_target_quantities(...)

# Placeholder for LJ_target calculation
LJ_target = 10 # This should be computed based on E_J
required_LJs.append(LJ_target)

# Placeholder for updating the DataFrame with anharmonicity, g, and qubit frequency
# self.df["g"], self.df["anharmonicity"], self.df["qubit_frequency"] = compute_g_alpha_freq(...)

# Placeholder logic for finding the best qubit-claw and cpw-claw design
# Implement actual logic here
idx1, closest_qubit_claw_design = 0, self.df.iloc[0] # Placeholder
idx2, closest_claw_cpw_design = 0, self.df.iloc[0] # Placeholder

# Calculate scaling factors
alpha_scaling = closest_qubit_claw_design['anharmonicity'] / alpha_target
g_scaling = g_target / closest_qubit_claw_design['g']

# Update the lengths based on the closest design and scaling
updated_cross_length = closest_qubit_claw_design['cross_length'] * alpha_scaling
updated_claw_length = closest_qubit_claw_design['claw_length'] * g_scaling * alpha_scaling
updated_resonator_length = closest_claw_cpw_design['total_length'] * (closest_claw_cpw_design['cavity_frequency'] / f_res_target)
updated_coupling_length = closest_claw_cpw_design['coupling_length'] * (kappa_target / closest_claw_cpw_design['kappa']) ** 0.5

# Append the updated lengths to the lists
updated_design_options.append({
'cross_length': updated_cross_length,
'claw_length': updated_claw_length,
'resonator_length': updated_resonator_length,
'coupling_length': updated_coupling_length
})
presimmed_best_qubit_designs.append(closest_qubit_claw_design)
presimmed_best_cpw_designs.append(closest_claw_cpw_design)

# Return DataFrame with updated values
return pd.DataFrame({
'updated_design_options': updated_design_options,
'required_LJs': required_LJs,
'presimmed_best_qubit_designs': presimmed_best_qubit_designs,
'presimmed_best_cpw_designs': presimmed_best_cpw_designs
})



11 changes: 3 additions & 8 deletions tutorials/Tutorial-1_Getting_Started_with_SQuADDS.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2772,14 +2772,9 @@
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
"source": [
"from squadds.interpolations.physics import ScalingInterpolator"
]
},
{
"cell_type": "markdown",
Expand Down

0 comments on commit 52dc6d5

Please sign in to comment.