SQuADDS 0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- SQuADDS-0.0.dist-info/LICENSE +21 -0
- SQuADDS-0.0.dist-info/METADATA +112 -0
- SQuADDS-0.0.dist-info/RECORD +20 -0
- SQuADDS-0.0.dist-info/WHEEL +5 -0
- SQuADDS-0.0.dist-info/top_level.txt +1 -0
- squadds/__init__.py +12 -0
- squadds/core/__init__.py +3 -0
- squadds/core/analysis.py +491 -0
- squadds/core/db.py +419 -0
- squadds/core/design_patterns.py +8 -0
- squadds/core/globals.py +3 -0
- squadds/core/metrics.py +148 -0
- squadds/core/selector.py +4 -0
- squadds/core/utils.py +79 -0
- squadds/database/__init__.py +3 -0
- squadds/database/checker.py +10 -0
- squadds/database/config.py +14 -0
- squadds/database/contributor.py +174 -0
- squadds/database/reader.py +4 -0
- squadds/database/utils.py +125 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Sadman Ahmed Shanto
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: SQuADDS
|
|
3
|
+
Version: 0.0
|
|
4
|
+
Summary: Our project introduces an open-source database of programmatically generated and experimentally validated superconducting quantum device designs, accessible through a user-friendly interface, significantly lowering the entry barrier for research in this field.
|
|
5
|
+
Home-page: https://github.com/LFL-Lab/SQuADDS
|
|
6
|
+
Author: Sadman Ahmed Shanto
|
|
7
|
+
Author-email: shanto@usc.edu
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Requires-Dist: datasets (==2.15.0)
|
|
14
|
+
Requires-Dist: huggingface-hub (==0.19.4)
|
|
15
|
+
Requires-Dist: numpy (==1.26.2)
|
|
16
|
+
Requires-Dist: pandas (==1.5.3)
|
|
17
|
+
Requires-Dist: pandasai (==1.5.11)
|
|
18
|
+
Requires-Dist: pymongo (==4.5.0)
|
|
19
|
+
Requires-Dist: python-dotenv (==1.0.0)
|
|
20
|
+
Requires-Dist: scqubits (==3.3.0)
|
|
21
|
+
Requires-Dist: setuptools (==65.5.1)
|
|
22
|
+
Requires-Dist: tabulate (==0.9.0)
|
|
23
|
+
|
|
24
|
+
#  SQuADDS:
|
|
25
|
+
|
|
26
|
+
> :warning: **This project is currently under active development. Features and documentation may be incomplete.**
|
|
27
|
+
|
|
28
|
+
The SQuADDS (Superconducting Qubit And Device Design and Simulation) Database Project is an open-source resource aimed at advancing research in superconducting quantum device designs. It provides a robust workflow for generating and simulating superconducting quantum device designs, facilitating the accurate prediction of Hamiltonian parameters across a wide range of design geometries.
|
|
29
|
+
|
|
30
|
+
Paper Link: [SQuADDS: A Database for Superconducting Quantum Device Design and Simulation](https://)
|
|
31
|
+
Website Link: [SQuADDS](https://sadmanahmedshanto.com/SQuADDS/)
|
|
32
|
+
|
|
33
|
+
## Table of Contents
|
|
34
|
+
|
|
35
|
+
- [Setup](#setup)
|
|
36
|
+
- [Features](#features)
|
|
37
|
+
- [Usage](#usage)
|
|
38
|
+
- [Contributing](#contributing)
|
|
39
|
+
- [License](#license)
|
|
40
|
+
- [Contact](#contact)
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## Setup
|
|
45
|
+
|
|
46
|
+
Install using pip:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
pip install SQuADDS
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Install from source:
|
|
53
|
+
|
|
54
|
+
### Prerequisites
|
|
55
|
+
- [Python 3.7+](https://www.python.org/downloads/)
|
|
56
|
+
- [pip](https://pip.pypa.io/en/stable/installing/)
|
|
57
|
+
- [Git](https://git-scm.com/downloads)
|
|
58
|
+
|
|
59
|
+
### Installation
|
|
60
|
+
|
|
61
|
+
1. Clone the repository.
|
|
62
|
+
```bash
|
|
63
|
+
git clone
|
|
64
|
+
```
|
|
65
|
+
2. Install the required packages.
|
|
66
|
+
```bash
|
|
67
|
+
pip install -r requirements.txt
|
|
68
|
+
```
|
|
69
|
+
3. Run the setup script.
|
|
70
|
+
```bash
|
|
71
|
+
python setup.py install
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Features
|
|
75
|
+
|
|
76
|
+
- **Data-Driven Interpolation**: Utilizes a comprehensive database for interpolating Hamiltonian parameters, ensuring high precision in predictions.
|
|
77
|
+
- **User-Specified Target Parameters**: Allows users to define target parameters such as qubit anharmonicity, coupling strength, resonator linewidth, and frequency.
|
|
78
|
+
- **Experimental Validation**: Includes experimentally measured data for enhancing the reliability and accuracy of the simulations.
|
|
79
|
+
- **Open-Source Collaboration**: Encourages contributions from the community, expanding the database and refining the simulation models.
|
|
80
|
+
|
|
81
|
+
## Tutorials
|
|
82
|
+
- [Tutorial 1: Getting Started with SQuADDS](https://sadmanahmedshanto.com/SQuADDS/tutorials/Tutorial-1_getting_started_with_SQuADDS.html)
|
|
83
|
+
- [Tutorial 2: Contributing to the SQuADDS Database](https://sadmanahmedshanto.com/SQuADDS/tutorials/Tutorial-2_Contributing_to_SQuADDS.html)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
## Contributing
|
|
87
|
+
|
|
88
|
+
Contributions are welcome! If you have improvements or additions to the database, please follow these steps:
|
|
89
|
+
|
|
90
|
+
- Fork the repository.
|
|
91
|
+
- Create a new branch for your feature.
|
|
92
|
+
- Add your contributions.
|
|
93
|
+
- Submit a pull request with a clear description of your changes.
|
|
94
|
+
|
|
95
|
+
## License
|
|
96
|
+
|
|
97
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
## Contact
|
|
101
|
+
For inquiries or support, please contact [Sadman Ahmed Shanto](mailto:shanto@usc.edu).
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
## Next Release:
|
|
106
|
+
|
|
107
|
+
- [ ] More tutorials/examples/explanations on the website
|
|
108
|
+
- [ ] Contribution via HuggingFace Hub API
|
|
109
|
+
- [ ] More data points to existing configurations
|
|
110
|
+
- [ ] Contribute data points to new configurations
|
|
111
|
+
|
|
112
|
+
---
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
squadds/__init__.py,sha256=-8PEtPIMUeLnvisR8Lanw65YBJtX0ts67tIcq-EZGBE,361
|
|
2
|
+
squadds/core/__init__.py,sha256=Tsu6hW4x8pDMLcIAxNV2HeI94PZOvX9X0dkLIKAkmRc,75
|
|
3
|
+
squadds/core/analysis.py,sha256=sUdH99tBW-3qzjFzMexEhqEiK4kHM1AT608imSgWtH8,23156
|
|
4
|
+
squadds/core/db.py,sha256=tYx6Aqm3tamqlw_5eybiw0nMqUc6shr4AOLyiC3ig_c,18174
|
|
5
|
+
squadds/core/design_patterns.py,sha256=RbXmSKFelVvjpAaB-bQ9OiLeuxArd1va-m7Ea2jCGz0,261
|
|
6
|
+
squadds/core/globals.py,sha256=uLO5nN0SghF8FPkrE1qBrk1OUC1h2Ub_YyzRhADmDMg,93
|
|
7
|
+
squadds/core/metrics.py,sha256=gMZBacCjxGjPZYpTRS03UEqcGB37WLCvs1vjNO0L5os,5845
|
|
8
|
+
squadds/core/selector.py,sha256=bEfceLXK-1jrqThq0drb6p-SDKP8LQd7hmP3hFQMDp8,57
|
|
9
|
+
squadds/core/utils.py,sha256=0pOBImy0G6C0V_msvCVb_byO0FX3pCQ48bxi557zI2g,2958
|
|
10
|
+
squadds/database/__init__.py,sha256=8B8DFLQlrWWlzKgVuIJnb4PNuI8iknIa8tTkVwH8pAk,83
|
|
11
|
+
squadds/database/checker.py,sha256=_XfMqvAPkgigAOTuuRMtf4X6xZkc4fB2VpXoQ-8LhWc,263
|
|
12
|
+
squadds/database/config.py,sha256=I1CDxAhxUY7GU7t0HoDnYzf5nFO0Iaso4Gb12pxwgT0,510
|
|
13
|
+
squadds/database/contributor.py,sha256=_qPLSXOtjppcjh21b3ErIHFhjjpWaJ7Q7NPne1bW9t4,6581
|
|
14
|
+
squadds/database/reader.py,sha256=1K_Q3qIXRGnvDHvF02x2j3Xb8SmjOM8Rg2BGu2z7xwg,63
|
|
15
|
+
squadds/database/utils.py,sha256=FuoVNCVNi0MlzKo2xEPQMqDWD5kF16hbGcVIMZLKlaU,4422
|
|
16
|
+
SQuADDS-0.0.dist-info/LICENSE,sha256=4XQ9B0E5IAf30PI8Q4w7rN9kaipeFlu2PcW0BiuRUGQ,1075
|
|
17
|
+
SQuADDS-0.0.dist-info/METADATA,sha256=KJzGFcdminipviIweVRLmwMu7wrqyluoPPopJArBxAM,3983
|
|
18
|
+
SQuADDS-0.0.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
|
|
19
|
+
SQuADDS-0.0.dist-info/top_level.txt,sha256=S5F4RGQLW9hX4oOe0RpyOaJ8AXtT81bFGXw5727G6WE,8
|
|
20
|
+
SQuADDS-0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
squadds
|
squadds/__init__.py
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
__version__ = '0.1.0'
|
|
4
|
+
__license__ = "MIT License"
|
|
5
|
+
__copyright__ = 'Sadman Ahmed Shanto, Eli Levenson-Falk 2023'
|
|
6
|
+
__author__ = 'Sadman Ahmed Shanto, Eli Levenson-Falk'
|
|
7
|
+
__status__ = "Development"
|
|
8
|
+
__repo_path__ = os.path.dirname(os.path.abspath(__file__))
|
|
9
|
+
__library_path__ = os.path.join(__repo_path__, "library")
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
from squadds.core.db import SQuADDS_DB
|
squadds/core/__init__.py
ADDED
squadds/core/analysis.py
ADDED
|
@@ -0,0 +1,491 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
import pandas as pd
|
|
3
|
+
import warnings
|
|
4
|
+
import os
|
|
5
|
+
import scqubits as scq
|
|
6
|
+
from scqubits.core.transmon import TunableTransmon
|
|
7
|
+
from pymongo import MongoClient
|
|
8
|
+
from pandasai import SmartDataframe
|
|
9
|
+
from pandasai.llm import OpenAI, Starcoder, Falcon
|
|
10
|
+
from dotenv import load_dotenv
|
|
11
|
+
|
|
12
|
+
from squadds import logging
|
|
13
|
+
from squadds.core.sweeper_helperfunctions import create_dict_list
|
|
14
|
+
from squadds.utils.metrics import *
|
|
15
|
+
from squadds.core.database import SQuADDS_DB
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
"""
|
|
19
|
+
=====================================================================================
|
|
20
|
+
HELPER FUNCTIONS
|
|
21
|
+
=====================================================================================
|
|
22
|
+
"""
|
|
23
|
+
# Helper function to scale values with 'um' in them
|
|
24
|
+
def scale_value(value, ratio):
|
|
25
|
+
# Remove 'um' from the value, convert to float, scale and convert back to string
|
|
26
|
+
scaled_value = str(float(value.replace('um', '')) * ratio) + 'um'
|
|
27
|
+
return scaled_value
|
|
28
|
+
|
|
29
|
+
"""
|
|
30
|
+
=====================================================================================
|
|
31
|
+
Analyzer
|
|
32
|
+
=====================================================================================
|
|
33
|
+
"""
|
|
34
|
+
class Analyzer:
|
|
35
|
+
|
|
36
|
+
__supported_metrics__ = ['Euclidean', 'Manhattan', 'Chebyshev', 'Weighted Euclidean' , 'Custom']
|
|
37
|
+
__supported_estimation_methods__ = ['Interpolation']
|
|
38
|
+
|
|
39
|
+
def __init__(self, db):
|
|
40
|
+
"""
|
|
41
|
+
Args:
|
|
42
|
+
db (SQuADDS_DB): The database to analyze.
|
|
43
|
+
|
|
44
|
+
Attributes:
|
|
45
|
+
db (SQuADDS_DB): The database to analyze.
|
|
46
|
+
component_name (str): The name of the component to analyze.
|
|
47
|
+
component_type (str): The type of the component to analyze.
|
|
48
|
+
df (pd.DataFrame): The dataframe of the component to analyze.
|
|
49
|
+
metric_strategy (MetricStrategy): The strategy to use for calculating the distance metric.
|
|
50
|
+
custom_metric_func (function): The custom function to use for calculating the distance metric.
|
|
51
|
+
metric_weights (dict): The weights to use for calculating the weighted distance metric.
|
|
52
|
+
smart_df (SmartDataframe): The SmartDataframe of the component to analyze.
|
|
53
|
+
H_param_keys (list): The keys of the Hamiltonian parameters.
|
|
54
|
+
|
|
55
|
+
Raises:
|
|
56
|
+
ValueError: If the specified metric is not supported.
|
|
57
|
+
"""
|
|
58
|
+
|
|
59
|
+
self.db = db
|
|
60
|
+
|
|
61
|
+
self.selected_component_name = self.db.selected_component_name
|
|
62
|
+
self.selected_component = self.db.selected_component
|
|
63
|
+
self.selected_data_type = self.db.selected_data_type
|
|
64
|
+
self.selected_confg = self.db.selected_confg
|
|
65
|
+
self.selected_qubit = self.db.selected_qubit
|
|
66
|
+
self.selected_cavity = self.db.selected_cavity
|
|
67
|
+
self.selected_coupler = self.db.selected_coupler
|
|
68
|
+
self.selected_system = self.db.selected_system
|
|
69
|
+
self.selected_df = self.db.selected_df
|
|
70
|
+
|
|
71
|
+
self.metric_strategy = None # Will be set dynamically
|
|
72
|
+
self.custom_metric_func = None
|
|
73
|
+
self.metric_weights = None
|
|
74
|
+
self.smart_df = None
|
|
75
|
+
self.coupling_type = None
|
|
76
|
+
|
|
77
|
+
def set_metric_strategy(self, strategy: MetricStrategy):
|
|
78
|
+
"""
|
|
79
|
+
Sets the metric strategy to use for calculating the distance metric.
|
|
80
|
+
|
|
81
|
+
Args:
|
|
82
|
+
strategy (MetricStrategy): The strategy to use for calculating the distance metric.
|
|
83
|
+
|
|
84
|
+
Raises:
|
|
85
|
+
ValueError: If the specified metric is not supported.
|
|
86
|
+
"""
|
|
87
|
+
|
|
88
|
+
self.metric_strategy = strategy
|
|
89
|
+
|
|
90
|
+
def _outside_bounds(self, df: pd.DataFrame, params: dict, display=True) -> bool:
|
|
91
|
+
"""
|
|
92
|
+
Check if entered parameters are outside the bounds of a dataframe.
|
|
93
|
+
|
|
94
|
+
Args:
|
|
95
|
+
df (pd.DataFrame): Dataframe to give warning.
|
|
96
|
+
params (dict): Keys are column names of `df`. Values are values to check for bounds.
|
|
97
|
+
|
|
98
|
+
Returns:
|
|
99
|
+
bool: True if any value is outside of bounds. False if all values are inside bounds.
|
|
100
|
+
"""
|
|
101
|
+
outside_bounds = False
|
|
102
|
+
filtered_df = df.copy()
|
|
103
|
+
|
|
104
|
+
for param, value in params.items():
|
|
105
|
+
if param not in df.columns:
|
|
106
|
+
raise ValueError(f"{param} is not a column in dataframe: {df}")
|
|
107
|
+
|
|
108
|
+
if isinstance(value, (int, float)):
|
|
109
|
+
if value < df[param].min() or value > df[param].max():
|
|
110
|
+
if display:
|
|
111
|
+
logging.info(f"\033[1mNOTE TO USER:\033[0m the value \033[1m{value} for {param}\033[0m is outside the bounds of our library.\nIf you find a geometry which corresponds to these values, please consider contributing it! 😁🙏\n")
|
|
112
|
+
outside_bounds = True
|
|
113
|
+
|
|
114
|
+
elif isinstance(value, str):
|
|
115
|
+
filtered_df = filtered_df[filtered_df[param] == value]
|
|
116
|
+
|
|
117
|
+
else:
|
|
118
|
+
raise ValueError(f"Unsupported type {type(value)} for parameter {param}")
|
|
119
|
+
|
|
120
|
+
if filtered_df.empty:
|
|
121
|
+
categorical_params = {key: value for key, value in params.items() if isinstance(value, str)}
|
|
122
|
+
if display and categorical_params:
|
|
123
|
+
logging.info(f"\033[1mNOTE TO USER:\033[0m There are no geometries with the specified categorical parameters - \033[1m{categorical_params}\033[0m.\nIf you find a geometry which corresponds to these values, please consider contributing it! 😁🙏\n")
|
|
124
|
+
outside_bounds = True
|
|
125
|
+
|
|
126
|
+
return outside_bounds
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def find_closest(self,
|
|
130
|
+
target_params: dict,
|
|
131
|
+
num_top: int,
|
|
132
|
+
metric: str = 'Euclidean',
|
|
133
|
+
display: bool = True):
|
|
134
|
+
"""
|
|
135
|
+
Finds the rows in the DataFrame with the closest matching characteristics
|
|
136
|
+
to the given target parameters using a specified metric.
|
|
137
|
+
|
|
138
|
+
Args:
|
|
139
|
+
target_params (dict): A dictionary containing the target values for columns in `self.df`.
|
|
140
|
+
Keys are column names and values are the target values.
|
|
141
|
+
num_top (int): The number of closest matching rows to return.
|
|
142
|
+
metric (str, optional): The distance metric to use for finding the closest matches.
|
|
143
|
+
Available options are specified in `self.__supported_metrics__`.
|
|
144
|
+
Defaults to 'Euclidean'.
|
|
145
|
+
display (bool, optional): Whether to display warnings and logs. Defaults to True.
|
|
146
|
+
|
|
147
|
+
Returns:
|
|
148
|
+
pd.DataFrame: A DataFrame containing the rows with the closest matching characteristics,
|
|
149
|
+
sorted by the distance metric.
|
|
150
|
+
|
|
151
|
+
Raises:
|
|
152
|
+
ValueError: If the specified metric is not supported or `num_top` exceeds the DataFrame size.
|
|
153
|
+
"""
|
|
154
|
+
### Checks
|
|
155
|
+
# Check for supported metric
|
|
156
|
+
if metric not in self.__supported_metrics__:
|
|
157
|
+
raise ValueError(f'`metric` must be one of the following: {self.__supported_metrics__}')
|
|
158
|
+
# Check for improper size of library
|
|
159
|
+
if (num_top > len(self.df)):
|
|
160
|
+
raise ValueError('`num_top` cannot be bigger than size of read-in library.')
|
|
161
|
+
|
|
162
|
+
# Log if parameters outside of library
|
|
163
|
+
filtered_df = self.df[self.H_param_keys] # Filter DataFrame based on H_param_keys
|
|
164
|
+
self._outside_bounds(df=filtered_df, params=target_params, display=display)
|
|
165
|
+
|
|
166
|
+
# Set strategy dynamically based on the metric parameter
|
|
167
|
+
if metric == 'Euclidean':
|
|
168
|
+
self.set_metric_strategy(EuclideanMetric())
|
|
169
|
+
elif metric == 'Manhattan':
|
|
170
|
+
self.set_metric_strategy(ManhattanMetric())
|
|
171
|
+
elif metric == 'Chebyshev':
|
|
172
|
+
self.set_metric_strategy(ChebyshevMetric())
|
|
173
|
+
elif metric == 'Weighted Euclidean':
|
|
174
|
+
self.set_metric_strategy(WeightedEuclideanMetric(self.metric_weights))
|
|
175
|
+
elif metric == 'Custom':
|
|
176
|
+
self.set_metric_strategy(CustomMetric(self.custom_metric_func))
|
|
177
|
+
|
|
178
|
+
if not self.metric_strategy:
|
|
179
|
+
raise ValueError("Invalid metric.")
|
|
180
|
+
|
|
181
|
+
# Main logic
|
|
182
|
+
distances = filtered_df.apply(lambda row: self.metric_strategy.calculate(target_params, row), axis=1)
|
|
183
|
+
|
|
184
|
+
# Sort distances and get the closest ones
|
|
185
|
+
sorted_indices = distances.nsmallest(num_top).index
|
|
186
|
+
closest_df = self.df.loc[sorted_indices]
|
|
187
|
+
|
|
188
|
+
return closest_df
|
|
189
|
+
|
|
190
|
+
def chat(self, question, llm="OpenAI"):
|
|
191
|
+
"""
|
|
192
|
+
Chat with the library using a language model.
|
|
193
|
+
|
|
194
|
+
Args:
|
|
195
|
+
question (str): The question to ask the library.
|
|
196
|
+
llm (str, optional): The language model to use for answering the question.
|
|
197
|
+
|
|
198
|
+
Returns:
|
|
199
|
+
SmartDataframe: The answer to the question in a dataframe format.
|
|
200
|
+
"""
|
|
201
|
+
|
|
202
|
+
# set up LLM
|
|
203
|
+
load_dotenv()
|
|
204
|
+
if llm == "OpenAI":
|
|
205
|
+
llm = OpenAI()
|
|
206
|
+
elif llm == "Starcoder":
|
|
207
|
+
llm = Starcoder(api_token=os.getenv("HUGGING_FACE_API_KEY"))
|
|
208
|
+
elif llm == "Falcon":
|
|
209
|
+
llm = Falcon(api_token=os.getenv("HUGGING_FACE_API_KEY"))
|
|
210
|
+
|
|
211
|
+
# filter the df
|
|
212
|
+
filtered_df = self.df[self.H_param_keys] # Filter DataFrame based on H_param_keys
|
|
213
|
+
|
|
214
|
+
# chat with the dataframe using pandasai
|
|
215
|
+
self.smart_df = SmartDataframe(filtered_df, config={"llm": llm})
|
|
216
|
+
response = self.smart_df.chat(question)
|
|
217
|
+
|
|
218
|
+
# merge the response with the original dataframe
|
|
219
|
+
pd_response = pd.DataFrame(response, columns=self.H_param_keys)
|
|
220
|
+
df_response = self.df.merge(pd_response, on=list(pd_response.columns), how='inner')
|
|
221
|
+
if len(df_response) == 0:
|
|
222
|
+
contrib_message = f"\nIf you find a geometry which corresponds to these values, please consider contributing it! 😁🙏\n"
|
|
223
|
+
raise ValueError("No matching geometries were found for your query 😢\n" + contrib_message)
|
|
224
|
+
return df_response.head(len(pd_response))
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
def get_interpolated_design(self,
|
|
228
|
+
target_params: dict,
|
|
229
|
+
metric: str = 'Euclidean',
|
|
230
|
+
display: bool = True):
|
|
231
|
+
"""
|
|
232
|
+
Implement the 7-step interpolation procedure to find the best qubit and resonator design.
|
|
233
|
+
|
|
234
|
+
Args:
|
|
235
|
+
target_params (dict): A dictionary containing the target parameters for qubit and resonator.
|
|
236
|
+
The dictionary should contain two keys: 'qubit_params' and 'resonator_params'.
|
|
237
|
+
metric (str, optional): The distance metric to use for finding the closest matches.
|
|
238
|
+
Defaults to 'Euclidean'.
|
|
239
|
+
display (bool, optional): Whether to display warnings and logs. Defaults to True.
|
|
240
|
+
|
|
241
|
+
Returns:
|
|
242
|
+
dict: A dictionary containing the interpolated design for the qubit and resonator.
|
|
243
|
+
|
|
244
|
+
Raises:
|
|
245
|
+
ValueError: If the specified metric is not supported or if `num_top` exceeds the DataFrame size.
|
|
246
|
+
NotImplementedError: If auxiliary methods for calculating parameters are not implemented.
|
|
247
|
+
"""
|
|
248
|
+
### Checks
|
|
249
|
+
# Validate target_params
|
|
250
|
+
if not isinstance(target_params, dict):
|
|
251
|
+
raise ValueError("`target_params` must be a dictionary.")
|
|
252
|
+
if not all(key in target_params for key in self.H_param_keys):
|
|
253
|
+
# remind the characteristics allowed
|
|
254
|
+
characteristics = self.db.get_characteristic_info(self.component_name, self.component_type)
|
|
255
|
+
raise ValueError("The target parameters must be one of the following: \n" + str(characteristics))
|
|
256
|
+
|
|
257
|
+
# Validate metric
|
|
258
|
+
if metric not in self.__supported_metrics__:
|
|
259
|
+
raise ValueError(f'`metric` must be one of the following: {self.__supported_metrics__}')
|
|
260
|
+
|
|
261
|
+
# Set num_top to 1
|
|
262
|
+
num_top = 1
|
|
263
|
+
|
|
264
|
+
### Start the interpolation algorithm
|
|
265
|
+
|
|
266
|
+
# Step 0: Extract the target parameters for qubit and resonator
|
|
267
|
+
f_q, alpha_target, g_target = target_params.get("Qubit_Frequency_GHz"), target_params.get("Qubit_Anharmonicity_MHz"), target_params.get("Coupling_Strength_MHz")
|
|
268
|
+
f_r, kappa, wavelength_type = target_params.get("Cavity_Frequency_GHz"), target_params.get("kappa_MHz"), target_params.get("wavelength")
|
|
269
|
+
self.coupling_type = target_params.get("feedline_coupling")
|
|
270
|
+
|
|
271
|
+
# Step 1: Compute the coupling parameters
|
|
272
|
+
C_q, C_r, C_c, E_J, E_C = self.get_coupling_parameters(f_q, f_r, alpha_target, g_target, wavelength_type)
|
|
273
|
+
|
|
274
|
+
# Step 2: Search database for best matching design for anharmonicity, coulping strength, resonator frequency and qubit frequency
|
|
275
|
+
target_params_1 = {"Qubit_Frequency_GHz": f_q, "Qubit_Anharmonicity_MHz": alpha_target, "Coupling_Strength_MHz": g_target, "Cavity_Frequency_GHz": f_r}
|
|
276
|
+
df_flagged_1 = self.find_closest(target_params_1, num_top, metric, display=False)
|
|
277
|
+
|
|
278
|
+
# Step 3: Scale qubit and coupling capacitor areas
|
|
279
|
+
|
|
280
|
+
# Step 3.1: Extract the best matching design parameters
|
|
281
|
+
alpha_sim, g_sim = df_flagged_1['Qubit_Anharmonicity_MHz'].values[0], df_flagged_1['Coupling_Strength_MHz'].values[0]
|
|
282
|
+
f_q_sim, f_r_sim = df_flagged_1['Qubit_Frequency_GHz'].values[0], df_flagged_1['Cavity_Frequency_GHz'].values[0]
|
|
283
|
+
# C_q_sim, C_r_sim, C_c_sim, E_J_sim, E_C_sim = self.get_coupling_parameters(f_q_sim, f_r_sim, alpha_sim, g_sim, wavelength_type)
|
|
284
|
+
|
|
285
|
+
# Step 3.2: Scale the qubit and coupling capacitor areas
|
|
286
|
+
qubit_ratio, coupling_ratio = alpha_sim/alpha_target, (alpha_sim/alpha_target)*(g_target/g_sim)
|
|
287
|
+
|
|
288
|
+
# Step 3.3: Get the design dict for the best matching design
|
|
289
|
+
design = self.get_design(df_flagged_1)
|
|
290
|
+
|
|
291
|
+
# Step 3.4: Scale the qubit and coupling capacitor areas and update the design dict
|
|
292
|
+
updated_design1 = self.get_updated_design_with_scaled_qubit_and_coupling_capacitor_areas(design, qubit_ratio, coupling_ratio)
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
# Step 4: Search database for best matching resonator design
|
|
296
|
+
target_params_resonator = {"Cavity_Frequency_GHz": f_r, "kappa_MHz": kappa, "wavelength": wavelength_type}
|
|
297
|
+
df_flagged_2 = self.find_closest(target_params_resonator, num_top, metric, display=False)
|
|
298
|
+
|
|
299
|
+
# Step 4.1: Extract the best matching resonator design parameters
|
|
300
|
+
kappa_sim, f_r_sim = df_flagged_2['kappa_MHz'].values[0], df_flagged_2['Cavity_Frequency_GHz'].values[0]
|
|
301
|
+
alpha_sim, g_sim = df_flagged_2['Qubit_Anharmonicity_MHz'].values[0], df_flagged_2['Coupling_Strength_MHz'].values[0]
|
|
302
|
+
f_q_sim = df_flagged_2['Qubit_Frequency_GHz'].values[0]
|
|
303
|
+
# C_q_sim, C_r_sim, C_c_sim, E_J_sim, E_C_sim = self.get_coupling_parameters(f_q_sim, f_r_sim, alpha_sim, g_sim, wavelength_type)
|
|
304
|
+
|
|
305
|
+
# Steps 5: Scale the resonator length and coupling dimension
|
|
306
|
+
|
|
307
|
+
# Step 5.1: Get the design dict for the best matching resonator design
|
|
308
|
+
design = self.get_design(df_flagged_2)
|
|
309
|
+
|
|
310
|
+
# Step 5.2: Scale the resonator length and coupling dimension
|
|
311
|
+
res_length_ratio, coupling_dim_ratio = f_r_sim/f_r, np.sqrt(kappa/kappa_sim)
|
|
312
|
+
|
|
313
|
+
# Step 5.3: Scale the resonator length and coupling dimension and update the design dict
|
|
314
|
+
updated_design2 = self.get_updated_design_scaled_resonator_length_and_coupling_dim(design, res_length_ratio, coupling_dim_ratio)
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
# Step 6: C_c / C_r > 0.01 check and rescale the resonator length as necessary to hit the target
|
|
318
|
+
|
|
319
|
+
# Step 6.1: Calculate the target resonator length
|
|
320
|
+
L_r = 1 / (C_r * (2*np.pi*f_r)** 2)
|
|
321
|
+
|
|
322
|
+
if C_c / C_r > 0.01:
|
|
323
|
+
# Step 6.2: rescale the resonator length
|
|
324
|
+
omega_r = 1 / np.sqrt(L_r*(C_r + C_c))
|
|
325
|
+
res_length_ratio = (2*np.pi*f_r_sim) / omega_r
|
|
326
|
+
updated_design2 = self.get_updated_design_scaled_resonator_length_and_coupling_dim(design, res_length_ratio, coupling_dim_ratio)
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
# TODO: create a `interpolated_design` dict using the updated information
|
|
330
|
+
# interpolated_designs = self.interpolate_design(updated_design1, updated_design2)
|
|
331
|
+
interpolated_designs = [updated_design1, updated_design2]
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
# Step 7: Return interpolated design and best matching df
|
|
335
|
+
df_design= self.find_closest(target_params, num_top, metric, display=False)
|
|
336
|
+
|
|
337
|
+
return interpolated_designs, df_design
|
|
338
|
+
|
|
339
|
+
def extract_area_parameters(self, options: dict[str, str]) -> dict[str, float]:
|
|
340
|
+
"""
|
|
341
|
+
Extracts parameters of interest related to the qubit and cavity capacitor
|
|
342
|
+
areas from the input options dictionary.
|
|
343
|
+
|
|
344
|
+
Args:
|
|
345
|
+
options (dict): Configuration options for qubit and cavity.
|
|
346
|
+
|
|
347
|
+
Returns:
|
|
348
|
+
dict: A dictionary containing the parameters of interest.
|
|
349
|
+
"""
|
|
350
|
+
# Define keys of interest
|
|
351
|
+
if "Transmon" in self.component_name:
|
|
352
|
+
keys_of_interest = [
|
|
353
|
+
'cavity_options.coupler_options.coupling_length',
|
|
354
|
+
'cavity_options.coupler_options.prime_width',
|
|
355
|
+
'qubit_options.cross_width',
|
|
356
|
+
'qubit_options.cross_length'
|
|
357
|
+
]
|
|
358
|
+
else:
|
|
359
|
+
raise NotImplementedError("The method for calculating qubit parameters for the chosen qubit type is not implemented.")
|
|
360
|
+
|
|
361
|
+
# Extract parameters of interest
|
|
362
|
+
params_of_interest = {}
|
|
363
|
+
for key in keys_of_interest:
|
|
364
|
+
if key not in options:
|
|
365
|
+
raise KeyError(f"Key {key} not found in options")
|
|
366
|
+
params_of_interest[key] = float(options[key].strip('um'))
|
|
367
|
+
return params_of_interest
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
def get_updated_design_with_scaled_qubit_and_coupling_capacitor_areas(self, design, qubit_ratio, coupling_ratio):
|
|
372
|
+
"""
|
|
373
|
+
Scales the qubit and coupling capacitor areas by a given ratio and updates the design dict accordingly.
|
|
374
|
+
|
|
375
|
+
Args:
|
|
376
|
+
design (dict): A dictionary containing the design parameters.
|
|
377
|
+
qubit_ratio (float): The ratio by which to scale the qubit area.
|
|
378
|
+
coupling_ratio (float): The ratio by which to scale the coupling capacitor area.
|
|
379
|
+
|
|
380
|
+
Returns:
|
|
381
|
+
dict: Updated design dict with scaled areas.
|
|
382
|
+
"""
|
|
383
|
+
|
|
384
|
+
# Check and scale qubit capacitor area
|
|
385
|
+
if 'Transmon' in self.component_name:
|
|
386
|
+
design['qubit_options.cross_length'] = scale_value(design['qubit_options.cross_length'], qubit_ratio)
|
|
387
|
+
else:
|
|
388
|
+
raise NotImplementedError("The method for calculating qubit parameters for the chosen qubit type is not implemented.")
|
|
389
|
+
|
|
390
|
+
# Check and scale coupling capacitor area
|
|
391
|
+
coupling_type = design.get('cavity_options.coupling_type', '')
|
|
392
|
+
if coupling_type in ['capacitive', 'inductive']:
|
|
393
|
+
design['cavity_options.coupler_options.coupling_length'] = scale_value(design['cavity_options.coupler_options.coupling_length'], coupling_ratio)
|
|
394
|
+
elif 'interdig' in coupling_type:
|
|
395
|
+
# If finger_length is not in the coupler_options dictionary, set its default value
|
|
396
|
+
if 'finger_length' not in design.get('cavity_options.coupler_options', {}):
|
|
397
|
+
design['cavity_options.coupler_options']['finger_length'] = '50um'
|
|
398
|
+
design['cavity_options.coupler_options']['finger_length'] = scale_value(design['cavity_options.coupler_options']['finger_length'], coupling_ratio)
|
|
399
|
+
|
|
400
|
+
return design
|
|
401
|
+
|
|
402
|
+
def get_updated_design_scaled_resonator_length_and_coupling_dim(self, design, res_length_ratio, coupling_dim_ratio):
|
|
403
|
+
"""
|
|
404
|
+
Scales the resonator length and coupling dimension by a given ratio and updates the design dict accordingly.
|
|
405
|
+
|
|
406
|
+
Args:
|
|
407
|
+
design (dict): A dictionary containing the design parameters.
|
|
408
|
+
res_length_ratio (float): The ratio by which to scale the resonator length.
|
|
409
|
+
coupling_dim_ratio (float): The ratio by which to scale the coupling dimension.
|
|
410
|
+
|
|
411
|
+
Returns:
|
|
412
|
+
dict: Updated design dict with scaled areas.
|
|
413
|
+
"""
|
|
414
|
+
|
|
415
|
+
# Check and scale resonator length
|
|
416
|
+
design['cavity_options.cpw_options.total_length'] = scale_value(design['cavity_options.cpw_options.total_length'], res_length_ratio)
|
|
417
|
+
|
|
418
|
+
# Check and scale coupling dimensions
|
|
419
|
+
coupling_type = design.get('cavity_options.coupling_type', '')
|
|
420
|
+
if coupling_type in ['capacitive', 'inductive']:
|
|
421
|
+
design['cavity_options.coupler_options.coupling_length'] = scale_value(design['cavity_options.coupler_options.coupling_length'], coupling_dim_ratio)
|
|
422
|
+
elif 'interdig' in coupling_type:
|
|
423
|
+
# If finger_length is not in the coupler_options dictionary, set its default value
|
|
424
|
+
if 'finger_length' not in design.get('cavity_options.coupler_options', {}):
|
|
425
|
+
design['cavity_options.coupler_options']['finger_length'] = '50um'
|
|
426
|
+
design['cavity_options.coupler_options']['finger_length'] = scale_value(design['cavity_options.coupler_options']['finger_length'], coupling_dim_ratio)
|
|
427
|
+
|
|
428
|
+
return design
|
|
429
|
+
|
|
430
|
+
|
|
431
|
+
def get_design(self, df):
|
|
432
|
+
"""
|
|
433
|
+
Extracts the design parameters from the dataframe and returns a dict.
|
|
434
|
+
"""
|
|
435
|
+
return df["design_options"].to_dict()[0]
|
|
436
|
+
|
|
437
|
+
def get_param(self, design, param):
|
|
438
|
+
"""
|
|
439
|
+
Extracts a specific parameter from the design dict.
|
|
440
|
+
"""
|
|
441
|
+
raise NotImplementedError
|
|
442
|
+
|
|
443
|
+
def interpolate_design(self, updated_design1, updated_design2):
|
|
444
|
+
"""
|
|
445
|
+
Interpolates the design parameters of the resonator and qubit to the design dict.
|
|
446
|
+
"""
|
|
447
|
+
raise NotImplementedError
|
|
448
|
+
|
|
449
|
+
def get_coupling_parameters(self, f_q, f_r, alpha, g, wavelength_type, Z_q=50, Z_r=50):
|
|
450
|
+
"""
|
|
451
|
+
Numerically calculate the required qubit capacitance, coupling capacitance, and E_J.
|
|
452
|
+
For demonstration, using theoretical expressions.
|
|
453
|
+
|
|
454
|
+
Args:
|
|
455
|
+
f_q (float): Qubit frequency in GHz.
|
|
456
|
+
f_r (float): Resonator frequency in GHz.
|
|
457
|
+
alpha (float): Qubit anharmonicity in MHz.
|
|
458
|
+
g (float): Coupling strength in MHz.
|
|
459
|
+
wavelength_type (str): Type of wavelength to use for calculating coupling capacitance.
|
|
460
|
+
Z_q (float): Qubit impedance in Ohms.
|
|
461
|
+
Z_r (float): Resonator impedance in Ohms.
|
|
462
|
+
Returns:
|
|
463
|
+
tuple: A tuple containing the calculated qubit capacitance, coupling capacitance, and E_J.
|
|
464
|
+
"""
|
|
465
|
+
PHI_0 = 2.067833848E-15 # Magnetic flux quantum
|
|
466
|
+
H = 6.62607015E-34 # Planck's constant
|
|
467
|
+
Q = 1.602176634E-19 # Elementary charge
|
|
468
|
+
|
|
469
|
+
scq.set_units("GHz")
|
|
470
|
+
|
|
471
|
+
|
|
472
|
+
if "Transmon" in self.component_name:
|
|
473
|
+
# alpha to gigahertz
|
|
474
|
+
alpha = - alpha/1000 #to gigahertz
|
|
475
|
+
E_J, E_C = TunableTransmon.find_EJ_EC(E01=f_q, anharmonicity=alpha, ncut=30)
|
|
476
|
+
|
|
477
|
+
C_q = Q ** 2 / (2 * E_C) # Qubit capacitance
|
|
478
|
+
|
|
479
|
+
if wavelength_type == "lambda/4" or "quarter":
|
|
480
|
+
C_r = np.pi / (4 * Z_r * f_r) # Resonator capacitance
|
|
481
|
+
elif wavelength_type == "lambda/2" or "half":
|
|
482
|
+
C_r = np.pi / (2 * Z_r * f_r) # Resonator capacitance
|
|
483
|
+
|
|
484
|
+
C_c = C_q * g * (C_r / (Q**2 * f_r))**1/2 * ((8*E_C)/E_J )**1/4 # Coupling capacitance (Here E_{C,q} = E_C)
|
|
485
|
+
|
|
486
|
+
if E_J / E_C < 30:
|
|
487
|
+
warnings.warn("E_J/E_C < 30, the design may not be optimal.")
|
|
488
|
+
return C_q, C_r, C_c, E_J, E_C
|
|
489
|
+
|
|
490
|
+
else:
|
|
491
|
+
raise NotImplementedError("The method for calculating qubit parameters for the chosen qubit type is not implemented.")
|