Example #1
0
def get_runs_from_db(
        path: str,
        start: int = 0,
        stop: Union[None, int] = None,
        get_structure: bool = False) -> Dict[int, DataSetInfoDict]:
    """
    Get a db ``overview`` dictionary from the db located in ``path``. The
    ``overview`` dictionary maps ``DataSet.run_id``s to dataset information as
    returned by ``get_ds_info`` functions.

    `start` and `stop` refer to indices of the runs in the db that we want
    to have details on; if `stop` is None, we'll use runs until the end.

    If `get_structure` is True, include info on the run data structure
    in the return dict.
    """
    initialise_or_create_database_at(path)

    datasets = sorted(chain.from_iterable(exp.data_sets()
                                          for exp in experiments()),
                      key=attrgetter('run_id'))

    # There is no need for checking whether ``stop`` is ``None`` because if
    # it is the following is simply equivalent to ``datasets[start:]``
    datasets = datasets[start:stop]

    overview = {
        ds.run_id: get_ds_info(ds, get_structure=get_structure)
        for ds in datasets
    }
    return overview
Example #2
0
def test_initialise_database_at_for_nonexisting_db(tmp_path):
    db_location = str(tmp_path / 'temp.db')
    assert not os.path.exists(db_location)

    initialise_or_create_database_at(db_location)

    assert os.path.exists(db_location)
    assert qc.config["core"]["db_location"] == db_location
def test_initialise_database_at_for_nonexisting_db():
    with tempfile.TemporaryDirectory() as tmpdirname:
        db_location = os.path.join(tmpdirname, 'temp.db')
        assert not os.path.exists(db_location)

        initialise_or_create_database_at(db_location)

        assert os.path.exists(db_location)
        assert qc.config["core"]["db_location"] == db_location
Example #4
0
def load_dataset_from(path: str, run_id: int) -> 'DataSet':
    """
    Loads ``DataSet`` with the given ``run_id`` from a database file that
    is located in in the given ``path``.

    Note that after the call to this function, the database location in the
    qcodes config of the current python process is changed to ``path``.
    """
    initialise_or_create_database_at(path)
    return load_by_id(run_id=run_id)
Example #5
0
def test_initialise_database_at_for_existing_db(tmp_path):
    # Define DB location
    db_location = str(tmp_path / 'temp.db')
    assert not os.path.exists(db_location)

    # Create DB file
    qc.config["core"]["db_location"] = db_location
    initialise_database()

    # Check if it has been created correctly
    assert os.path.exists(db_location)
    assert qc.config["core"]["db_location"] == db_location

    # Call function under test
    initialise_or_create_database_at(db_location)

    # Check if the DB is still correct
    assert os.path.exists(db_location)
    assert qc.config["core"]["db_location"] == db_location
def test_initialise_database_at_for_existing_db():
    with tempfile.TemporaryDirectory() as tmpdirname:
        # Define DB location
        db_location = os.path.join(tmpdirname, 'temp.db')
        assert not os.path.exists(db_location)

        # Create DB file
        qc.config["core"]["db_location"] = db_location
        initialise_database()

        # Check if it has been created correctly
        assert os.path.exists(db_location)
        assert qc.config["core"]["db_location"] == db_location

        # Call function under test
        initialise_or_create_database_at(db_location)

        # Check if the DB is still correct
        assert os.path.exists(db_location)
        assert qc.config["core"]["db_location"] == db_location
                units=("unit1", "unit2"),
            )
            self.setpoints = (tuple(), tuple())
            self.setpoint_shapes = (tuple(), tuple())
            self.setpoint_labels = (("I channel", ), ('Q channel', ))
            self.setpoint_units = (("mV", ), ("mV", ))
            self.setpoint_names = (("I_channel", ), ("Q_channel", ))
            self.i = 2

        def get_raw(self):
            self.i += 1
            return (self.i, self.i + 100)

    now = str(datetime.datetime.now())
    path = os.path.join(os.getcwd(), 'test.db')
    initialise_or_create_database_at(path)
    load_or_create_experiment('tutorial ' + now, 'no sample')
    my_param = MyCounter('test_instr')
    from qcodes.instrument.specialized_parameters import ElapsedTimeParameter

    x = qc.Parameter(name='x',
                     label='Voltage_x',
                     unit='V',
                     set_cmd=None,
                     get_cmd=None)
    y = qc.Parameter(name='y',
                     label='Voltage_y',
                     unit='V',
                     set_cmd=None,
                     get_cmd=None)
    timer = ElapsedTimeParameter('time')
Example #8
0
osc.ch3.t_start.set(-10)
osc.ch3.t_stop.set(10)
osc.ch4.t_start.set(-10)
osc.ch4.t_stop.set(10)

amp = 1
PSG1.amp(amp)
PSG2.amp(amp)

station = Station()
station.snapshot()

station.add_component(osc)

# Criar um database
initialise_or_create_database_at("~/teste.db")

exp = load_or_create_experiment(experiment_name='osc realtime intro 2',
                                sample_name="osc realtime 1")


def calculateGain():
    Y = osc.ch3.wavesample()
    n_mean = int(len(Y) / 2)
    value = 2 * np.mean(Y[n_mean:])
    value = 10 * np.log(np.power(value, 2))
    return value


gain = Parameter('gain', label='gain', unit='dB', get_cmd=calculateGain)