Example #1
0
def empty_temp_db():
    # create a temp database for testing
    with tempfile.TemporaryDirectory() as tmpdirname:
        qc.config["core"]["db_location"] = os.path.join(tmpdirname, 'temp.db')
        qc.config["core"]["db_debug"] = True
        initialise_database()
        yield
Example #2
0
def test_load_2dsoftsweep():
    qc.config.core.db_location = DBPATH
    initialise_database()
    exp = load_or_create_experiment('2d_softsweep', sample_name='no sample')

    # define some test data
    x = np.linspace(0, 1., 5)
    y = np.linspace(0, 1., 5)
    xx, yy = np.meshgrid(x, y, indexing='ij')
    zz = np.random.rand(*xx.shape)

    # put data into a new dataset
    ds = new_data_set('2d_softsweep',
                      specs=[ParamSpec('x', 'numeric', unit='A'),
                             ParamSpec('y', 'numeric', unit='B'),
                             ParamSpec('z', 'numeric', unit='C',
                                       depends_on=['x', 'y']), ], )

    def get_next_result():
        for x, y, z in zip(xx.reshape(-1), yy.reshape(-1), zz.reshape(-1)):
            yield dict(x=x, y=y, z=z)

    results = get_next_result()
    for r in results:
        ds.add_result(r)
    ds.mark_complete()

    # retrieve data as data dict
    run_id = ds.run_id
    ddict = datadict_from_path_and_run_id(DBPATH, run_id)

    assert np.all(np.isclose(ddict.data_vals('z'), zz.reshape(-1), atol=1e-15))
    assert np.all(np.isclose(ddict.data_vals('x'), xx.reshape(-1), atol=1e-15))
    assert np.all(np.isclose(ddict.data_vals('y'), yy.reshape(-1), atol=1e-15))
Example #3
0
def test_update_qcloader(qtbot):
    qc.config.core.db_location = DBPATH
    initialise_database()
    exp = load_or_create_experiment('2d_softsweep', sample_name='no sample')

    # define test data
    x = np.linspace(0, 1., 5)
    y = np.linspace(0, 1., 5)
    xx, yy = np.meshgrid(x, y, indexing='ij')
    zz = np.random.rand(*xx.shape)

    def get_2dsoftsweep_results():
        for x, y, z in zip(xx.reshape(-1), yy.reshape(-1), zz.reshape(-1)):
            yield dict(x=x, y=y, z=z)

    # create data set
    _ds = new_data_set(
        '2d_softsweep',
        exp_id=exp.exp_id,
        specs=[
            ParamSpec('x', 'numeric', unit='A'),
            ParamSpec('y', 'numeric', unit='B'),
            ParamSpec('z', 'numeric', unit='C', depends_on=['x', 'y']),
        ],
    )

    run_id = _ds.run_id
    results = get_2dsoftsweep_results()

    # setting up the flowchart
    nodes, fc = make_sequential_flowchart([QCodesDSLoader])
    loader = nodes[0]
    loader.pathAndId = DBPATH, run_id

    def check():
        nresults = _ds.number_of_results
        loader.update()
        ddict = fc.output()['dataOut']

        z_in = zz.reshape(-1)[:nresults]
        z_out = ddict.data_vals('z')
        if z_out is not None:
            assert z_in.size == z_out.size
            assert np.allclose(z_in, z_out, atol=1e-15)

    # insert data in small chunks, and check
    while True:
        try:
            ninsertions = np.random.randint(0, 5)
            for n in range(ninsertions):
                _ds.add_result(next(results))
        except StopIteration:
            _ds.mark_complete()
            break
        check()
    check()
def init_or_create_database(db_file_with_abs_path: str) -> None:
    """
    This function sets up QCoDeS to refer to the given database file. If the
    database file does not exist, it will be initiated.

    Args:
        db_file_with_abs_path
            Database file name with absolute path, for example
            "C:\mydata\majorana_experiments.db"
    """
    qcodes.config.core.db_location = db_file_with_abs_path
    initialise_database()
Example #5
0
def empty_temp_db():
    global n_experiments
    n_experiments = 0
    # create a temp database for testing
    with tempfile.TemporaryDirectory() as tmpdirname:
        qc.config["core"]["db_location"] = os.path.join(tmpdirname, 'temp.db')
        if os.environ.get('QCODES_SQL_DEBUG'):
            qc.config["core"]["db_debug"] = True
        else:
            qc.config["core"]["db_debug"] = False
        initialise_database()
        yield
Example #6
0
    def setup(self, bench_param):
        # Init DB
        self.tmpdir = tempfile.mkdtemp()
        qcodes.config["core"]["db_location"] = os.path.join(
            self.tmpdir, 'temp.db')
        qcodes.config["core"]["db_debug"] = False
        initialise_database()

        # Create experiment
        self.experiment = new_experiment("test-experiment",
                                         sample_name="test-sample")

        # Create measurement
        meas = Measurement(self.experiment)

        x1 = ManualParameter('x1')
        x2 = ManualParameter('x2')
        x3 = ManualParameter('x3')
        y1 = ManualParameter('y1')
        y2 = ManualParameter('y2')

        meas.register_parameter(x1, paramtype=bench_param['paramtype'])
        meas.register_parameter(x2, paramtype=bench_param['paramtype'])
        meas.register_parameter(x3, paramtype=bench_param['paramtype'])
        meas.register_parameter(y1,
                                setpoints=[x1, x2, x3],
                                paramtype=bench_param['paramtype'])
        meas.register_parameter(y2,
                                setpoints=[x1, x2, x3],
                                paramtype=bench_param['paramtype'])

        self.parameters = [x1, x2, x3, y1, y2]

        # Create the Runner context manager
        self.runner = meas.run()

        # Enter Runner and create DataSaver
        self.datasaver = self.runner.__enter__()

        # Create values for parameters
        for _ in range(len(self.parameters)):
            self.values.append(np.random.rand(bench_param['n_values']))
Example #7
0
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
Example #8
0
from qdev_wrappers.station_configurator import StationConfigurator

import qcodes_measurements as qcm
from qcodes_measurements.plot.plot_tools import *
from qcodes_measurements.device import *

from dac_params import *

# Log all output
from IPython import get_ipython
ip = get_ipython()
ip.magic("logstop")
ip.magic("logstart -o -t iPython_Logs\\fivedot_analysis_log.py rotate")
ip.magic("autoreload 0")

# Close any instruments that may already be open
instruments = list(qc.Instrument._all_instruments.keys())
for instrument in instruments:
    instr = qc.Instrument._all_instruments.pop(instrument)
    instr = instr()
    instr.close()
del instruments

exp_name = 'QDP_FIVEDOT'
sample_name = 'DARLINGTON_D1'

initialise_database()
exp = load_or_create_experiment(exp_name, sample_name)
print('Experiment loaded. Last ID no:', exp.last_counter)