Repository navigation
Sweeper speed - zhinst.toolkit about 3x slower than zhinst.core #297
|
Hello, Version info:
This simplified code using Expand zhinst.toolkit Codefrom zhinst.toolkit import Session
import numpy as np
import time
def _last_non_nan(input: np.array) -> float:
for i in reversed(range(len(input))):
if not np.isnan(input[i]):
return input[i]
return np.nan
def get_frame(sweeper_module, sample_node) -> dict:
frame = {"Progress": sweeper_module.progress()}
data = sweeper_module.read()
if sample_node in data:
imp_data = data[sample_node][0][0]
frame["absz"] = _last_non_nan(imp_data["absz"])
frame["realz"] = _last_non_nan(imp_data["realz"])
frame["imagz"] = _last_non_nan(imp_data["imagz"])
frame["frequency"] = _last_non_nan(imp_data["frequency"])
frame["bias"] = _last_non_nan(imp_data["bias"])
frame["drive"] = _last_non_nan(imp_data["drive"])
return frame
session = Session("valid ip")
device = session.connect_device("valid device")
sweeper_module = session.modules.sweeper
sweeper_module.device(device)
sweeper_module.gridnode(device.oscs[0].freq)
sweeper_module.start(1)
sweeper_module.stop(5.1e6)
sweeper_module.samplecount(300)
sweeper_module.scan("sequential")
sweeper_module.xmapping("log")
sweeper_module.endless(0)
sweeper_module.save.fileformat("csv")
sweeper_module.subscribe(device.imps[0].sample)
sweeper_module.execute()
while not sweeper_module.raw_module.finished():
time.sleep(1)
print(f"{get_frame(sweeper_module, device.imps[0].sample)=}")
# process last frame
print(f"{get_frame(sweeper_module, device.imps[0].sample)=}")
sweeper_module.unsubscribe(device.imps[0].sample)The Expand zhinst.core Codeimport zhinst.core
import numpy as np
import time
def _last_non_nan(input: np.array) -> float:
for i in reversed(range(len(input))):
if not np.isnan(input[i]):
return input[i]
return np.nan
def get_frame(sweeper_module) -> dict:
frame = {"Progress": sweeper_module.progress()}
data = sweeper_module.read()
if 'valid device' in data:
imp_data = data['valid device']['imps']['0']['sample'][0][0]
frame["absz"] = _last_non_nan(imp_data["absz"])
frame["realz"] = _last_non_nan(imp_data["realz"])
frame["imagz"] = _last_non_nan(imp_data["imagz"])
frame["frequency"] = _last_non_nan(imp_data["frequency"])
frame["bias"] = _last_non_nan(imp_data["bias"])
frame["drive"] = _last_non_nan(imp_data["drive"])
return frame
device = zhinst.core.ziDAQServer("valid ip", 8004, 6)
sweeper = device.sweep()
sweeper.set('device', 'valid device')
sweeper.set('gridnode', '/valid device/oscs/0/freq')
sweeper.set('historylength', 100)
sweeper.set('settling/inaccuracy', 0.01000000)
sweeper.set('averaging/sample', 20)
sweeper.set('averaging/tc', 15.00000000)
sweeper.set('averaging/time', 0.10000000)
sweeper.set('bandwidth', 10.00000000)
sweeper.set('bandwidthoverlap', 1)
sweeper.set('maxbandwidth', 100.00000000)
sweeper.set('omegasuppression', 80.00000000)
sweeper.set('order', 8)
sweeper.set('start', 1.00000000)
sweeper.set('stop', 5100000.00000000)
sweeper.set('samplecount', 300)
sweeper.set('xmapping', 1)
sweeper.set('endless', 0)
sweeper.subscribe('/valid device/imps/0/sample')
sweeper.execute()
while not sweeper.finished():
time.sleep(1)
print(f"{get_frame(sweeper)=}")
# process last frame
print(f"{get_frame(sweeper)=}")
sweeper.unsubscribe('/valid device/imps/0/sample')I'd prefer to use the toolkit version of things. Any idea why it is slower? Maybe some deep copies somewhere that I can disable? |
Replies: 1 comment 1 reply
|
Hello @woopelderly Thank you for your question and sharing your scripts. In order to have similar performance in toolkit and core Python APIs, we simply need to use similar settings for the Sweeper module in both frameworks. I can see from your scripts that not all Sweeper settings in the core API are applied to the Sweeper module of toolkit framework. For example, the I hope this answer helps. |
Hello @woopelderly
Thank you for your question and sharing your scripts.
In order to have similar performance in toolkit and core Python APIs, we simply need to use similar settings for the Sweeper module in both frameworks. I can see from your scripts that not all Sweeper settings in the core API are applied to the Sweeper module of toolkit framework. For example, the
bandwidthoverlapis set in the core API throughsweeper.set('bandwidthoverlap', 1)while it is not set in the toolkit API. This already makes a big difference in the time it takes to perform a sweep. If you allow bandwidth overlap in the toolkit framework throughsweeper_module.bandwidthoverlap(1), you will observe a much f…