Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

pyquac

Package Overview
Dependencies
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pyquac - npm Package Compare versions

Comparing version
1.1.9
to
1.1.11
+646
pyquac/fmn_spectroscopy.py
# built-in libraries
from time import perf_counter
from typing import Iterable, Union
import time
# installable libraries
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
from scipy import stats
import numba as nb
# working with 2nd qubit
from scipy.optimize import curve_fit
# devices
import zhinst
import zhinst.ziPython
from drivers.M9290A import *
from drivers.N5183B import *
from drivers.znb_besedin import *
from resonator_tools import circlefit
from resonator_tools.circuit import notch_port
# family class
from pyquac.fmn_datatools import TwoToneSpectroscopy, timer
def _fit_cos(t, A1, A0, omega, teta):
return A1 * np.cos(2 * np.pi * omega * t + teta) + A0
class Tts(TwoToneSpectroscopy):
"""
Two Tone Spectroscopy for 1 qubit measurements
"""
def __init__(self,
*, x_min, x_max, y_min, y_max,
fr_min: float, fr_max: float,
nx_points=None, x_step=None,
y_step=None, ny_points=None,
hdawg_port: str = '127.0.0.1', hdawg_port1: int = 8004, hdawg_mode: int = 6,
hdawg_device: str = 'dev8210', hdawg_channel: int = 5,
LO_port: str = 'TCPIP0::192.168.180.143::hislip0::INSTR',
LO_res_port: str = 'TCPIP0::192.168.180.110::inst0::INSTR',
LO_set_power: int = 5,
LO_res_set_bandwidth: int = 20, LO_res_set_power: int = -10, LO_res_set_nop=101,
base_bandwidth=40, LO_res_set_averages=1, LO_res_meas_averages=1
):
"""
Class provides methods for working with live data for Two Tone Spectroscopy
:param x_min: x minimum value (int | float)
:param x_max: x maximum value (int | float)
:param y_min: y minimum value (int | float)
:param y_max: y maximum value (int | float)
:param nx_points: x count value (int)
:param x_step: x step value (float)
:param ny_points: y count value (int)
:param y_step: y step value (float)
:param fr_min: min frequency for find resonator
:param fr_max: max frequency for find resonator
:param hdawg_port: hdawg = zhinst.ziPython.ziDAQServer(hdawg_port, hdawg_port1, hdawg_mode)
:param hdawg_port1: hdawg = zhinst.ziPython.ziDAQServer(hdawg_port, hdawg_port1, hdawg_mode)
:param hdawg_mode: hdawg = zhinst.ziPython.ziDAQServer(hdawg_port, hdawg_port1, hdawg_mode)
:param LO_port: qubit LO = N5183B('N5183B', LO_port)
:param LO_res_port: resonator LO_res = Znb(LO_res_port)
:param hdawg_device: 'dev8210' by default
:param hdawg_channel: hdawg.setInt('/' + hdawg_device + '/sigouts/' + str(hdawg_channel) + '/on', 1)
:param LO_set_power: base LO power (default 5)
:param LO_res_set_bandwidth: bandwidth during resonator tuning
:param LO_res_set_power: base resonator LO power (default -10)
:param LO_res_set_nop: number of points during resonator scanning (default 101)
:param base_bandwidth: (int) bandwidth during mesurments
:param LO_res_set_averages: set averages for resonator LO parameter
:param LO_res_meas_averages: measure averages for resonator LO parameter
"""
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)
self.fr_min = fr_min
self.fr_max = fr_max
self.hdawg_channel = hdawg_channel
self.hdawg_device = hdawg_device
# HDAWG init
self.hdawg = zhinst.ziPython.ziDAQServer(hdawg_port, hdawg_port1, hdawg_mode)
self.hdawg_setDouble = '/' + self.hdawg_device + '/sigouts/' + str(self.hdawg_channel) + '/offset'
# open HDAWG ZI
hdawgModule = self.hdawg.awgModule()
# freq generator init
self.LO = N5183B('N5183B', LO_port) # qubit
self.LO_res = Znb(LO_res_port) # resonator
# set base parameters
self.LO_set_power = LO_set_power
self.LO_res_set_nop = LO_res_set_nop
self.LO_res_set_bandwidth = LO_res_set_bandwidth
self.LO_res_set_power = LO_res_set_power
self.base_bandwidth = base_bandwidth
self.LO_res_set_averages = LO_res_set_averages
self.LO_res.set_averages(LO_res_set_averages)
self.LO_res_meas_averages = LO_res_meas_averages
pass
@property
def __find_resonator(self):
self.LO.set_status(0)
# prior bandwidth
bandwidth = self.LO_res.get_bandwidth()
xlim = self.LO_res.get_freq_limits()
self.LO_res.set_bandwidth(self.LO_res_set_bandwidth)
self.LO_res.set_nop(self.LO_res_set_nop)
self.LO_res.set_freq_limits(self.fr_min, self.fr_max)
self.LO_res.set_averages(self.LO_res_set_averages)
# measure S21
freqs = self.LO_res.get_freqpoints()
notch = notch_port(freqs, self.LO_res.measure()['S-parameter'])
notch.autofit(electric_delay=60e-9)
result = round(notch.fitresults['fr'])
# Resetting to the next round of measurements
self.LO_res.set_bandwidth(bandwidth)
self.LO_res.set_freq_limits(*xlim)
self.LO_res.set_nop(1)
self.LO.set_status(1)
return result
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, timeout=None):
# Turn on HDAWG
self.hdawg.setInt('/' + self.hdawg_device + '/sigouts/' + str(self.hdawg_channel) + '/on', 1)
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)
# Set power
self.LO.set_power(self.LO_set_power)
self.LO_res.set_power(self.LO_res_set_power)
# base bandwidth
self.LO_res.set_bandwidth(self.base_bandwidth)
try:
for i in range(len(self.load)):
if (i == 0) or (self.load[i] != self.load[i - 1]):
self.LO_res.set_center(float(self.__find_resonator))
if timeout is not None:
timer.sleep(timeout)
else:
pass
# measurement averages
self.LO_res.set_averages(self.LO_res_meas_averages)
self.hdawg.setDouble(self.hdawg_setDouble, self.load[i]) # Current write
self.LO.set_frequency(self.frequency[i]) # Frequency write
result = self.LO_res.measure()['S-parameter']
self.write(x=self.load[i],
y=self.frequency[i],
heat=20 * np.log10(abs(result)[0])
)
timer.sleep(sleep)
except KeyboardInterrupt:
pass
# Turn off LO
self.LO.set_status(0)
# Turn off HDAWG
self.hdawg.setInt('/' + self.hdawg_device + '/sigouts/' + str(self.hdawg_channel) + '/on', 0)
class Sts(TwoToneSpectroscopy):
"""
Single Tone Spectroscopy for 1 qubit measurements
"""
def __init__(self,
*, x_min, x_max, y_min, y_max,
nx_points=None, x_step=None, y_step=None, ny_points=None,
hdawg_port: str = '127.0.0.1', hdawg_port1: int = 8004, hdawg_mode: int = 6,
hdawg_channel: int = 5, hdawg_device: str = 'dev8210',
LO_res_port: str = 'TCPIP0::192.168.180.110::inst0::INSTR',
LO_res_set_bandwidth: int = 20, LO_res_set_power: int = -10,
LO_res_set_averages=1
):
"""
:param x_min: x minimum value (int | float)
:param x_max: x maximum value (int | float)
:param y_min: y minimum value (int | float)
:param y_max: y maximum value (int | float)
:param x_step: x step value (float)
:param nx_points: x count value (int)
:param y_step: y step value (float)
:param ny_points: y count value (int)
:param hdawg_port: hdawg = zhinst.ziPython.ziDAQServer(hdawg_port, hdawg_port1, hdawg_mode)
:param hdawg_port1: hdawg = zhinst.ziPython.ziDAQServer(hdawg_port, hdawg_port1, hdawg_mode)
:param hdawg_mode: hdawg = zhinst.ziPython.ziDAQServer(hdawg_port, hdawg_port1, hdawg_mode)
:param LO_res_port: resonator LO_res = Znb(LO_res_port)
:param hdawg_channel: hdawg.setInt('/' + hdawg_device + '/sigouts/' + str(hdawg_channel) + '/on', 1)
:param hdawg_device: 'dev8210' by default
:param LO_res_set_bandwidth: base bandwidth (default 20)
:param LO_res_set_power: base LO_res power (default -10)
:param LO_res_set_averages: set averages for resonator LO parameter
"""
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)
self.ny_points = ny_points if self.y_step is None else len(self.y_list)
# HDAWG init
self.hdawg_device = hdawg_device
self.hdawg_channel = hdawg_channel
# HDAWG init
self.hdawg = zhinst.ziPython.ziDAQServer(hdawg_port, hdawg_port1, hdawg_mode)
hdawgModule = self.hdawg.awgModule()
# LO connect
self.LO_res = Znb(LO_res_port) # resonator
# set base parameters of LO res
self.LO_res_set_bandwidth = LO_res_set_bandwidth
self.LO_res_set_power = LO_res_set_power
self.LO_res_set_averages = LO_res_set_averages
self.LO_res.set_averages(LO_res_set_averages)
pass
def run_measurements(self, *, sleep=0.0007):
self.iter_setup(x_key=None, y_key=None,
x_min=None, x_max=None, y_min=None, y_max=None)
# enable channel
self.hdawg.setInt('/' + self.hdawg_device + '/sigouts/' + str(self.hdawg_channel) + '/on', 1)
# Set power
self.LO_res.set_power(self.LO_res_set_power)
# Set LO parameters
self.LO_res.set_bandwidth(self.LO_res_set_bandwidth)
self.LO_res.set_nop(self.ny_points)
self.LO_res.set_freq_limits(self.y_min, self.y_max)
freq_len = len(self.y_list)
try:
for i in range(len(self.load)):
if (i == 0) or (self.load[i] != self.load[i - 1]):
self.hdawg.setDouble('/' + hdawg_device + '/sigouts/' + str(self.hdawg_channel)
+ '/offset', self.load[i]) # current write
self.LO_res.set_averages(self.LO_res_set_averages)
result = self.LO_res.measure()['S-parameter']
for j in range(freq_len):
self.write(x=self.load[i],
y=self.y_list[j],
heat=20 * np.log10(abs(result[j]))
)
timer.sleep(sleep)
except KeyboardInterrupt:
if (self.x_raw[-1] == self.x_list[-1]) and (self.y_raw[-1] == self.y_list[-1]):
pass
else:
# drop the last column if interrupt for stable data saving
self.drop(x=self.x_raw[-1])
pass
# channel switch off
self.hdawg.setInt('/' + self.hdawg_device + '/sigouts/' + str(self.hdawg_channel) + '/on', 0)
class Sts2Q(TwoToneSpectroscopy):
"""
Single Tone Spectroscopy for 2 qubit measurements
"""
def __init__(self,
*,
flux_qubit: str, readout_qubit: str,
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_min_coupler=None, x_max_coupler=None, x_step_coupler=None, nx_points_coupler=None,
x_min_control=None, x_max_control=None, x_step_control=None, nx_points_control=None,
target_ch: int = None,
control_ch: int = None,
coupler_ch: int = None,
hdawg_port: str = '127.0.0.1', hdawg_port1: int = 8004, hdawg_mode: int = 6,
hdawg_device: str = 'dev8210',
LO_res_port: str = 'TCPIP0::192.168.180.110::inst0::INSTR',
LO_res_set_bandwidth: int = 20, LO_res_set_power: int = -10,
LO_res_set_averages=1
):
"""
:param flux_qubit: str|list of strings. names of qubits that we drive
:param readout_qubit: str. name of readout qubit
:param x_min: min x value of target qubit or base x_min while checking
:param x_max: max x value of target qubit or base x_max while checking
:param y_min: min y value of readout qubit
:param y_max: max y value of readout qubit
:param nx_points: nx_points value of target qubit or base nx_points while checking
:param x_step: x_step value of target qubit or base x_step while checking
:param y_step: y_step value of readout qubit
:param ny_points: ny_points value of readout qubit
:param x_min_coupler: min x value of coupler qubit
:param x_max_coupler: max x value of coupler qubit
:param x_step_coupler: x_step value of coupler qubit
:param nx_points_coupler: nx_points value of coupler qubit
:param x_min_control: min x value of control qubit
:param x_max_control: max x value of control qubit
:param x_step_control: x_step value of control qubit
:param nx_points_control: nx_points value of control qubit
:param target_ch: target channel
:param control_ch: control channel
:param coupler_ch: coupler channel
:param hdawg_port: hdawg = zhinst.ziPython.ziDAQServer(hdawg_port, hdawg_port1, hdawg_mode)
:param hdawg_port1: hdawg = zhinst.ziPython.ziDAQServer(hdawg_port, hdawg_port1, hdawg_mode)
:param hdawg_mode: hdawg = zhinst.ziPython.ziDAQServer(hdawg_port, hdawg_port1, hdawg_mode)
:param LO_res_port: resonator LO_res = Znb(LO_res_port)
:param hdawg_channel: hdawg.setInt('/' + hdawg_device + '/sigouts/' + str(hdawg_channel) + '/on', 1)
:param hdawg_device: 'dev8210' by default
:param LO_res_set_bandwidth: base bandwidth (default 20)
:param LO_res_set_power: base LO_res power (default -10)
:param LO_res_set_averages: set averages for resonator LO parameter
"""
if (target_ch is not None) and (control_ch is None) and (coupler_ch is 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)
self.ny_points = ny_points if self.y_step is None else len(self.y_list)
# channel define
self.target_ch = target_ch
elif (coupler_ch is not None) and (control_ch is None) and (target_ch is None):
super().__init__(x_min=x_min_coupler, x_max=x_max_coupler, nx_points=nx_points_coupler, y_min=y_min,
y_max=y_max,
ny_points=ny_points, x_step=x_step_coupler, y_step=y_step)
self.ny_points = ny_points if self.y_step is None else len(self.y_list)
# channel define
self.coupler_ch = coupler_ch
elif (control_ch is not None) and (coupler_ch is None) and (target_ch is None):
super().__init__(x_min=x_min_control, x_max=x_max_control, nx_points=nx_points_control, y_min=y_min,
y_max=y_max, ny_points=ny_points, x_step=x_step_control,
y_step=y_step)
self.ny_points = ny_points if self.y_step is None else len(self.y_list)
# channel define
self.control_ch = control_ch
else:
if target_ch is not None:
self.target_ch = target_ch
if coupler_ch is not None:
self.coupler_ch = coupler_ch
if control_ch is not None:
self.control_ch = control_ch
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)
self.ny_points = ny_points if self.y_step is None else len(self.y_list)
# HDAWG init
self.hdawg_device = hdawg_device
self.hdawg = zhinst.ziPython.ziDAQServer(hdawg_port, hdawg_port1, hdawg_mode)
hdawgModule = self.hdawg.awgModule()
# LO connect
self.LO_res = Znb(LO_res_port) # resonator
# set base parameters of LO res
self.LO_res_set_bandwidth = LO_res_set_bandwidth
self.LO_res_set_power = LO_res_set_power
self.LO_res_set_averages = LO_res_set_averages
self.LO_res.set_averages(LO_res_set_averages)
self.flux_qubit = flux_qubit
self.readout_qubit = readout_qubit
self.finished = False
self.active = False
self.start_for_fit_LP = (6, 0.02, 0.1, 0)
self.start_for_fit_HP = (10, 0.2, 0.5, 0)
self.fit = None
self.x_offset = None
pass
def run_measurements(self, *, sleep=0.0007):
self.iter_setup(x_key=None, y_key=None,
x_min=None, x_max=None, y_min=None, y_max=None)
self.active = True
# channel switch on
if self.target_ch is not None:
self.hdawg.setInt('/' + self.hdawg_device + '/sigouts/' + str(self.target_ch) + '/on', 1)
if self.coupler_ch is not None:
self.hdawg.setInt('/' + self.hdawg_device + '/sigouts/' + str(self.coupler_ch) + '/on', 1)
if self.control_ch is not None:
self.hdawg.setInt('/' + self.hdawg_device + '/sigouts/' + str(self.control_ch) + '/on', 1)
# Set power
self.LO_res.set_power(self.LO_res_set_power)
# Set LO parameters
self.LO_res.set_bandwidth(self.LO_res_set_bandwidth)
self.LO_res.set_nop(self.ny_points)
self.LO_res.set_freq_limits(self.y_min, self.y_max)
freq_len = len(self.y_list)
try:
for i in range(len(self.load)):
if (i == 0) or (self.load[i] != self.load[i - 1]):
if self.target_ch is not None:
self.hdawg.setDouble('/' + self.hdawg_device + '/sigouts/'
+ str(self.target_ch) + '/offset', self.load[i])
if self.coupler_ch is not None:
self.hdawg.setDouble('/' + self.hdawg_device + '/sigouts/'
+ str(self.coupler_ch) + '/offset', self.load[i])
if self.control_ch is not None:
self.hdawg.setDouble('/' + self.hdawg_device + '/sigouts/'
+ str(self.control_ch) + '/offset', self.load[i])
self.LO_res.set_averages(self.LO_res_set_averages)
result = self.LO_res.measure()['S-parameter']
for j in range(freq_len):
self.write(x=self.load[i],
y=self.y_list[j],
heat=20 * np.log10(abs(result[j]))
)
timer.sleep(sleep)
except KeyboardInterrupt:
if (self.x_raw[-1] == self.x_list[-1]) and (self.y_raw[-1] == self.y_list[-1]):
pass
else:
# drop the last column if interrupt for stable data saving
self.drop(x=self.x_raw[-1])
self.active = False
pass
if (self.x_raw[-1] == self.x_list[-1]) and (self.y_raw[-1] == self.y_list[-1]):
self.finished = True
else:
pass
# channel switch off
if self.target_ch is not None:
self.hdawg.setInt('/' + self.hdawg_device + '/sigouts/' + str(self.target_ch) + '/on', 0)
if self.coupler_ch is not None:
self.hdawg.setInt('/' + self.hdawg_device + '/sigouts/' + str(self.coupler_ch) + '/on', 0)
if self.control_ch is not None:
self.hdawg.setInt('/' + self.hdawg_device + '/sigouts/' + str(self.control_ch) + '/on', 0)
self.active = False
def fit_and_offset(self, start, fitted_freqs=None):
if fitted_freqs is not None:
fitted_params, cov = curve_fit(_fit_cos, self.x_list, fitted_freqs, start)
else:
fitted_freqs = self.fit_curve()['y']
fitted_params, cov = curve_fit(_fit_cos, self.x_list, fitted_freqs, start)
A1, A0, omega, teta = fitted_params
fit = A1 * np.cos(2 * np.pi * omega * self.x_list + teta) + A0
fit_dict = dict(x=self.x_list, y=fit)
x_offset = self.x_list[np.argmax(fit)]
self.fit = fit
self.x_offset = x_offset
return fit_dict, x_offset
class Sts2QContainer:
def __init__(self, *,
y_minQ1, y_maxQ1, y_minQ2, y_maxQ2,
q1_ch: int,
q2_ch: int,
coupler_ch: int,
x_min=None, x_max=None, nx_points=None, x_step=None,
x_minQ1=None, x_maxQ1=None, nx_pointsQ1=None, x_stepQ1=None,
ny_pointsQ1=None, y_stepQ1=None,
x_minC=None, x_maxC=None, nx_pointsC=None, x_stepC=None,
x_minQ2=None, x_maxQ2=None, nx_pointsQ2=None, x_stepQ2=None,
ny_pointsQ2=None, y_stepQ2=None,
hdawg_port: str = '127.0.0.1', hdawg_port1: int = 8004, hdawg_mode: int = 6,
hdawg_device: str = 'dev8210',
LO_res_port: str = 'TCPIP0::192.168.180.110::inst0::INSTR',
LO_res_set_bandwidth: int = 20, LO_res_set_power: int = -10,
LO_res_set_averages=1
):
if (x_min is not None) and (x_max is not None):
x_minQ1 = x_min if x_minQ1 is None else x_minQ1
x_minQ2 = x_min if x_minQ2 is None else x_minQ2
x_minC = x_min if x_minC is None else x_minC
x_maxQ1 = x_max if x_maxQ1 is None else x_maxQ1
x_maxQ2 = x_max if x_maxQ2 is None else x_maxQ2
x_maxC = x_max if x_maxC is None else x_maxC
nx_pointsQ1 = nx_points if nx_pointsQ1 is None else nx_pointsQ1
nx_pointsQ2 = nx_points if nx_pointsQ2 is None else nx_pointsQ2
nx_pointsC = nx_points if nx_pointsC is None else nx_pointsC
x_stepQ1 = x_step if x_stepQ1 is None else x_stepQ1
x_stepQ2 = x_step if x_stepQ2 is None else x_stepQ2
x_stepC = x_step if x_stepC is None else x_stepC
else:
pass
"Flux on Q1 | Coupler | Q2; Readout - Q1"
self.Q1 = Sts2Q(x_min=x_minQ1, x_max=x_maxQ1, y_min=y_minQ1, y_max=y_maxQ1,
nx_points=nx_pointsQ1, x_step=x_stepQ1, y_step=y_stepQ1, ny_points=ny_pointsQ1,
target_ch=q1_ch,
readout_qubit='Q1', flux_qubit='Q1',
hdawg_port=hdawg_port, hdawg_port1=hdawg_port1, hdawg_mode=hdawg_mode,
hdawg_device=hdawg_device,
LO_res_port=LO_res_port,
LO_res_set_bandwidth=LO_res_set_bandwidth, LO_res_set_power=LO_res_set_power,
LO_res_set_averages=LO_res_set_averages)
self.Q1_Coupler = Sts2Q(x_min_coupler=x_minC, x_max_coupler=x_maxC, y_min=y_minQ1, y_max=y_maxQ1,
nx_points_coupler=nx_pointsC, x_step_coupler=x_stepC, y_step=y_stepQ1, ny_points=ny_pointsQ1,
coupler_ch=coupler_ch,
readout_qubit='Q1', flux_qubit='Coupler',
hdawg_port=hdawg_port, hdawg_port1=hdawg_port1, hdawg_mode=hdawg_mode,
hdawg_device=hdawg_device,
LO_res_port=LO_res_port,
LO_res_set_bandwidth=LO_res_set_bandwidth, LO_res_set_power=LO_res_set_power,
LO_res_set_averages=LO_res_set_averages)
self.Q1_Q2 = Sts2Q(x_min_control=x_minQ2, x_max_control=x_maxQ2, y_min=y_minQ1, y_max=y_maxQ1,
nx_points_control=nx_pointsQ2, x_step_control=x_stepQ2, y_step=y_stepQ1, ny_points=ny_pointsQ1,
control_ch=q2_ch,
readout_qubit='Q1', flux_qubit='Q2',
hdawg_port=hdawg_port, hdawg_port1=hdawg_port1, hdawg_mode=hdawg_mode,
hdawg_device=hdawg_device,
LO_res_port=LO_res_port,
LO_res_set_bandwidth=LO_res_set_bandwidth, LO_res_set_power=LO_res_set_power,
LO_res_set_averages=LO_res_set_averages)
"Flux on Q1 | Coupler | Q2; Readout - Q2"
self.Q2 = Sts2Q(x_min=x_minQ2, x_max=x_maxQ2, y_min=y_minQ2, y_max=y_maxQ2,
nx_points=nx_pointsQ2, x_step=x_stepQ2, y_step=y_stepQ2, ny_points=ny_pointsQ2,
target_ch=q2_ch,
readout_qubit='Q2', flux_qubit='Q2',
hdawg_port=hdawg_port, hdawg_port1=hdawg_port1, hdawg_mode=hdawg_mode,
hdawg_device=hdawg_device,
LO_res_port=LO_res_port,
LO_res_set_bandwidth=LO_res_set_bandwidth, LO_res_set_power=LO_res_set_power,
LO_res_set_averages=LO_res_set_averages)
self.Q2_Coupler = Sts2Q(x_min_coupler=x_minC, x_max_coupler=x_maxC, y_min=y_minQ2, y_max=y_maxQ2,
nx_points_coupler=nx_pointsC, x_step_coupler=x_stepC, y_step=y_stepQ2, ny_points=ny_pointsQ2,
coupler_ch=coupler_ch,
readout_qubit='Q2', flux_qubit='Coupler',
hdawg_port=hdawg_port, hdawg_port1=hdawg_port1, hdawg_mode=hdawg_mode,
hdawg_device=hdawg_device,
LO_res_port=LO_res_port,
LO_res_set_bandwidth=LO_res_set_bandwidth, LO_res_set_power=LO_res_set_power,
LO_res_set_averages=LO_res_set_averages)
self.Q2_Q1 = Sts2Q(x_min_control=x_minQ1, x_max_control=x_maxQ1, y_min=y_minQ2, y_max=y_maxQ2,
nx_points_control=nx_pointsQ1, x_step_control=x_stepQ1, y_step=y_stepQ2, ny_points=ny_pointsQ2,
control_ch=q1_ch,
readout_qubit='Q2', flux_qubit='Q1',
hdawg_port=hdawg_port, hdawg_port1=hdawg_port1, hdawg_mode=hdawg_mode,
hdawg_device=hdawg_device,
LO_res_port=LO_res_port,
LO_res_set_bandwidth=LO_res_set_bandwidth, LO_res_set_power=LO_res_set_power,
LO_res_set_averages=LO_res_set_averages)
pass
@property
def final_matrix(self):
# First row
Q1_offset_base = self.Q1.x_offset if self.Q1.finished else None
a11 = 1 if self.Q1.finished else None
Q2_offset = self.Q1_Q2.x_offset if self.Q1_Q2.finished else None
a12 = Q1_offset_base / Q2_offset if self.Q1_Q2.finished and self.Q1.finished else None
Q1_coupler_offset = self.Q1_Coupler.x_offset if self.Q1_Coupler.finished else None
a13 = Q1_offset_base / Q1_coupler_offset if self.Q1_Coupler.finished and self.Q1.finished else None
# Second row
Q2_offset_base = self.Q2.x_offset if self.Q2.finished else None
Q1_offset = self.Q2_Q1.x_offset if self.Q2_Q1.finished else None
a21 = Q2_offset_base / Q1_offset if self.Q2_Q1.finished and self.Q2.finished else None
a22 = 1 if self.Q2.finished else None
Q2_coupler_offset = self.Q2_Coupler.x_offset if self.Q2_Coupler.finished else None
a23 = Q2_offset_base / Q2_coupler_offset if self.Q2_Coupler.finished and self.Q2.finished else None
# Third row
a31 = 0
a32 = 0
a33 = 1
matrix = np.array([[a11, a12, a13], [a21, a22, a23], [a31, a32, a33]])
return np.linalg.inv(matrix)
+1
-1
Metadata-Version: 2.1
Name: pyquac
Version: 1.1.9
Version: 1.1.11
Summary: Useful tools for quantum computing experiments, provided for BMSTU FMN

@@ -5,0 +5,0 @@ Home-page: https://github.com/ikaryss/pyquac

Metadata-Version: 2.1
Name: pyquac
Version: 1.1.9
Version: 1.1.11
Summary: Useful tools for quantum computing experiments, provided for BMSTU FMN

@@ -5,0 +5,0 @@ Home-page: https://github.com/ikaryss/pyquac

@@ -9,2 +9,3 @@ LICENSE.txt

pyquac/fmn_plottools.py
pyquac/fmn_spectroscopy.py
pyquac/fmn_tts.py

@@ -11,0 +12,0 @@ pyquac.egg-info/PKG-INFO

@@ -5,2 +5,3 @@ from . import datatools

from . import fmn_tts
from . import fmn_spectroscopy

@@ -11,3 +12,4 @@ __all__ = [

'fmn_datatools',
'fmn_tts'
'fmn_tts',
'fmn_spectroscopy'
]

@@ -110,3 +110,3 @@ # built-in libraries

*, x_min, x_max, y_min, y_max,
x_step = None, y_step = None, nx_points = None, ny_points = None):
x_step=None, y_step=None, nx_points=None, ny_points=None):
"""

@@ -185,2 +185,5 @@ Class provides methods for working with live data for Two Tone Spectroscopy

# service variables
self.__n_steps = int(0.04 * len(self.y_list))
x1 = 2000

@@ -379,2 +382,23 @@ y1 = 70e3

def get_raw_result(self):
"""
generates raw Data Frame with columns [x_value, y_value, response]
:return: Pandas Data Frame
"""
x = []
y = []
heat = []
uniq_x = np.unique(self.raw_frame.x_value.values)
for xx in uniq_x:
y_arr = self.raw_frame[self.raw_frame.x_value == xx].y_value.values
heat_arr = self.raw_frame[self.raw_frame.x_value == xx].heat_value.values
x.append(xx)
y.append(y_arr)
heat.append(heat_arr)
return pd.DataFrame({'x_value': x, 'y_value': y, 'response': heat})
@property

@@ -414,3 +438,2 @@ def non_njit_result(self):

ind_array = _complicated(x_val, y_val,

@@ -428,3 +451,3 @@ self.x_min, self.x_step, self.y_min, self.y_step,

def approximate(self, resolving_zone: float = 0.1, *, fillna: bool = False, info=False,
plot: bool = False, heat_sample=None, heat_sampe_tol=2):
plot: bool = False, heat_sample=None, heat_sampe_tol=0.5, x_key=None):
"""

@@ -442,9 +465,16 @@ return dict object with keys:

"""
X = self.raw_frame.copy()
"""rows that we are looking for (every x_value)"""
x_set = np.unique(X['x_value'].values) # get an array of unique values of x
if x_key is not None:
x_key = self.__config_closest_values(x_key, self.x_list)
X = self.raw_frame[self.raw_frame.x_value.isin(x_key)].copy()
X = X.reset_index(drop=True)
x_set = x_key
else:
X = self.raw_frame.copy()
"""rows that we are looking for (every x_value)"""
x_set = np.unique(X['x_value'].values) # get an array of unique values of x
if heat_sample is None:
glob_samp, glob_h_mi, glob_h_ma = self.__define_heat_sample_on(x_set, info=info, plot=plot, q_max=80, q_min=20)
glob_samp, glob_h_mi, glob_h_ma = self.__define_heat_sample_on(x_set, info=info, plot=plot, q_max=90,
q_min=10)

@@ -470,3 +500,3 @@ self.glob_samp = glob_samp

for xxx in x_set:
for _ in x_set:
self.heat_samples = np.append(self.heat_samples, self.glob_samp)

@@ -486,3 +516,3 @@ self.heat_mins = np.append(self.heat_mins, self.glob_h_mi)

if len(self.raw_frame[X.x_value == xx].y_value) <= 0.7 * len(self.y_list):
if len(X[X.x_value == xx].y_value) <= 0.7 * len(self.y_list):
temp_y_idx = (X[X.x_value == xx].heat_value - heat_sample).abs().idxmin()

@@ -574,2 +604,58 @@ else:

def fit_curve(self, x_key=None):
X = self.raw_frame.copy()
"""rows that we are looking for (every x_value)"""
x_set = np.unique(X['x_value'].values) # get an array of unique values of x
glob_samp, glob_h_mi, glob_h_ma = self.__define_heat_sample_on(x_set, info=False, plot=False, q_max=95,
q_min=5)
if x_key is not None:
approx = self.approximate(x_key=x_key, heat_sample=glob_samp, heat_sampe_tol=abs(glob_h_ma - glob_h_mi) / 2)
y_approx = approx['poly_line']['y']
tuple_list = ()
ip = 0
for xx in x_set:
y_min, y_max = self.__find_min_max_y_on_(xx, glob_samp)
if x_key is not None:
"block to prevent jump in y axis"
y_mid = (y_max + y_min) / 2
if abs(y_mid - y_approx[ip]) > (self.y_max - self.y_min) * 0.07:
y_min = y_approx[ip] - self.__n_steps * self.y_step
y_max = y_approx[ip] + self.__n_steps * self.y_step
pass
ip += 1
if len(self.raw_frame[X.x_value == xx].y_value) <= 0.7 * len(self.y_list):
temp_y_idx = (X[X.x_value == xx].heat_value - glob_samp).abs().idxmin()
else:
temp_y_idx = (X[(X.x_value == xx) & (X.y_value >= y_min) & (X.y_value <= y_max)
].heat_value - glob_samp).abs().idxmin()
temp_max_row = tuple(X.iloc[temp_y_idx])
tuple_list += (temp_max_row,)
# rotating array
tuple_of_max_z_values = np.array(tuple_list).T
return dict(x=tuple_of_max_z_values[0],
y=tuple_of_max_z_values[1])
def check_heat_samp(self, q_max=90, q_min=10):
X = self.raw_frame.copy()
"""rows that we are looking for (every x_value)"""
x_set = np.unique(X['x_value'].values) # get an array of unique values of x
glob_samp, glob_h_mi, glob_h_ma = self.__define_heat_sample_on(x_set, info=False, plot=False, q_max=q_max,
q_min=q_min)
return glob_samp
def clean_up(self):

@@ -778,3 +864,3 @@ """

def __define_heat_sample_on(self, xx, info, plot, q_max=80, q_min=20):
def __define_heat_sample_on(self, xx, info, plot, q_max=90, q_min=10):

@@ -883,5 +969,5 @@ xx = xx if isinstance(xx, Iterable) else [xx, ]

def __find_min_max_y_on_(self, x, heat_sample):
def __find_min_max_y_on_(self, x, heat_sample, wrong_y=None):
n_steps = int(0.04 * len(self.y_list))
n_steps = self.__n_steps

@@ -897,2 +983,6 @@ if len(self.raw_frame[self.raw_frame.x_value == x].y_value) <= 0.7 * len(self.y_list):

if wrong_y is not None:
mask = (smooth_y > wrong_y - n_steps * self.y_step) & (smooth_y < wrong_y + n_steps * self.y_step)
smooth_heat[mask] = self.check_heat_samp(q_max=70, q_min=35)
idx = list(smooth_heat).index(self.__find_nearest_universal(smooth_heat, heat_sample))

@@ -906,3 +996,3 @@ y_min = smooth_y[idx] - n_steps * self.y_step

stdev = np.std(self.heat_samples)
#print(stats.mode(self.heat_samples))
# print(stats.mode(self.heat_samples))
mode = np.percentile(self.heat_samples, 50)

@@ -909,0 +999,0 @@

@@ -20,3 +20,8 @@ """

def _save_path(data: str, qubit_name: str = 'qubit_default_name',
default_path: str = 'D:/Scripts/Measurement_automation/data/qubits/'):
default_path: str = 'D:/Scripts/Measurement_automation/data/qubits/',
spectroscopy_type: str = 'tts'):
if spectroscopy_type == 'tts':
spectroscopy = 'two_tone_spectroscopy'
else:
spectroscopy = 'single_tone_spectroscopy'

@@ -28,3 +33,3 @@ current_date = str(date.today())

dir_date = os.path.join(dir_qubit, current_date)
dir_tts = os.path.join(dir_date, 'two_tone_spectroscopy')
dir_tts = os.path.join(dir_date, spectroscopy)

@@ -76,10 +81,10 @@ if os.path.exists(parent_dir):

logo: bool = False,
logo_local=False,
logo_local=None,
y_logo_pos: float = 1.09,
save_png: str = None,
save_svg: str = None,
x_logo_pos: float = 1,
logo_size: float = 0.09,
qubit_number: Union[str, float] = None,
exponent_mode = False,
width = 700,
height = 600
exponent_mode=False,
width=700,
height=600
):

@@ -121,5 +126,15 @@

:param x_axis_title: (Optional) Sets the title of this axis. Default - 'Currents, A'
:param x_axis_size: size of x axis font
:param y_axis_title: (Optional) Sets the title of this axis. Default - 'Frequencies, Hz'
:param y_axis_size: size of y axis font
:param colorbar_text: (Optional) Sets the title of color bar. Default - None
:param logo: (Optional) If True - shows the FMN logo at the upper right corner. Default - True
:param logo_local: (Optional) If not None - puts <filename> file as a logo
:param y_logo_pos: sets y logo position
:param x_logo_pos: sets x logo position
:param logo_size: logo scale parameter
:param qubit_number: qubit information
:param exponent_mode: if False - ignore exponential formatting
:param width: the width of the plot (in pixels)
:param height: the height of the plot (in pixels)
:return:

@@ -203,3 +218,3 @@ """

fig.update_traces(zhoverformat='.2f')
#fig.update_layout(xaxis=dict(showexponent='none', exponentformat='e'))
# fig.update_layout(xaxis=dict(showexponent='none', exponentformat='e'))
else:

@@ -221,5 +236,5 @@ fig.update_layout(yaxis_tickformat='.2e', xaxis_tickformat='.2e')

xref="paper", yref="paper",
x=1, y=y_logo_pos,
sizex=0.09,
sizey=0.09,
x=x_logo_pos, y=y_logo_pos,
sizex=logo_size,
sizey=logo_size,
xanchor="right", yanchor="bottom",

@@ -231,3 +246,3 @@ opacity=1,

if logo_local:
if logo_local is not None:
img = Image.open('logo_sign.png')

@@ -238,5 +253,5 @@ fig.add_layout_image(

xref="paper", yref="paper",
x=1, y=y_logo_pos,
sizex=0.09,
sizey=0.09,
x=x_logo_pos, y=y_logo_pos,
sizex=logo_size,
sizey=logo_size,
xanchor="right", yanchor="bottom",

@@ -254,8 +269,2 @@ opacity=1,

if save_png is not None:
fig.write_image(save_png)
if save_svg is not None:
fig.write_image(save_svg)
return fig

@@ -277,2 +286,4 @@

y_logo_pos: float = 1.09,
x_logo_pos: float = 1,
logo_size: float = 0.09,
qubit_number: Union[str, float] = None,

@@ -403,5 +414,5 @@ exponent_mode=False,

xref="paper", yref="paper",
x=1, y=y_logo_pos,
sizex=0.09,
sizey=0.09,
x=x_logo_pos, y=y_logo_pos,
sizex=logo_size,
sizey=logo_size,
xanchor="right", yanchor="bottom",

@@ -419,5 +430,5 @@ opacity=1,

xref="paper", yref="paper",
x=1, y=y_logo_pos,
sizex=0.09,
sizey=0.09,
x=x_logo_pos, y=y_logo_pos,
sizex=logo_size,
sizey=logo_size,
xanchor="right", yanchor="bottom",

@@ -475,11 +486,35 @@ opacity=1,

@classmethod
def configure_app(cls, data, fig, mode='inline', port=8051, interval=4e3, qubit_id=None, chip_id=None):
cls.fig = fig
cls.mode = mode
cls.interval = interval
cls.port = port
cls.chip_id = chip_id
cls.qubit_id = qubit_id
def __init__(self, data, fig, qubit_id=None, chip_id=None, additional_info: str = '', spectroscopy_type='tts'):
"""
:param data: entity of Tts | Sts or TwoToneSpectroscopy class
:param fig: displayed figure
:param qubit_id: id of qubit
:param chip_id: id of chip
:param spectroscopy_type: tts or sts
"""
self.data = data
self.fig = fig
self.qubit_id = qubit_id
self.chip_id = chip_id
self.additional_info = '_' + additional_info + '_'
self.spectroscopy_type = spectroscopy_type
self._ts = 'TTS_' if self.spectroscopy_type == 'tts' else 'STS_'
def __middle_name(self, time):
return 'q' + str(self.qubit_id) + self.additional_info + str(
time) if self.qubit_id is not None else 'q' + '_untitled' + self.additional_info + str(time)
def configure_app(self, mode='inline', port=8051, interval=4e3):
"""
Configures Dashboard app
:param mode: 'inline', 'external'
:param port:
:param interval: default update time in ms
:return:
"""
self.mode = mode
self.interval = interval
self.port = port
disabled_btn = False

@@ -493,6 +528,7 @@ disabled_input = False

[
html.Button('Save CSV', id='btn-nclicks-1', n_clicks=0),
html.Button('Save PDF', id='btn-nclicks-2', n_clicks=0),
html.Button('Save HTML', id='btn-nclicks-3', n_clicks=0),
html.Button('Save SVG', id='btn-nclicks-5', n_clicks=0),
html.Button('raw CSV', id='btn-nclicks-1', n_clicks=0),
html.Button('CSV', id='btn-nclicks-6', n_clicks=0),
html.Button('PDF', id='btn-nclicks-2', n_clicks=0),
html.Button('HTML', id='btn-nclicks-3', n_clicks=0),
html.Button('SVG', id='btn-nclicks-5', n_clicks=0),
dcc.Checklist(id='checkbox',

@@ -510,4 +546,4 @@ options=[{'label': 'stop live upd', 'value': 'NO'}],

),
dcc.Graph(id="heatmap", figure=cls.fig),
dcc.Interval(id="animateInterval", interval=cls.interval, n_intervals=0,
dcc.Graph(id="heatmap", figure=self.fig),
dcc.Interval(id="animateInterval", interval=self.interval, n_intervals=0,
max_intervals=maxx_interval),

@@ -524,2 +560,3 @@ ],

Input('btn-nclicks-1', 'n_clicks'),
Input('btn-nclicks-6', 'n_clicks'),
Input('btn-nclicks-2', 'n_clicks'),

@@ -533,3 +570,3 @@ Input('btn-nclicks-3', 'n_clicks'),

)
def doUpdate(btn1, btn2, btn3, btn5, chkbx, btn4, time_val, i):
def doUpdate(btn1, btn6, btn2, btn3, btn5, chkbx, btn4, time_val, i):

@@ -546,33 +583,34 @@ if chkbx[-1] == 'NO':

changed_id = [p['prop_id'] for p in callback_context.triggered][0]
# self.middle_name = 'q' + str(self.qubit_id) + self.additional_info + str(datetime.now().strftime("_%H-%M-%S")) if self.qubit_id is not None else 'q' + '_untitled' + self.additional_info + str(datetime.now().strftime("_%H-%M-%S"))
# CSV
if 'btn-nclicks-1' in changed_id:
file_name = (self._ts + 'raw_' + self.__middle_name(datetime.now().strftime("_%H-%M-%S")) + '.csv')
self.data.get_result().to_csv(
_save_path(file_name, self.chip_id, spectroscopy_type=self.spectroscopy_type), index=False)
file_name = ('TTS_' + 'q' + str(cls.qubit_id) + str(datetime.now().strftime(
"_%H-%M-%S")) + '.csv' if cls.qubit_id is not None else 'TTS_' + 'q' + '_untitled_' + str(
datetime.now().strftime("_%H-%M-%S")) + '.csv')
# CSV FORMATTED
elif 'btn-nclicks-6' in changed_id:
file_name = (self._ts + self.__middle_name(datetime.now().strftime("_%H-%M-%S")) + '.csv')
self.data.get_raw_result().to_csv(
_save_path(file_name, self.chip_id, spectroscopy_type=self.spectroscopy_type), index=False)
data.get_result().to_csv(_save_path(file_name, cls.chip_id), index=False)
# PDF
elif 'btn-nclicks-2' in changed_id:
file_name = (self._ts + self.__middle_name(datetime.now().strftime("_%H-%M-%S")) + '.pdf')
fig.write_image(_save_path(file_name, self.chip_id, spectroscopy_type=self.spectroscopy_type))
file_name = ('TTS_'+'q'+str(cls.qubit_id)+str(datetime.now().strftime(
"_%H-%M-%S"))+'.pdf' if cls.qubit_id is not None else 'TTS_'+'q'+'_untitled_'+str(
datetime.now().strftime("_%H-%M-%S"))+'.pdf')
fig.write_image(_save_path(file_name, cls.chip_id))
# HTML
elif 'btn-nclicks-3' in changed_id:
file_name = (self._ts + self.__middle_name(datetime.now().strftime("_%H-%M-%S")) + '.html')
fig.write_html(_save_path(file_name, self.chip_id, spectroscopy_type=self.spectroscopy_type))
file_name = ('TTS_' + 'q' + str(cls.qubit_id) + str(datetime.now().strftime(
"_%H-%M-%S")) + '.html' if cls.qubit_id is not None else 'TTS_' + 'q' + '_untitled_' + str(
datetime.now().strftime("_%H-%M-%S")) + '.html')
fig.write_html(_save_path(file_name, cls.chip_id))
# SVG
elif 'btn-nclicks-5' in changed_id:
file_name = (self._ts + self.__middle_name(datetime.now().strftime("_%H-%M-%S")) + '.svg')
fig.write_image(_save_path(file_name, self.chip_id, spectroscopy_type=self.spectroscopy_type))
file_name = ('TTS_' + 'q' + str(cls.qubit_id) + str(datetime.now().strftime(
"_%H-%M-%S")) + '.svg' if cls.qubit_id is not None else 'TTS_' + 'q' + '_untitled_' + str(
datetime.now().strftime("_%H-%M-%S")) + '.svg')
fig.write_image(_save_path(file_name, cls.chip_id))
elif 'btn-nclicks-4' in changed_id:
z = data.njit_result
z = self.data.njit_result
fig.update_traces(z=z)

@@ -583,39 +621,618 @@ else:

if time_val:
cls.interval = time_val
self.interval = time_val
z = data.njit_result
z = self.data.njit_result
return cls.fig.update_traces(z=z), maxx_interval, cls.interval, disabled_btn, disabled_input
return self.fig.update_traces(z=z), maxx_interval, self.interval, disabled_btn, disabled_input
return app.run_server(mode=cls.mode, port=cls.port)
return app.run_server(mode=self.mode, port=self.port)
@classmethod
def save_all(cls, data, fig,
def save_all(self,
*, csv=True, pdf=True, html=True, svg=True):
"""
Saves data in different formats
:param csv: if true - saves csv
:param pdf: if true - saves pdf
:param html: if true - saves html
:param svg: if true - saves svg
:return:
"""
# CSV
file_name = ('TTS_' + 'q' + str(cls.qubit_id) + str(datetime.now().strftime(
"_%H-%M-%S")) + '.csv' if cls.qubit_id is not None else 'TTS_' + 'q' + '_untitled_' + str(
datetime.now().strftime("_%H-%M-%S")) + '.csv')
if csv:
file_name = (self._ts + 'raw_' + self.__middle_name(datetime.now().strftime("_%H-%M-%S")) + '.csv')
data.get_result().to_csv(_save_path(file_name, cls.chip_id), index=False)
self.data.get_result().to_csv(_save_path(file_name, self.chip_id, spectroscopy_type=self.spectroscopy_type),
index=False)
# CSV FORMATTED
if csv:
file_name = (self._ts + self.__middle_name(datetime.now().strftime("_%H-%M-%S")) + '.csv')
self.data.get_raw_result().to_csv(
_save_path(file_name, self.chip_id, spectroscopy_type=self.spectroscopy_type), index=False)
# PDF
file_name = ('TTS_' + 'q' + str(cls.qubit_id) + str(datetime.now().strftime(
"_%H-%M-%S")) + '.pdf' if cls.qubit_id is not None else 'TTS_' + 'q' + '_untitled_' + str(
datetime.now().strftime("_%H-%M-%S")) + '.pdf')
if pdf:
file_name = (self._ts + self.__middle_name(datetime.now().strftime("_%H-%M-%S")) + '.pdf')
fig.write_image(_save_path(file_name, self.chip_id, spectroscopy_type=self.spectroscopy_type))
fig.write_image(_save_path(file_name, cls.chip_id))
# HTML
file_name = ('TTS_' + 'q' + str(cls.qubit_id) + str(datetime.now().strftime(
"_%H-%M-%S")) + '.html' if cls.qubit_id is not None else 'TTS_' + 'q' + '_untitled_' + str(
datetime.now().strftime("_%H-%M-%S")) + '.html')
if html:
file_name = (self._ts + self.__middle_name(datetime.now().strftime("_%H-%M-%S")) + '.html')
fig.write_html(_save_path(file_name, self.chip_id, spectroscopy_type=self.spectroscopy_type))
fig.write_html(_save_path(file_name, cls.chip_id))
# SVG
file_name = ('TTS_' + 'q' + str(cls.qubit_id) + str(datetime.now().strftime(
"_%H-%M-%S")) + '.svg' if cls.qubit_id is not None else 'TTS_' + 'q' + '_untitled_' + str(
datetime.now().strftime("_%H-%M-%S")) + '.svg')
if svg:
file_name = (self._ts + self.__middle_name(datetime.now().strftime("_%H-%M-%S")) + '.svg')
fig.write_image(_save_path(file_name, self.chip_id, spectroscopy_type=self.spectroscopy_type))
fig.write_image(_save_path(file_name, cls.chip_id))
class Dash_app_2Q:
def __init__(self, *,
data11, data12, data13,
data21, data22, data23,
fig11, fig12, fig13,
fig21, fig22, fig23,
Q1_id=None, Q2_id=None, Coupler_id=None,
chip_id=None,
check=False,
additional_info: str = '', spectroscopy_type='sts'
):
self.data11, self.data12, self.data13 = data11, data12, data13
self.data21, self.data22, self.data23 = data21, data22, data23
self.data_zoo = np.array([self.data11, self.data12, self.data12,
self.data21, self.data22, self.data23])
self.main_data = self.data11
self.picked_data = None
self.fig11, self.fig12, self.fig13 = fig11, fig12, fig13
self.fig21, self.fig22, self.fig23 = fig21, fig22, fig23
self.fig_zoo = np.array([self.fig11, self.fig12, self.fig12,
self.fig21, self.fig22, self.fig23])
self.main_fig = self.fig11
self.picked_fig = None
self.Q1_id, self.Q2_id, self.Coupler_id = Q1_id, Q2_id, Coupler_id
self.chip_id = chip_id
self.additional_info = '_' + additional_info + '_'
self.spectroscopy_type = spectroscopy_type
self._ts = 'STS_' if self.spectroscopy_type == 'sts' else 'TTS_'
self.check = check
self.__dict_of_data = dict(fig11=self.data11, fig12=self.data12, fig13=self.data13,
fig21=self.data21, fig22=self.data22, fig23=self.data23)
self.__dict_of_figs = dict(fig11=self.fig11, fig12=self.fig12, fig13=self.fig13,
fig21=self.fig21, fig22=self.fig22, fig23=self.fig23)
pass
def __middle_name(self, time, data):
if self.check == False:
mid_name = (data.readout_qubit + '_' + self.__get_id(
data.readout_qubit.upper()) + '_' + data.flux_qubit + '_ '
+ self.__get_id(data.flux_qubit.upper()) + '_' + self.additional_info + str(time))
else:
mid_name = ('check_' + data.readout_qubit + '_' + self.__get_id(data.readout_qubit.upper()) + '_'
+ data.flux_qubit + '_ '
+ self.__get_id(data.flux_qubit.upper()) + '_' + self.additional_info + str(time))
return mid_name
def __get_id(self, qubit):
if qubit == 'Q1':
qid = self.Q1_id
elif qubit == 'Q2':
qid = self.Q2_id
elif qubit == 'Coupler':
qid = self.Coupler_id
else:
qid = 'Nan'
return str(qid)
def configure_app(self, mode='external', port=8051, interval=4e3):
"""
Configures Dashboard app
:param mode: 'inline', 'external'
:param port:
:param interval: default update time in ms
:return:
"""
self.mode = mode
self.interval = interval
self.port = port
disabled_btn = False
disabled_input = False
maxx_interval = -1
# Build App
app = JupyterDash(__name__)
app.layout = html.Div(
[
html.Button('raw CSV', id='btn-nclicks-1', n_clicks=0),
html.Button('CSV', id='btn-nclicks-6', n_clicks=0),
html.Button('PDF', id='btn-nclicks-2', n_clicks=0),
html.Button('HTML', id='btn-nclicks-3', n_clicks=0),
html.Button('SVG', id='btn-nclicks-5', n_clicks=0),
dcc.Dropdown(options=['fig11', 'fig12', 'fig13',
'fig21', 'fig22', 'fig23'], value='fig11', id='fig-dropdown'),
dcc.Checklist(id='checkbox',
options=[{'label': 'stop live upd', 'value': 'NO'}],
value=['YES', 'NO'],
labelStyle={'display': 'inline-block'}
),
html.Button('Manual upd', id='btn-nclicks-4', n_clicks=0),
dcc.Input(
id="input_time",
type='number',
placeholder="Auto upd in, ms",
min=800,
),
dcc.Graph(id="heatmap11", figure=self.fig11), dcc.Graph(id="heatmap12", figure=self.fig12),
dcc.Graph(id="heatmap13", figure=self.fig13), dcc.Graph(id="heatmap21", figure=self.fig21),
dcc.Graph(id="heatmap22", figure=self.fig22), dcc.Graph(id="heatmap23", figure=self.fig23),
dcc.Interval(id="animateInterval", interval=self.interval, n_intervals=0,
max_intervals=maxx_interval),
],
)
@app.callback(
Output("heatmap11", "figure"), Output("heatmap12", "figure"), Output("heatmap13", "figure"),
Output("heatmap21", "figure"), Output("heatmap22", "figure"), Output("heatmap23", "figure"),
Output("animateInterval", "max_intervals"),
Output("animateInterval", "interval"),
Output('btn-nclicks-4', 'disabled'),
Output('input_time', 'disabled'),
Input('btn-nclicks-1', 'n_clicks'),
Input('btn-nclicks-6', 'n_clicks'),
Input('btn-nclicks-2', 'n_clicks'),
Input('btn-nclicks-3', 'n_clicks'),
Input('btn-nclicks-5', 'n_clicks'),
Input('fig-dropdown', 'value'),
Input('checkbox', 'value'),
Input('btn-nclicks-4', 'n_clicks'),
Input('input_time', 'value'),
Input("animateInterval", "n_intervals"),
)
def doUpdate(btn1, btn6, btn2, btn3, btn5, fig_dropd_value, chkbx, btn4, time_val, i):
active = np.array([self.data11.active, self.data12.active, self.data12.active,
self.data21.active, self.data22.active, self.data23.active])
self.picked_data = self.data_zoo[active][0] if len(self.data_zoo[active]) == 1 else self.main_data
self.picked_fig = self.fig_zoo[active][0] if len(self.fig_zoo[active]) == 1 else self.main_fig
data_for_save = self.__dict_of_data[fig_dropd_value]
fig_for_save = self.__dict_of_figs[fig_dropd_value]
if chkbx[-1] == 'NO':
maxx_interval = 0
disabled_btn = False
disabled_input = False
else:
maxx_interval = -1
disabled_btn = True
disabled_input = True
changed_id = [p['prop_id'] for p in callback_context.triggered][0]
# CSV
if 'btn-nclicks-1' in changed_id:
file_name = (self._ts + 'raw_' + self.__middle_name(datetime.now().strftime("_%H-%M-%S"),
data_for_save) + '.csv')
data_for_save.get_result().to_csv(
_save_path(file_name, self.chip_id, spectroscopy_type=self.spectroscopy_type), index=False)
# CSV FORMATTED
elif 'btn-nclicks-6' in changed_id:
file_name = (
self._ts + self.__middle_name(datetime.now().strftime("_%H-%M-%S"), data_for_save) + '.csv')
data_for_save.get_raw_result().to_csv(
_save_path(file_name, self.chip_id, spectroscopy_type=self.spectroscopy_type), index=False)
# PDF
elif 'btn-nclicks-2' in changed_id:
file_name = (
self._ts + self.__middle_name(datetime.now().strftime("_%H-%M-%S"), data_for_save) + '.pdf')
fig_for_save.write_image(_save_path(file_name, self.chip_id, spectroscopy_type=self.spectroscopy_type))
# HTML
elif 'btn-nclicks-3' in changed_id:
file_name = (self._ts + self.__middle_name(datetime.now().strftime("_%H-%M-%S"),
data_for_save) + '.html')
fig_for_save.write_html(_save_path(file_name, self.chip_id, spectroscopy_type=self.spectroscopy_type))
# SVG
elif 'btn-nclicks-5' in changed_id:
file_name = (
self._ts + self.__middle_name(datetime.now().strftime("_%H-%M-%S"), data_for_save) + '.svg')
fig_for_save.write_image(_save_path(file_name, self.chip_id, spectroscopy_type=self.spectroscopy_type))
if time_val:
self.interval = time_val
z = self.picked_data.njit_result
return self.picked_fig.update_traces(z=z), maxx_interval, self.interval, disabled_btn, disabled_input
return app.run_server(mode=self.mode, port=self.port)
class Dash_app_2Q_base:
def __init__(self, *,
data1,
fig,
data2=None, data3=None,
data4=None, data5=None, data6=None,
Q1_id=None, Q2_id=None, Coupler_id=None,
chip_id=None,
check=False,
additional_info: str = '', spectroscopy_type='sts'
):
self.data11, self.data12, self.data13 = data1, data2, data3
self.data21, self.data22, self.data23 = data4, data5, data6
self.data_zoo = np.array([self.data11, self.data12, self.data13,
self.data21, self.data22, self.data23])
'block for dropdown menu'
none_count = 0
for data in self.data_zoo:
if data is None:
none_count += 1
self.existing_data = self.data_zoo[:-none_count]
self.disabled_drpdwn = False if none_count < 5 else True
self.data_zoo_names = []
data_zoo_names_temp = np.array([self.get_label_name(d) for d in self.data_zoo[:-none_count]]) if none_count > 0 \
else np.array([self.get_label_name(d) for d in self.data_zoo])
for name in data_zoo_names_temp:
self.data_zoo_names.append(name)
while len(self.data_zoo_names) < len(self.data_zoo):
self.data_zoo_names.append('undefined')
'end of block for dropdown menu'
self.data_zoo_names = np.array(self.data_zoo_names)
self.disabled_markers = []
for name in self.data_zoo_names:
if name == 'undefined':
self.disabled_markers.append(True)
else:
self.disabled_markers.append(False)
self.fig_zoo = {
self.data_zoo_names[0]: 0, self.data_zoo_names[1]: 1, self.data_zoo_names[2]: 2,
self.data_zoo_names[3]: 3, self.data_zoo_names[4]: 4, self.data_zoo_names[5]: 5,
}
self.main_data = self.data11
self.picked_data = None
self.fig = fig
self.Q1_id, self.Q2_id, self.Coupler_id = Q1_id, Q2_id, Coupler_id
self.chip_id = chip_id
self.additional_info = '_' + additional_info + '_'
self.spectroscopy_type = spectroscopy_type
self._ts = 'STS_' if self.spectroscopy_type == 'sts' else 'TTS_'
self.check = check
self.__dict_of_data = dict(fig11=self.data11, fig12=self.data12, fig13=self.data13,
fig21=self.data21, fig22=self.data22, fig23=self.data23)
pass
def __middle_name(self, time, data):
if not self.check:
mid_name = (data.readout_qubit + '_' + data.flux_qubit + '_'
+ 'sweep' + self.additional_info + str(time))
else:
mid_name = ('check_' + data.readout_qubit + '_' + data.flux_qubit + '_'
+ 'sweep' + self.additional_info + str(time))
return mid_name
def __get_id(self, qubit):
if qubit == 'Q1':
qid = self.Q1_id
elif qubit == 'Q2':
qid = self.Q2_id
elif qubit == 'Coupler':
qid = self.Coupler_id
else:
qid = 'Nan'
return str(qid)
def get_label_name(self, data):
readout = data.readout_qubit
flux = data.flux_qubit
if isinstance(flux, str):
return str(readout) + '_' + str(flux) + '_sweep'
else:
global_str = str(readout) + '_'
for f in flux:
global_str += str(f) + '+'
global_str = global_str[:-1]
global_str += '_sweep'
return global_str
def configure_app(self, mode='inline', port=8051, interval=4e3):
"""
Configures Dashboard app
:param mode: 'inline', 'external'
:param port:
:param interval: default update time in ms
:return:
"""
self.mode = mode
self.interval = interval
self.port = port
disabled_btn = False
disabled_input = False
maxx_interval = -1
# Build App
app = JupyterDash(__name__)
app.layout = html.Div(
[
html.Button('raw CSV', id='btn-nclicks-1', n_clicks=0),
html.Button('CSV', id='btn-nclicks-6', n_clicks=0),
html.Button('PDF', id='btn-nclicks-2', n_clicks=0),
html.Button('HTML', id='btn-nclicks-3', n_clicks=0),
html.Button('SVG', id='btn-nclicks-5', n_clicks=0),
dcc.Dropdown(
options=[{'label': value, 'value': value, 'disabled': disabl} for value, disabl in
zip(self.data_zoo_names, self.disabled_markers)],
value=self.get_label_name(self.data11), id='fig-dropdown',
disabled=self.disabled_drpdwn,
clearable=False
),
dcc.Checklist(id='checkbox',
options=[{'label': 'stop live upd', 'value': 'NO'}],
value=['YES', 'NO'],
labelStyle={'display': 'inline-block'}
),
html.Button('Manual upd', id='btn-nclicks-4', n_clicks=0),
dcc.Input(
id="input_time",
type='number',
placeholder="Auto upd in, ms",
min=800,
),
dcc.Graph(id="heatmap", figure=self.fig),
dcc.Interval(id="animateInterval", interval=self.interval, n_intervals=0,
max_intervals=maxx_interval),
],
)
@app.callback(
Output("heatmap", "figure"),
Output("animateInterval", "max_intervals"),
Output("animateInterval", "interval"),
Output('btn-nclicks-4', 'disabled'),
Output('input_time', 'disabled'),
Input('btn-nclicks-1', 'n_clicks'),
Input('btn-nclicks-6', 'n_clicks'),
Input('btn-nclicks-2', 'n_clicks'),
Input('btn-nclicks-3', 'n_clicks'),
Input('btn-nclicks-5', 'n_clicks'),
Input('fig-dropdown', 'value'),
Input('checkbox', 'value'),
Input('btn-nclicks-4', 'n_clicks'),
Input('input_time', 'value'),
Input("animateInterval", "n_intervals"),
)
def doUpdate(btn1, btn6, btn2, btn3, btn5, fig_dropd_value, chkbx, btn4, time_val, i):
self.picked_data = self.data_zoo[
self.fig_zoo[fig_dropd_value]] if self.disabled_drpdwn is False else self.data11
if chkbx[-1] == 'NO':
maxx_interval = 0
disabled_btn = False
disabled_input = False
else:
maxx_interval = -1
disabled_btn = True
disabled_input = True
changed_id = [p['prop_id'] for p in callback_context.triggered][0]
# CSV
if 'btn-nclicks-1' in changed_id:
file_name = (self._ts + 'raw_' + self.__middle_name(datetime.now().strftime("_%H-%M-%S"),
self.picked_data) + '.csv')
self.picked_data.get_result().to_csv(
_save_path(file_name, self.chip_id, spectroscopy_type=self.spectroscopy_type), index=False)
# CSV FORMATTED
elif 'btn-nclicks-6' in changed_id:
file_name = (
self._ts + self.__middle_name(datetime.now().strftime("_%H-%M-%S"), self.picked_data) + '.csv')
self.picked_data.get_raw_result().to_csv(
_save_path(file_name, self.chip_id, spectroscopy_type=self.spectroscopy_type), index=False)
# PDF
elif 'btn-nclicks-2' in changed_id:
file_name = (
self._ts + self.__middle_name(datetime.now().strftime("_%H-%M-%S"), self.picked_data) + '.pdf')
self.fig.write_image(_save_path(file_name, self.chip_id, spectroscopy_type=self.spectroscopy_type))
# HTML
elif 'btn-nclicks-3' in changed_id:
file_name = (self._ts + self.__middle_name(datetime.now().strftime("_%H-%M-%S"),
self.picked_data) + '.html')
self.fig.write_html(_save_path(file_name, self.chip_id, spectroscopy_type=self.spectroscopy_type))
# SVG
elif 'btn-nclicks-5' in changed_id:
file_name = (
self._ts + self.__middle_name(datetime.now().strftime("_%H-%M-%S"), self.picked_data) + '.svg')
self.fig.write_image(_save_path(file_name, self.chip_id, spectroscopy_type=self.spectroscopy_type))
if time_val:
self.interval = time_val
z = self.picked_data.njit_result
x = self.picked_data.x_1d
y = self.picked_data.y_1d
return self.fig.update_traces(z=z, x=x, y=y), maxx_interval, self.interval, disabled_btn, disabled_input
return app.run_server(mode=self.mode, port=self.port)
def save_all(self):
for data in self.existing_data:
# CSV
file_name = (self._ts + 'raw_' + self.__middle_name(datetime.now().strftime("_%H-%M-%S"),
data) + '.csv')
self.picked_data.get_result().to_csv(
_save_path(file_name, self.chip_id, spectroscopy_type=self.spectroscopy_type), index=False)
# CSV FORMATTED
file_name = (
self._ts + self.__middle_name(datetime.now().strftime("_%H-%M-%S"), data) + '.csv')
self.picked_data.get_raw_result().to_csv(
_save_path(file_name, self.chip_id, spectroscopy_type=self.spectroscopy_type), index=False)
# PDF
file_name = (
self._ts + self.__middle_name(datetime.now().strftime("_%H-%M-%S"), data) + '.pdf')
self.fig.write_image(_save_path(file_name, self.chip_id, spectroscopy_type=self.spectroscopy_type))
# HTML
file_name = (self._ts + self.__middle_name(datetime.now().strftime("_%H-%M-%S"),
data) + '.html')
self.fig.write_html(_save_path(file_name, self.chip_id, spectroscopy_type=self.spectroscopy_type))
# SVG
file_name = (
self._ts + self.__middle_name(datetime.now().strftime("_%H-%M-%S"), data) + '.svg')
self.fig.write_image(_save_path(file_name, self.chip_id, spectroscopy_type=self.spectroscopy_type))
class Dash_app_2Q1111:
def __init__(self, *,
data11, data12, data13,
data21, data22, data23,
fig11, fig12, fig13,
fig21, fig22, fig23,
Q1_id=None, Q2_id=None, Coupler_id=None,
chip_id=None,
check=False,
additional_info: str = '', spectroscopy_type='sts'
):
self.data11, self.data12, self.data13 = data11, data12, data13
self.data21, self.data22, self.data23 = data21, data22, data23
self.fig11, self.fig12, self.fig13 = fig11, fig12, fig13
self.fig21, self.fig22, self.fig23 = fig21, fig22, fig23
self.Q1_id, self.Q2_id, self.Coupler_id = Q1_id, Q2_id, Coupler_id
self.chip_id = chip_id
self.additional_info = '_' + additional_info + '_'
self.spectroscopy_type = spectroscopy_type
self._ts = 'STS_' if self.spectroscopy_type == 'sts' else 'TTS_'
self.check = check
pass
def configure_app(self, mode='external', port=8051, interval=4e3):
"""
Configures Dashboard app
:param mode: 'inline', 'external'
:param port:
:param interval: default update time in ms
:return:
"""
self.mode = mode
self.interval = interval
self.port = port
external_stylesheets = [
# Dash CSS
'https://codepen.io/chriddyp/pen/bWLwgP.css',
# Loading screen CSS
'https://codepen.io/chriddyp/pen/brPBPO.css']
app = JupyterDash(__name__, external_stylesheets=external_stylesheets)
server = app.server
CACHE_CONFIG = {
# try 'FileSystemCache' if you don't want to setup redis
'CACHE_TYPE': 'redis',
'CACHE_REDIS_URL': os.environ.get('REDIS_URL', 'redis://localhost:6379')
}
cache = Cache()
cache.init_app(app.server, config=CACHE_CONFIG)
app.layout = html.Div([
html.Div([
html.Div(dcc.Graph(id='heatmap11', figure=self.fig11), className="six columns"),
html.Div(dcc.Graph(id='heatmap12', figure=self.fig12), className="six columns"),
html.Div(dcc.Graph(id='heatmap13', figure=self.fig13), className="six columns"),
], className="row"),
html.Div([
html.Div(dcc.Graph(id='heatmap21', figure=self.fig21), className="six columns"),
html.Div(dcc.Graph(id='heatmap22', figure=self.fig22), className="six columns"),
html.Div(dcc.Graph(id='heatmap23', figure=self.fig23), className="six columns"),
], className="row"),
# signal value to trigger callbacks
dcc.Store(id='signal'),
dcc.Interval(id="animateInterval", interval=self.interval, n_intervals=0)
])
# perform expensive computations in this "global store"
# these computations are cached in a globally available
# redis memory store which is available across processes
# and for all time.
@cache.memoize()
def global_store():
z11 = self.data11.njit_result
z12 = self.data12.njit_result
z13 = self.data13.njit_result
z21 = self.data21.njit_result
z22 = self.data22.njit_result
z23 = self.data23.njit_result
return z11, z12, z13, z21, z22, z23
@app.callback(Output('signal', 'data'), Input("animateInterval", "n_intervals"))
def compute_value(i):
# compute value and send a signal when done
global_store()
return value

@@ -45,3 +45,2 @@ import zhinst

:param ny_points: y count value (int)
:param fr_min: min frequency for find resonator

@@ -48,0 +47,0 @@ :param fr_max: max frequency for find resonator

@@ -11,3 +11,3 @@ from setuptools import setup, find_packages

name='pyquac',
version='1.1.9',
version='1.1.11',
description='Useful tools for quantum computing experiments, provided for BMSTU FMN',

@@ -14,0 +14,0 @@ long_description_content_type="text/markdown",