|
14 | 14 | from qcodes.dataset import load_by_id, load_by_run_spec |
15 | 15 | from qcodes.dataset.data_set_in_memory import DataSetInMem, load_from_file |
16 | 16 | from qcodes.dataset.data_set_protocol import DataSetType |
| 17 | +from qcodes.dataset.descriptions.dependencies import InterDependencies_ |
| 18 | +from qcodes.dataset.descriptions.param_spec import ParamSpecBase |
17 | 19 | from qcodes.dataset.sqlite.connection import AtomicConnection, atomic_transaction |
18 | 20 | from qcodes.station import Station |
19 | 21 |
|
@@ -511,6 +513,49 @@ def test_load_from_file_by_id(meas_with_registered_param, DMM, DAC, tmp_path) -> |
511 | 513 | assert not isinstance(loaded_ds_from_db, DataSetInMem) |
512 | 514 |
|
513 | 515 |
|
| 516 | +def test_load_from_netcdf_non_completed_dataset(experiment, tmp_path) -> None: |
| 517 | + """Test that non-completed datasets can be loaded from netcdf files.""" |
| 518 | + # Create a non-completed dataset by NOT using the measurement context manager |
| 519 | + # which automatically completes the dataset on exit |
| 520 | + ds = DataSetInMem._create_new_run(name="test-dataset") |
| 521 | + |
| 522 | + # Set up interdependencies with simple parameters following the established pattern |
| 523 | + x_param = ParamSpecBase("x", paramtype="numeric") |
| 524 | + y_param = ParamSpecBase("y", paramtype="numeric") |
| 525 | + idps = InterDependencies_(dependencies={y_param: (x_param,)}) |
| 526 | + ds.prepare(interdeps=idps, snapshot={}) |
| 527 | + |
| 528 | + # Add some data points |
| 529 | + for x_val in np.linspace(0, 25, 5): |
| 530 | + y_val = x_val**2 # simple function |
| 531 | + ds._enqueue_results({x_param: np.array([x_val]), y_param: np.array([y_val])}) |
| 532 | + |
| 533 | + # Note: do NOT call ds.mark_completed() to keep it non-completed |
| 534 | + |
| 535 | + # Verify that the dataset is not completed |
| 536 | + assert ds.completed_timestamp_raw is None |
| 537 | + assert not ds.completed |
| 538 | + |
| 539 | + # Export the non-completed dataset to NetCDF |
| 540 | + ds.export(export_type="netcdf", path=str(tmp_path)) |
| 541 | + |
| 542 | + # Load the dataset from NetCDF |
| 543 | + loaded_ds = DataSetInMem._load_from_netcdf( |
| 544 | + tmp_path / f"qcodes_{ds.captured_run_id}_{ds.guid}.nc" |
| 545 | + ) |
| 546 | + |
| 547 | + # Verify that the loaded dataset is still non-completed |
| 548 | + assert isinstance(loaded_ds, DataSetInMem) |
| 549 | + assert loaded_ds.completed_timestamp_raw is None |
| 550 | + assert not loaded_ds.completed |
| 551 | + |
| 552 | + # Compare other properties |
| 553 | + assert loaded_ds.captured_run_id == ds.captured_run_id |
| 554 | + assert loaded_ds.guid == ds.guid |
| 555 | + assert loaded_ds.name == ds.name |
| 556 | + assert loaded_ds.run_timestamp_raw == ds.run_timestamp_raw |
| 557 | + |
| 558 | + |
514 | 559 | def test_load_from_netcdf_legacy_version(non_created_db) -> None: |
515 | 560 | # Qcodes 0.26 exported netcdf files did not contain |
516 | 561 | # the parent dataset links and used a different engine to write data |
|
0 commit comments