Skip to content

[Bug]: Exception reading two live-scripts one after the other with matnwb 2.8.0 #703

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
2 tasks done
aranega opened this issue Apr 21, 2025 · 3 comments · Fixed by #707
Closed
2 tasks done

[Bug]: Exception reading two live-scripts one after the other with matnwb 2.8.0 #703

aranega opened this issue Apr 21, 2025 · 3 comments · Fixed by #707
Labels
category: bug errors in the code or code behavior status: todo something needs to be done topic: matnwb-api related to improving the matnwb api

Comments

@aranega
Copy link

aranega commented Apr 21, 2025

What happened?

When executing two live-scripts in the same MATLAB session in DANDI-Hub/MATLAB online one after the other leads to an exception, unless all the variables are cleared before opening the second libe script.

The problem is visible on the live-script read from this repository:
https://github.com/MATLAB-Community-Toolboxes-at-INCF/example-live-scripts

Executing one of the live-scripts leads do to trigger any errors, but if I don't clear the variables after executing a live-script and executing the second one, reading a nwb file triggers and exception.
Here is the problematic line

nwbfile = nwbRead(the_file)

and the stack trace

The class 'types.hdmf_common.Container' is not a superclass of class 'types.core.NWBContainer', as required to invoke a superclass constructor or method.

Error in types.core.NWBContainer (line 19)
        obj = [email protected]_common.Container(varargin{:});

Error in types.core.NWBDataInterface (line 19)
        obj = [email protected](varargin{:});

Error in types.core.TimeSeries (line 74)
        obj = [email protected](varargin{:});

Error in io.createParsedType (line 28)
    typeInstance = feval(typeName, varargin{:}); % Create the type.

Error in io.parseGroup (line 78)
    parsed = io.createParsedType(info.Name, Type.typename, kwargs{:});

Error in io.parseGroup (line 38)
    subg = io.parseGroup(filename, group, Blacklist);

Error in io.parseGroup (line 38)
    subg = io.parseGroup(filename, group, Blacklist);

Error in nwbRead (line 97)
    nwb = io.parseGroup(filename, h5info(filename), blackList);

Steps to Reproduce

1. Take the live-scripts from this repository https://github.com/MATLAB-Community-Toolboxes-at-INCF/example-live-scripts
2. Download the necessary dataset from DANDI using the DANDI set downloader (it needs to be installed to have a quick access to the datasets): `dandi download dandi://dandi/000207` and `dandi download dandi://dandi/000011/sub-255201/sub-255201_ses-20141124_behavior+ecephys+ogen.nwb`
3. Execute one of the live-script (either `000207` or `000011`)
4. Execute the other live-script
5. The execution of `nwbRead(...)` triggers an error while executing the second live-script

Error Message

The class 'types.hdmf_common.Container' is not a superclass of class 'types.core.NWBContainer', as required to invoke a superclass constructor or method.

Error in types.core.NWBContainer (line 19)
        obj = [email protected]_common.Container(varargin{:});

Error in types.core.NWBDataInterface (line 19)
        obj = [email protected](varargin{:});

Error in types.core.TimeSeries (line 74)
        obj = [email protected](varargin{:});

Error in io.createParsedType (line 28)
    typeInstance = feval(typeName, varargin{:}); % Create the type.

Error in io.parseGroup (line 78)
    parsed = io.createParsedType(info.Name, Type.typename, kwargs{:});

Error in io.parseGroup (line 38)
    subg = io.parseGroup(filename, group, Blacklist);

Error in io.parseGroup (line 38)
    subg = io.parseGroup(filename, group, Blacklist);

Error in nwbRead (line 97)
    nwb = io.parseGroup(filename, h5info(filename), blackList);

Operating System

Linux

Matlab Version

MATLAB 2024b - build from MATLAB 2024b Docker image ghcr.io/mathworks-ref-arch/matlab-integration-for-jupyter/jupyter-matlab-notebook:2024b

Code of Conduct

@ehennestad
Copy link
Collaborator

ehennestad commented Apr 21, 2025

Thanks for reporting this!

What you see is a side effect of reading files that are created using different NWB versions. The files from dataset 000011 are created using NWB schema 2.1.0 and the files from 000207 are created using NWB schema 2.4.0.

MatNWB dynamically generates class files representing neurodata types matching specific versions of the NWB specification when reading from a file. So when you read a new file, the classes are regenerated, but if you still have variables in MATLAB's memory, the previous class definitions are loaded in memory. This can lead to the type of conflicts/errors you have seen, and the correct thing to do, as you have already noticed is to clear all the variables generated by running the first livescript.

With the current design, there is really no way to avoid this, but the error messages should be made more specific, and also suggest using a clear all statement in a situation where a file is being read using an NWB version that is incompatible with the previously loaded version.

@ehennestad ehennestad added category: bug errors in the code or code behavior status: todo something needs to be done topic: matnwb-api related to improving the matnwb api labels Apr 21, 2025
@aranega
Copy link
Author

aranega commented Apr 23, 2025

Hi @ehennestad, sorry for the late answer and thank you so much for your quick answer, and explanations, it's really clear!
I totally understand the problem, and executing a clear all is perfectly fine as solution for us at the moment :)

Thanks so much!

@bendichter
Copy link
Contributor

@ehennestad Is there a way to detect this version change and clear specifically the classes causing the problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: bug errors in the code or code behavior status: todo something needs to be done topic: matnwb-api related to improving the matnwb api
Projects
None yet
3 participants