Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/jkochNU/qfit
Browse files Browse the repository at this point in the history
  • Loading branch information
Harrinive committed Mar 4, 2024
2 parents 689ee59 + 7130543 commit 8735108
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 64 deletions.
20 changes: 14 additions & 6 deletions QFit_Quick_Start.ipynb

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions qfit/core/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,22 +337,22 @@ def calibrationMVCInits(self):
"""
# ui grouping
self.rawLineEdits = {
"X0": self.ui.rawX1LineEdit,
"X1": self.ui.rawX2LineEdit,
"Y0": self.ui.rawY1LineEdit,
"Y1": self.ui.rawY2LineEdit,
"X1": self.ui.rawX1LineEdit,
"X2": self.ui.rawX2LineEdit,
"Y1": self.ui.rawY1LineEdit,
"Y2": self.ui.rawY2LineEdit,
}
self.mapLineEdits = {
"X0": self.ui.mapX1LineEdit,
"X1": self.ui.mapX2LineEdit,
"Y0": self.ui.mapY1LineEdit,
"Y1": self.ui.mapY2LineEdit,
"X1": self.ui.mapX1LineEdit,
"X2": self.ui.mapX2LineEdit,
"Y1": self.ui.mapY1LineEdit,
"Y2": self.ui.mapY2LineEdit,
}
self.calibrationButtons = {
"X0": self.ui.calibrateX1Button,
"X1": self.ui.calibrateX2Button,
"Y0": self.ui.calibrateY1Button,
"Y1": self.ui.calibrateY2Button,
"X1": self.ui.calibrateX1Button,
"X2": self.ui.calibrateX2Button,
"Y1": self.ui.calibrateY1Button,
"Y2": self.ui.calibrateY2Button,
}

self.caliParamModel = CaliParamModel()
Expand Down
56 changes: 26 additions & 30 deletions qfit/models/calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ class CaliParamModel(
yCaliUpdated = Signal(object, object)
updatePrefitModel = Signal(ParamAttr)
caliModelRawVecUpdatedForSwapXY = Signal()
# calibrationIsOn: Literal["CALI_X1", "CALI_X2", "CALI_Y1", "CALI_Y2", False]
# calibrationIsOn: Literal["CALI_X2", "CALI_X2", "CALI_Y2", "CALI_Y2", False]

isFullCalibration: bool
caliTableXRowNr: int
caliTableXRowIdxList: List[str]
caliTableYRowIdxList: List[str] = ["Y0", "Y1"]
caliTableYRowIdxList: List[str] = ["Y1", "Y2"]
xRowIdxBySourceDict: Dict[str, List[str]] = {}

parameters: Dict[str, Dict[str, CaliTableRowParam]]
Expand All @@ -69,8 +69,8 @@ def __init__(
If insufficient number of figures are provided, the calibration is partial. In this case, the calibration
is done for each figure separately. Assume we have F figures, then for each figure, the relation between the
rawVecX and mapVecX is:
rawVecX = rawVecX1 + tX * (rawVecX2 - rawVecX1)
mapVecX = mapVecX1 + tX * (mapVecX2 - mapVecX1)
rawVecX = rawVecX2 + tX * (rawVecX2 - rawVecX2)
mapVecX = mapVecX2 + tX * (mapVecX2 - mapVecX2)
here the rawVecX is the voltage vector in a figure that one wants to calibrate, and mapVecX is the calibrated
vector. The tX is the parameter that determines the position of the rawVecX in the figure. The calibration
is done by providing 2 pairs of (rawVecX, mapVecX) data points for each figure.
Expand Down Expand Up @@ -143,7 +143,7 @@ def _isSufficientForFullCalibration(self, rawVecDim: int, figNr: int):
self.isFullCalibration = True
self.caliTableXRowNr = pointsRequired
self.caliTableXRowIdxList = [
f"X{XRowIdx}" for XRowIdx in range(self.caliTableXRowNr)
f"X{XRowIdx+1}" for XRowIdx in range(self.caliTableXRowNr)
]

def insertAllParams(self):
Expand Down Expand Up @@ -444,11 +444,11 @@ def _getYAlphaVec(self) -> np.ndarray:
augRawYMat = np.zeros((2, 2))
for YRowIdx in range(2):
augRawYMat[YRowIdx, 0] = 1
augRawYMat[YRowIdx, 1] = self[f"Y{YRowIdx}"][self.rawYName].value
augRawYMat[YRowIdx, 1] = self[f"Y{YRowIdx+1}"][self.rawYName].value
# gather all the point pair mapped value and solve alphaVec by inversion
mapCompVec = np.zeros(2)
for YRowIdx in range(2):
mapCompVec[YRowIdx] = self[f"Y{YRowIdx}"]["mappedY"].value
mapCompVec[YRowIdx] = self[f"Y{YRowIdx+1}"]["mappedY"].value
alphaVec = np.linalg.solve(augRawYMat, mapCompVec)
return alphaVec

Expand Down Expand Up @@ -754,35 +754,29 @@ def swapXYData(self):
# will send the signals after the swap is done
self.blockSignals(True)

oldX0RawValue = self.parameters["X0"][self.rawXVecNameList[0]].value
oldX1RawValue = self.parameters["X1"][self.rawXVecNameList[0]].value
oldX0MapValue = self.parameters["X0"][
oldX2RawValue = self.parameters["X2"][self.rawXVecNameList[0]].value
oldX1MapValue = self.parameters["X1"][
f"{self.sweepParamParentName}.{self.sweepParamName}"
].value
oldX1MapValue = self.parameters["X1"][
oldX2MapValue = self.parameters["X2"][
f"{self.sweepParamParentName}.{self.sweepParamName}"
].value
oldY0RawValue = self.parameters["Y0"][self.rawYName].value
oldY1RawValue = self.parameters["Y1"][self.rawYName].value
oldY0MapValue = self.parameters["Y0"]["mappedY"].value
oldY2RawValue = self.parameters["Y2"][self.rawYName].value
oldY1MapValue = self.parameters["Y1"]["mappedY"].value
self.setParameter(
rowIdx="X0",
colName=self.rawXVecNameList[0],
attr="value",
value=oldY0RawValue,
)
oldY2MapValue = self.parameters["Y2"]["mappedY"].value
self.setParameter(
rowIdx="X1",
colName=self.rawXVecNameList[0],
attr="value",
value=oldY1RawValue,
)
self.setParameter(
rowIdx="X0",
colName=f"{self.sweepParamParentName}.{self.sweepParamName}",
rowIdx="X2",
colName=self.rawXVecNameList[0],
attr="value",
value=oldY0MapValue,
value=oldY2RawValue,
)
self.setParameter(
rowIdx="X1",
Expand All @@ -791,17 +785,23 @@ def swapXYData(self):
value=oldY1MapValue,
)
self.setParameter(
rowIdx="Y0", colName=self.rawYName, attr="value", value=oldX0RawValue
rowIdx="X2",
colName=f"{self.sweepParamParentName}.{self.sweepParamName}",
attr="value",
value=oldY2MapValue,
)
self.setParameter(
rowIdx="Y1", colName=self.rawYName, attr="value", value=oldX1RawValue
)
self.setParameter(
rowIdx="Y0", colName="mappedY", attr="value", value=oldX0MapValue
rowIdx="Y2", colName=self.rawYName, attr="value", value=oldX2RawValue
)
self.setParameter(
rowIdx="Y1", colName="mappedY", attr="value", value=oldX1MapValue
)
self.setParameter(
rowIdx="Y2", colName="mappedY", attr="value", value=oldX2MapValue
)

self.blockSignals(False)

Expand Down Expand Up @@ -854,17 +854,13 @@ def emitUpdatePrefitModel(self):
if self._prefitHas(rowName, colName):
# update min, max, value for the prefit model
min, max = self._fitMinMaxByColName(rowName, colName)
self.updatePrefitModel.emit(
ParamAttr(rowName, colName, "min", min)
)
self.updatePrefitModel.emit(
ParamAttr(rowName, colName, "max", max)
)
self.updatePrefitModel.emit(ParamAttr(rowName, colName, "min", min))
self.updatePrefitModel.emit(ParamAttr(rowName, colName, "max", max))
self.updatePrefitModel.emit(
ParamAttr(
rowName,
colName,
"value",
param.value,
)
)
)
32 changes: 16 additions & 16 deletions qfit/views/calibration_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ def dynamicalInit(
self._generateCaliTableSet()

# need to be removed in the future
self.caliTableSet["X0"][self.rawXVecNameList[0]].setSibling(
self.caliTableSet["X1"][self.rawXVecNameList[0]]
self.caliTableSet["X1"][self.rawXVecNameList[0]].setSibling(
self.caliTableSet["X2"][self.rawXVecNameList[0]]
)
self.caliTableSet["Y0"][self.rawYName].setSibling(
self.caliTableSet["Y1"][self.rawYName]
self.caliTableSet["Y1"][self.rawYName].setSibling(
self.caliTableSet["Y2"][self.rawYName]
)

# connects
Expand All @@ -101,26 +101,26 @@ def _generateCaliTableSet(self):
if self.caliTableSet != {}:
self.caliTableSet.clear()
self.caliTableSet: Dict[str, Dict[str, "CalibrationLineEdit"]] = {
"X0": {
self.rawXVecNameList[0]: self.rawLineEdits["X0"],
f"{self.sweepParamParentName}.{self.sweepParamName}": self.mapLineEdits[
"X0"
],
},
"X1": {
self.rawXVecNameList[0]: self.rawLineEdits["X1"],
f"{self.sweepParamParentName}.{self.sweepParamName}": self.mapLineEdits[
"X1"
],
},
"Y0": {
self.rawYName: self.rawLineEdits["Y0"],
"mappedY": self.mapLineEdits["Y0"],
"X2": {
self.rawXVecNameList[0]: self.rawLineEdits["X2"],
f"{self.sweepParamParentName}.{self.sweepParamName}": self.mapLineEdits[
"X2"
],
},
"Y1": {
self.rawYName: self.rawLineEdits["Y1"],
"mappedY": self.mapLineEdits["Y1"],
},
"Y2": {
self.rawYName: self.rawLineEdits["Y2"],
"mappedY": self.mapLineEdits["Y2"],
},
}

def _generateRowIdxToButtonGroupIdDict(self):
Expand All @@ -132,9 +132,9 @@ def _generateRowIdxToButtonGroupIdDict(self):
"""
self.rowIdxToButtonGroupId: Dict[str, int] = {}
for rowIdx in range(self.caliTableXRowNr):
self.rowIdxToButtonGroupId[f"X{rowIdx}"] = rowIdx
self.rowIdxToButtonGroupId["Y0"] = self.caliTableXRowNr
self.rowIdxToButtonGroupId["Y1"] = self.caliTableXRowNr + 1
self.rowIdxToButtonGroupId[f"X{rowIdx+1}"] = rowIdx
self.rowIdxToButtonGroupId["Y1"] = self.caliTableXRowNr
self.rowIdxToButtonGroupId["Y2"] = self.caliTableXRowNr + 1

self.buttonGroupIdToRowIdx: Dict[int, str] = {
v: k for k, v in self.rowIdxToButtonGroupId.items()
Expand Down

0 comments on commit 8735108

Please sign in to comment.