def _singleInstrumentParametersToJson(instrument: InstrumentBase,
                                      get: bool = False,
                                      addPrefix: str = '',
                                      includeMeta: List[str] = [],
                                      excludeParameters: List[str] = [],
                                      simpleFormat: bool = True) -> Dict:
    """Create a dictionary that holds the parameters of an instrument."""

    if "IDN" not in excludeParameters:
        excludeParameters.append("IDN")

    ret = {}
    snap = instrument.snapshot(update=get)
    for name, param in instrument.parameters.items():
        if name not in excludeParameters:
            if len(includeMeta) == 0 and simpleFormat:
                ret[addPrefix + name] = snap['parameters'][name].get('value', None)
            else:
                ret[addPrefix + name] = dict()
                for k, v in snap['parameters'][name].items():
                    if k in (['value'] + includeMeta):
                        ret[addPrefix + name][k] = v
        else:
            logger.debug(f"excluded: {addPrefix + name}")

    for name, submod in instrument.submodules.items():
        ret.update(_singleInstrumentParametersToJson(
            submod, get=get, addPrefix=f"{addPrefix + name}.",
            simpleFormat=simpleFormat, includeMeta=includeMeta))
    return ret
Exemple #2
0
    def test_snapshot_and_meta_attrs(self):
        """Test snapshot of InstrumentBase contains _meta_attrs attributes"""
        instr = InstrumentBase('instr')

        self.assertEqual(instr.name, 'instr')

        self.assertTrue(hasattr(instr, '_meta_attrs'))
        self.assertListEqual(instr._meta_attrs, ['name'])

        snapshot = instr.snapshot()

        self.assertIn('name', snapshot)
        self.assertEqual('instr', snapshot['name'])

        self.assertIn('__class__', snapshot)
        self.assertIn('InstrumentBase', snapshot['__class__'])
Exemple #3
0
def test_snapshot_and_meta_attrs():
    """Test snapshot of InstrumentBase contains _meta_attrs attributes"""
    instr = InstrumentBase('instr')

    assert instr.name == 'instr'

    assert hasattr(instr, '_meta_attrs')
    assert instr._meta_attrs == ['name']

    snapshot = instr.snapshot()

    assert 'name' in snapshot
    assert 'instr' == snapshot['name']

    assert '__class__' in snapshot
    assert 'InstrumentBase' in snapshot['__class__']