Class for loading pysmurf configuration files. In addition to
functions for reading and writing pysmurf configuration files,
contains helper functions for manipulating configuration variables
which are stored internally in a class instance attribute
dictionary named config.
pysmurf configuration files must be in the JSON format [1].
On instantiation, attempts to read the pysmurf configuration file
at the path provided by the filename argument into the
config dictionary. If the filename argument is not
provided, no configuration file is loaded and the config
attribute is None.
If a pysmurf configuration file is successfully loaded and the
validate constructor argument is True (which is the default
behavior), the parameters in the configuration file will be
validated using the 3rd party schema python library [2]
using the rules specified in the validate_config() class
method. If the configuration file data is valid, parameters are
loaded into the config dictionary.
If validate is False, the pysmurf configuration data will be
loaded without schema validation. Use at your own risk!
Parameters:
filename (str or None, optional, default None) – Path to pysmurf configuration file to load.
validate (bool, optional, default True) – Whether or not to run schema validation on the pysmurf
configuration file data. If schema validation fails, a
SchemaError exception will be raised.
Variables:
filename (str or None) – Path to loaded pysmurf configuration file, or configuration
file to load. None if no pysmurf configuration file has
been loaded.
config (dict or None) – Loaded dictionary of pysmurf configuration data. None if no
pysmurf configuration file has been loaded.
Read config file and update the config dictionary.
Reads raw configuration parameters from configuration file at
the path specified by the filename class instance
attribute using the read_json() method.
If the validate argument is True (which is the default
behavior), the loaded configuration parameters are validated
using the validate_config() routine.
The config class instance attribute is only updated
with the loaded configuration parameters if the update
argument is True (it is False by default). Either way,
the loaded configuration parameter dictionary is returned.
Parameters:
update (bool, optional, default False) – Whether or not to update the configuration.
validate (bool, optional, default True) – Whether or not to run schema validation on the pysmurf
configuration file data. If schema validation fails, a
SchemaError exception will be raised.
Returns:
config – The loaded dictionary of pysmurf configuration parameters.
Opens configuration file at the path provided by the
filename argument, strips off all lines that start with the
character provided by the comment_char argument, and then
parses the remaining lines in the pysmurf configuration file
into a dictionary using the json.loads() routine.
Any text after the comment_char on a line is also ignored.
Parameters:
filename (str) – Path to pysmurf configuration file to load.
comment_char (str, optional, default '#') – Comments that start with this character will be ignored.
Returns:
loaded_config – Dictionary of loaded pysmurf configuration parameters.
Validates the parameters in the configuration dictionary
provided by the loaded_config argument using the 3rd party
schema python library. If the configuration data is valid,
parameters are returned as a dictionary.
schema validation does several important things to raw data
loaded from the pysmurf configuration file:
Checks that all mandatory configuration variables are defined.
Conditions all configuration variables into the correct type
(e.g. float, int, str, etc.).
Automatically fills in the values for missing optional
parameters. Optional parameters are typically parameters which
almost never change from SMuRF system to SMuRF system.
Checks if parameters have valid values (e.g., some parameters
can only be either 0 or 1, or must be in a predefined interval,
etc.).
Performs validation of some known higher level configuration
data interdependencies (e.g. prevents the user from defining an
RTM DAC as both a TES bias and an RF amplifier bias).
If validation fails, schema will raise a SchemaError exception
and fail to load the configuration data, forcing the user to fix
the cause of the SchemaError exception before the configuration
file can be loaded and used.
Parameters:
loaded_config (dict) – Dictionary of pysmurf configuration parameters to run
schema validation on.
Returns:
validated_config – Dictionary of validated configuration parameters.
Parameter values are conditioned by schema to conform to
the specified types.
SmurfConfigPropertiesMixin for WHAT IS THIS MIXIN FOR.
Parameters:
cfg_file (str, optional, default None) – Config file path. Must be provided if not on offline mode.
data_dir (str, optional, default None) – Path to the data directory.
name (str, optional, default None) – The name of the output directory. If None, it will use the
current timestamp as the output directory name.
make_logfile (bool, optional, default True) – Whether to make a log file. If False, outputs will go to the
screen.
setup (bool, optional, default False) – Whether to run the setup step.
offline (bool, optional, default False) – Whether or not to instantiate in offline mode.
smurf_cmd_mode (bool, optional, default False) – This mode tells the system that the input is coming in from the
command line (rather than a python session). Everything
implemented here are in smurf_cmd.py.
no_dir (bool, optional, default False) – Whether to make a skip making a directory.
validate_config (bool, optional, default True) – Whether to check if the input config file is correct.
data_dir (str, optional, default None) – Path to the data directory.
name (str, optional, default None) – The name of the output directory. If None, it will use
the current timestamp as the output directory name.
make_logfile (bool, optional, default True) – Whether to make a log file. If False, outputs will
go to the screen.
setup (bool, optional, default False) – Whether to run the setup step.
smurf_cmd_mode (bool, optional, default False) – This mode tells the system that the input is coming in
from the command line (rather than a python session).
Everything implemented here are in smurf_cmd.py.
no_dir (bool, optional, default False) – Whether to make a skip making a directory.
publish (bool, optional, default False) – Whether to send messages to the OCS publisher.
payload_size (int, optional, default 2048) – The payload size to set on setup.
data_path_id (str, optional, default None) – If set, this will add the path-id to the output and plot dir
paths to avoid possible collisions between multiple smurf
instances running simultaneously. For instance, if set to
crate1slot2 the outputs directory will be::
<data_dir>/<date>/crate1slot2/<ctime>/outputs
Sets up the SMuRF system by first loading hardware register
defaults followed by overriding the hardware default register
values with defaults from the pysmurf configuration file.
Setup steps (in order of execution):
Disables hardware logging if it’s active (to avoid register
access collisions).
Sets FPGA OT limit (if one is specified in pysmurf cfg).
Configures timing based on pysmurf configuration file settings.
Resumes hardware logging if it was active at beginning.
If system configuration fails, returns False, otherwise
returns True. Failure modes (which will return False) are
as follows:
set_defaults_pv()
fails (only supported for pysmurf core code versions
>=4.1.0). If failure is detected, doesn’t attempt to
execute the subsequent setup steps.
set_check_jesd()
fails (only supported for Rogue ZIP file versions >=0.3.0).
If failure is detected, doesn’t attempt to execute the
subsequent setup steps.
Parameters:
write_log (bool, optional, default True) – Whether to write to the log file.
payload_size (int, optional, default 2048) – The starting size of the payload.
force_configure (bool, optional, default False) – Whether or not to force configure if system has already
been configured once by the currently running Rogue
server.
**kwargs – Arbitrary keyword arguments. Passed to many, but not all,
of the _caput calls.
Returns:
success – Returns True if system setup succeeded, otherwise
False. Also returns False if system has already been
configured by the currently running Rogue server and
force_configure=False.
Dump the current configuration to a file. This wraps around the config
file writing in the config object. Files are timestamped and dumped to
the S.output_dir by default.
Parameters:
filename (str, optional, default None) – Full path of output configuration file to write to disk.
Mixin for loading pysmurf configuration parameters.
Defines properties used by pysmurf whose values are specified in
the pysmurf configuration file. More details on python properties
can be found in the documentation for python “Built-in Functions”
[3].
If a user changes the value of a property but then writes the
internal pysmurf configuration to disk with the
write_output()
function, the value written to the file will not reflect the
user’s change.
Examples
Taking the pA_per_phi0 property as an example, if S is a
SmurfControl class
instance, once the property has been set with a call to the
copy_config_to_properties() routine, its value can be
retrieved like this:
>>> S.pA_per_phi09000000.0
and it can be set like this:
>>> S.pA_per_phi0=9000000.0
Each property has a corresponding class instance internal
attribute that the property get/set operates on and which is used
internally in all pysmurf functions that rely on the property.
The internal attributes corresponding to each property have the
same name as the property but with an underscore preceding the
property name. E.g. the internal attribute corresponding to the
pA_per_phi0 property is called _pA_per_phi0. Users should
never set or get the internal attribute directly.
Gets or sets the list of TES bias groups in use. Each element
of this list must be an integer corresponding to a TES bias
group and in [0,16). bias_group_to_pair() encodes the
mapping from TES bias group number to bipolar RTM DAC pair.
Specified in the pysmurf configuration file as
all_bias_groups.
Map between the 500MHz bands and their RF attenuators.
Gets or sets the assumed hardware correspondence between the
500 MHz attenuators and their UC and DC RF attenuator numbers.
Only the mapping for bands 0-3 should be specified, since the
mapping is assumed to be identical for the two carrier AMC
bays (e.g. the mapping is identical from band to attenuator
number for band % 4). Unitless.
Specified in the pysmurf configuration file as
attenuator.
Returns:
A dictionary with two keys, ‘band’ and ‘att’, which map to
two numpy.ndarray of integers corresponding to
the UC and DC attenuator numbers and their corresponding
500 MHz band numbers, in the same order.
where the keys (e.g. “att1”) specify which attenuator maps to
which 500 MHz band (the integer value). The mapping is stored
in a very different format inside pysmurf - loading the above
attenuator mapping results in the following value for the
attenuator property (here S is a
SmurfControl class
instance):
Resonator frequency ranges to ignore when relocking.
Gets or sets the list of RF frequency intervals in which to
ignore resonator candidates in calls to
relock()
Frequencies are in units of MHz.
relock()
is called at the end of many tuning functions including
setup_notches()
and
track_and_check().
Specified in the pysmurf configuration file as
bad_mask.
The bad_mask property is specified as a dictionary in the
pysmurf configuration file like this (where the ellipsis
denotes additional possible bad_mask entries):
"bad_mask":{"0":[5000,5100],"1":[5500,5750],...},
where the keys are ignored (but must be unique) and the values
specify intervals of RF frequencies in MHz over which to
discard resonator candidates when relocking. The frequency
ranges are stored in pysmurf in the bad_mask property as a
numpy.ndarray of numpy.ndarray.
For example, the above would result in the following value for
the bad_mask property (here S is a
SmurfControl class
instance and the ellipsis denotes additional possible
entries):
Gets or sets the total low current mode TES bias line
resistance. Assumes the same resistance for every TES bias
line. Includes the inline resistance on the cryostat card
(with the cryostat card relays set to the low current
operation mode position) and cryocable impedance (including
any cold resistors). Technically includes the resistance
added by the connected TES+shunt resistor chain, but that is
typically negligible compared to the cryostat card and
cryocable impedances. Units are Ohms.
Specified in the pysmurf configuration file as
bias_line_resistance.
Returns:
Total low current mode TES bias line resistance in Ohms.
Gets or sets the 50K RF amplifier drain current is measured
before the regulator that steps the main RF6.0V supply down to
the lower 50K RF amplifier drain voltage using an inline
resistor (see fiftyk_amp_Vd_series_resistor()), so the
total measured current through the series resistor includes
both the drain current drawn by the 50K RF amplifier and any
additional current drawn by the DC/DC regulator. An accurate
measurement of the 50K amplifier drain current requires
subtracting the current drawn by that regulator from the
measured total current. This is the offset to subtract off
the measured value. Units are milliamperes.
Specified in the pysmurf configuration file as
amplifier:50k_Id_offset.
50K LNA drain current measurement resistor in Ohms.
Gets or sets the resistance of the resistor that is inline
with the 50K LNA drain voltage source which is used to infer
the 50K RF amplifier drain current. This resistor is inline
with but before the regulator that steps the main RF6.0V
supply down to the lower 50K LNA drain voltage, so the current
flowing through this resistor includes both the drain current
drawn by the 50K RF amplifier and any additional current drawn
by the DC/DC regulator. The default value of 10 Ohm is the
standard value loaded onto cryostat card revision C02
(PC-248-103-02-C02). The resistor on that revision of the
cryostat card is R54. Units are Ohms.
Specified in the pysmurf configuration file as
amplifier:50K_amp_Vd_series_resistor.
Returns:
Resistance in Ohms of the inline resistor used to measure
the 50K LNA drain current.
Gets or set the conversion from bits (the digital value the
RTM DAC is set to) to Volts for the 50K LNA gate (specified at
the output of the cryostat card). An important dependency is
the voltage division on the cryostat card, which can be
different from cryostat card to cryostat card. Units are
Volts/bit.
Specified in the pysmurf configuration file as
amplifier:bit_to_V_50k.
Returns:
Conversion factor from bits to volts for the 50K LNA gate
in Volts/bit.
Gets or sets the DAC number of the DAC on the RTM that is
wired to the 50K LNA gate. Must be an integer between 1 and
32, at least for RTM main board revision C01
(PC-379-396-32-C01). The DAC number corresponds to the number
on the RTM schematic (e.g. see the nets named DAC1,…,DAC32.
The connection between an RTM DAC and the 50K LNA gate is made
on the cryostat card. The default RTM DAC that’s wired to the
50K LNA gate for cryostat card revision C02
(PC-248-103-02-C02) is DAC32 (if JMP4 on the cryostat card is
populated correctly).
Specified in the pysmurf configuration file as
amplifier:dac_num_50k.
Gets or sets the 4K HEMT drain current is measured before the
regulator that steps the main RF6.0V supply down to the lower
4K HEMT drain voltage using an inline resistor (see
hemt_Vd_series_resistor()), so the total measured
current through the series resistor includes both the drain
current drawn by the 4K HEMT and any additional current drawn
by the DC/DC regulator. An accurate measurement of the 4K
amplifier drain current requires subtracting the current drawn
by that regulator from the measured total current. This is
the offset to subtract off the measured value. Units are
milliamperes.
Specified in the pysmurf configuration file as
amplifier:hemt_Id_offset.
4K HEMT drain current measurement resistor in Ohms.
Gets or sets the resistance of the resistor that is inline
with the 4K HEMT amplifier drain voltage source which is used
to infer the 4K HEMT amplifier drain current. This resistor
is inline with but before the regulator that steps the main
RF6.0V supply down to the lower 4K HEMT drain voltage, so the
current flowing through this resistor includes both the drain
current drawn by the 4K HEMT and any additional current drawn
by the DC/DC regulator. The default value of 200 Ohm is the
standard value loaded onto cryostat card revision C02
(PC-248-103-02-C02). The resistor on that revision of the
cryostat card is R44. Units are Ohms.
Specified in the pysmurf configuration file as
amplifier:hemt_Vd_series_resistor.
Returns:
Resistance in Ohms of the inline resistor used to measure
the 4K HEMT amplifier drain current.
Gets or sets the conversion from bits (the digital value the
RTM DAC is set to) to Volts for the 4K amplifier gate
(specified at the output of the cryostat card). An important
dependency is the voltage division on the cryostat card, which
can be different from cryostat card to cryostat card. Units
are Volts/bit.
Specified in the pysmurf configuration file as
amplifier:bit_to_V_hemt.
Returns:
Conversion factor from bits to volts for the 4K amplifier
gate in Volts/bit.
Gets or sets the maximum voltage the 4K HEMT gate voltage can
be set to using the
set_hemt_gate_voltage()
function unless this software limit is overriden with the
boolean override argument of
set_hemt_gate_voltage().
Units are Volts.
Specified in the pysmurf configuration file as
amplifier:hemt_gate_max_voltage.
Returns:
Software limit on maximum 4K HEMT gate voltage user can
apply, in Volts.
Gets or sets the minimum voltage the 4K HEMT gate voltage can
be set to using the
set_hemt_gate_voltage()
function unless this software limit is overriden with the
boolean override argument of
set_hemt_gate_voltage().
Units are Volts.
Specified in the pysmurf configuration file as
amplifier:hemt_gate_min_voltage.
Returns:
Software limit on minimum 4K HEMT gate voltage user can
apply, in Volts.
Gets or sets the ratio of currents sourced by the cryostat
card for the same applied TES bias voltage (from the RTM, at
the input to the cryostat card) in high- versus low-current
cryostat card TES bias relay modes. In typical applications,
this ratio is >1, since otherwise the currents sourced in
high-current mode wouldn’t be higher than the currents sourced
in low current mode! Assumes the same ratio for every TES
bias line. In typical applications, this ratio is well
approximated by the ratio of the resistances on the cryostat
card alone (computed as the total resistance for the relay in
the low-current mode position divided by the total resistance
for the relay in the high-current mode position). Unitless.
Specified in the pysmurf configuration file as
high_low_current_ratio.
Returns:
The ratio of currents sourced by the cryostat card for the
same applied TES bias voltage (from the RTM, at the input
to the cryostat card) in high- versus low-current modes
(unitless).
Demodulated SQUID phase to TES current conversion factor.
Gets or sets the conversion factor between the demodulated
SQUID phase for every SMuRF channel and the equivalent TES
current. Units are picoamperes per Phi0, with Phi0 the
magnetic flux quantum.
Specified in the pysmurf configuration file as
constant:pA_per_phi0.
Returns:
Conversion factor between demodulated SQUID phase and
equivalent TES current in picoamperes per Phi0.
Gets or sets the coarse (analog + digital) round-trip delay.
This is the total time it takes a tone to traverse the
synthesis filter bank, get generated by the DAC, propagate
through the external analog RF circuit (e.g. through a cold RF
chain including MUX chips), get digitized by the ADC, and then
traverse the analysis filter bank. This register is named
refPhaseDelay in firmware.
Unit-less unsigned integer. Each step is a clock tick whose
frequency is given by
get_channel_frequency_mhz()
in MHz. Different carrier firmware versions support different
ranges.
This delay is applied to the phase of each generated tone, and
an overall phase rotation of (etaPhase - refPhaseDelay) is
applied to each tone after demodulation and downmix.
refPhaseDelay can be measured using the
estimate_phase_delay()
routine.
The total effective delay can be fine tuned by also setting
the refPhaseDelayFine register (see
ref_phase_delay_fine()) which adjusts the compensated
delay more finely by 307.2 MHz ticks (although they way
refPhaseDelayFine compensates for delay in firmware is not
the same as refPhaseDelay - see the docstring for the
ref_phase_delay_fine() property for more details).
Specified in the pysmurf configuration file as
init:band_#:refPhaseDelay with # the SMuRF 500 MHz band
number e.g. init:band_0:refPhaseDelay for band 0.
Warning
Because refPhaseDelay and refPhaseDelayFine include the
digital delay, it will vary for different firmware
versions.
Examples
For firmware where refPhaseDelay is measured in 2.4 MHz
ticks, if refPhaseDelay is 6 that corresponds to a time
delay of 6/(2.4 MHz) = 2.5 microseconds. For example, a 2
microsecond delay for a 100 kHz phi0 rate corresponds to an ~1
rad phase shift – so it’s particularly important to set
refPhaseDelay correctly if running at high phi0 rates (10
kHz or higher).
Returns:
Coarse (analog + digital) round-trip delay. Unit-less
unsigned integer. Each step is a clock tick whose rate is
given by
get_channel_frequency_mhz()
in MHz. Different carrier firmware versions support
different ranges.
Fine adjust for (analog + digital) round-trip delay.
Gets or sets fine adjustment for the total (analog + digital)
round-trip delay. This allows for fine adjustment of the
total effective system round-trip delay on top of the coarser
correction provided by programming the refPhaseDelay register
(see ref_phase_delay() and
set_ref_phase_delay()
for more details).
Unit-less unsigned integer. Each step is a 307.2 MHz tick
(3.255 ns), for all firmware versions. Different carrier
firmware versions support different ranges.
This register is named refPhaseDelayFine in firmware and is
implemented differently than refPhaseDelay : setting
refPhaseDelayFine only adds a time lag to the RF DAC output.
refPhaseDelayFine can be measured using the
estimate_phase_delay()
routine.
Specified in the pysmurf configuration file as
init:band_#:refPhaseDelayFine with # the SMuRF 500 MHz band
number e.g. init:band_0:refPhaseDelayFine for band 0.
Warning
Because refPhaseDelay and refPhaseDelayFine include the
digital delay, it will vary for different firmware
versions.
Examples
Say the total delay measured using
estimate_phase_delay()
is 2.3 microseconds. To program this delay, you’d first set
refPhaseDelay to 6, which is 2.5 microseconds (assuming that
refPhaseDelay is measured in 2.4 MHz ticks, and so 6/(2.4
MHz) = 2.5 microseconds). Because refPhaseDelayFine adds
time lag to the RF DAC output, it subtracts from the total
delay (so it compensates in the opposite direction that
refPhaseDelay does). So setting refPhaseDelayFine to 61
would result in a programmed delay of:
which is as close to 2.3 microseconds as we can program the
delay, given the clock rates.
Returns:
Fine adjustment for (analog + digital) round-trip delay.
Unit-less unsigned integer. Each step is a 307.2 MHz tick.
Different carrier firmware versions support different
ranges.