Skip to content

Commit

Permalink
hot bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ikaryss committed Nov 11, 2022
1 parent 1942d93 commit 15947b9
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,6 @@ poetry.lock
tech_tests.ipynb
/examples/random_test.ipynb
/home_tests
/pyquac/ddd.csv
/pyquac/good_case.csv
/pyquac/jyp_app.ipynb
.vscode
64 changes: 44 additions & 20 deletions examples/random_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,61 @@
# family class
from pyquac.datatools import Spectroscopy, timer


class Random_spectroscopy(Spectroscopy):
"""
Two Tone Spectroscopy for 1 qubit measurements
"""

def __init__(self,
*,
x_min=None, x_max=None, y_min=None, y_max=None,
nx_points=None, x_step=None,
y_step=None, ny_points=None,
x_arr=None, y_arr=None,
):
def __init__(
self,
*,
x_min=None,
x_max=None,
y_min=None,
y_max=None,
nx_points=None,
x_step=None,
y_step=None,
ny_points=None,
x_arr=None,
y_arr=None,
):

super().__init__(x_min=x_min, x_max=x_max, nx_points=nx_points, y_min=y_min, y_max=y_max, ny_points=ny_points,
x_step=x_step, y_step=y_step, x_arr=x_arr, y_arr=y_arr)
super().__init__(
x_min=x_min,
x_max=x_max,
nx_points=nx_points,
y_min=y_min,
y_max=y_max,
ny_points=ny_points,
x_step=x_step,
y_step=y_step,
x_arr=x_arr,
y_arr=y_arr,
)
pass

def run_measurements(self, *, x_key: Union[float, int, Iterable] = None, y_key: Union[float, int, Iterable] = None,
x_min=None, x_max=None, y_min=None, y_max=None,
sleep=0.007):

self.iter_setup(x_key=x_key, y_key=y_key,
x_min=x_min, x_max=x_max, y_min=y_min, y_max=y_max)
def run_measurements(
self,
*,
x_key: Union[float, int, Iterable] = None,
y_key: Union[float, int, Iterable] = None,
x_min=None,
x_max=None,
y_min=None,
y_max=None,
sleep=0.007,
):

self.iter_setup(
x_key=x_key, y_key=y_key, x_min=x_min, x_max=x_max, y_min=y_min, y_max=y_max
)
iterations = len(self.load)
try:
for i in range(len(self.load)):
for i in range(iterations):

self.write(x=self.load[i],
y=self.frequency[i],
z=np.random.random()
)
self.write(x=self.load[i], y=self.frequency[i], z=np.random.random())
timer.sleep(sleep)

except KeyboardInterrupt:
Expand Down
20 changes: 10 additions & 10 deletions pyquac/datatools.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ def cust_range(cls, *args, rtol=1e-05, atol=1e-08, include=(True, False)):
Avoids also floating point rounding errors as with
numpy.arange(1, 1.3, 0.1)
array([1. , 1.1, 1.2, 1.3])
args: [start, ]stop, [step, ]
as in numpy.arange
rtol, atol: floats
Expand Down Expand Up @@ -113,7 +112,6 @@ class timer:
"""
timer class provides accurate variation of time.sleep() method. Example:
timer.sleep(1) # sleeps for 1. second
Why to use this? If you use time.sleep() for 1 iteration, it wouldn't bring you problem, but if your script
requires a loop with time.sleep() inside, Windows OS will ruin your script execution. To explain why this
happened, Windows OS has its default timer resolution set to 15.625 ms or 64 Hz, which is decently enough for
Expand All @@ -130,10 +128,8 @@ def sleep(sec: float):

class Spectroscopy:
"""Data class for manipulating live-data for heatmap graph
Raises:
AttributeError: _description_
Returns:
_type_: _description_
"""
Expand Down Expand Up @@ -166,6 +162,7 @@ class Spectroscopy:
"__len_y",
"__x_for_approximate_idxs",
"__approximation_y_keys",
"__z_container_numba"
]

def __init__(
Expand Down Expand Up @@ -284,6 +281,9 @@ def __init__(
self.__x_container = np.zeros(len(self.x_list) * len(self.y_list))
self.__y_container = np.zeros(len(self.x_list) * len(self.y_list))

self.__z_container_numba = np.zeros(len(self.x_list) * len(self.y_list))
self.__z_container_numba[:] = np.nan

self.x_1d = np.repeat(self.x_list, len(self.y_list))
self.y_1d = np.tile(self.y_list, len(self.x_list))
self.__n_steps = int(0.04 * len(self.y_list))
Expand Down Expand Up @@ -620,7 +620,7 @@ def njit_result(self):
x_val, y_val, self.x_min, self.x_step, self.y_min, self.y_step, self.__len_y
)
if len(self.x_raw) >= 2:
array_to_process = np.copy(self.__z_container)
array_to_process = np.copy(self.__z_container_numba)
array_to_process[ind_array.astype(int)] = z_val

return array_to_process
Expand Down Expand Up @@ -952,17 +952,17 @@ def drop(
self.__drop_the_cols(x, y)
pass

def load_data(self, raw_file: str):
def load_data(self, raw_file: str, x_col_name:str = 'x_value', y_col_name:str = 'y_value', z_col_name:str = 'z_value'):
"""
loads csv file to Spectroscopy class data structure. CSV file must contain three columns ['x_value', 'y_value', 'z_value']. Dtype of each value - Float | int
:param raw_file: x value(s)
:type raw_file: str
"""
raw_csv = pd.read_csv(raw_file)

self.x_raw = list(raw_csv.x_value.values)
self.y_raw = list(raw_csv.y_value.values)
self.z_raw = list(raw_csv.z_value.values)
self.x_raw = list(raw_csv[x_col_name].values)
self.y_raw = list(raw_csv[y_col_name].values)
self.z_raw = list(raw_csv[z_col_name].values)

def __drop_the(self, column: str, value_s: Union[float, int, Iterable]):

Expand Down Expand Up @@ -1150,4 +1150,4 @@ def __find_nearest_universal(self, arr, value):
def __find_nearest(self, value):
array = np.asarray(self.y_list)
idx = (np.abs(array - value)).argmin()
return array[idx]
return array[idx]

0 comments on commit 15947b9

Please sign in to comment.