mne-tools / mne-bids-pipeline

Automatically process entire electrophysiological datasets using MNE-Python.
https://mne.tools/mne-bids-pipeline/
BSD 3-Clause "New" or "Revised" License
134 stars 65 forks source link

pydantic.errors.PydanticSchemaGenerationError: Unable to generate pydantic-core schema for <class 'mne.channels.montage.DigMontage'>. #841

Closed SophieHerbst closed 6 months ago

SophieHerbst commented 6 months ago

Hello, I am running into an error when trying to re-run the pipeline (or a step of it, I tried both).

The key message seems to be this:

pydantic.errors.PydanticSchemaGenerationError: Unable to generate pydantic-core schema for <class 'mne.channels.montage.DigMontage'>. Set arbitrary_types_allowed=True in the model_config to ignore this error or implement __get_pydantic_core_schema__ on your type to fully support it.

I previously ran the pipeline (about 10 months ago), and now updated to version 1.5.0, using MNE 1.6.1 I also deleted the derivatives and starting all steps anew, but the error remains.

Any help on how to proceed will be highly appreciated, thanks! Sophie


> ────────┬ Welcome aboard MNE-BIDS-Pipeline! 👋 ─────────────────────────────────────────────────────────────────────────────────────
> │09:44:34│ 📝 Using configuration: /neurospin/meg/meg_tmp/TimeInWM_Izem_2019/BIDS_anonymized/code/config_sophie.py
> Traceback (most recent call last):
>   File "/home/sh254795/anaconda3/envs/mne/bin/mne_bids_pipeline", line 8, in <module>
>     sys.exit(main())
>   File "/home/sh254795/anaconda3/envs/mne/lib/python3.10/site-packages/mne_bids_pipeline/_main.py", line 218, in main
>     config_imported = _import_config(
>   File "/home/sh254795/anaconda3/envs/mne/lib/python3.10/site-packages/mne_bids_pipeline/_config_import.py", line 56, in _import_config
>     _check_config(config, config_path)
>   File "/home/sh254795/anaconda3/envs/mne/lib/python3.10/site-packages/mne_bids_pipeline/_config_import.py", line 224, in _check_config
>     _pydantic_validate(config=config, config_path=config_path)
>   File "/home/sh254795/anaconda3/envs/mne/lib/python3.10/site-packages/mne_bids_pipeline/_config_import.py", line 406, in _pydantic_validate
>     UserConfig = dataclass(config=dataclass_config)(UserConfig)
>   File "/home/sh254795/anaconda3/envs/mne/lib/python3.10/site-packages/pydantic/dataclasses.py", line 234, in create_dataclass
>     pydantic_complete = _pydantic_dataclasses.complete_dataclass(
>   File "/home/sh254795/anaconda3/envs/mne/lib/python3.10/site-packages/pydantic/_internal/_dataclasses.py", line 154, in complete_dataclass
>     schema = gen_schema.generate_schema(cls, from_dunder_get_core_schema=False)
>   File "/home/sh254795/anaconda3/envs/mne/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 501, in generate_schema
>     schema = self._generate_schema(obj)
>   File "/home/sh254795/anaconda3/envs/mne/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 739, in _generate_schema
>     schema = self._post_process_generated_schema(self._generate_schema_inner(obj))
>   File "/home/sh254795/anaconda3/envs/mne/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 766, in _generate_schema_inner
>     return self.match_type(obj)
>   File "/home/sh254795/anaconda3/envs/mne/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 840, in match_type
>     return self._dataclass_schema(obj, None)
>   File "/home/sh254795/anaconda3/envs/mne/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 1489, in _dataclass_schema
>     args = sorted(
>   File "/home/sh254795/anaconda3/envs/mne/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 1490, in <genexpr>
>     (self._generate_dc_field_schema(k, v, decorators) for k, v in fields.items()),
>   File "/home/sh254795/anaconda3/envs/mne/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 942, in _generate_dc_field_schema
>     common_field = self._common_field_schema(name, field_info, decorators)
>   File "/home/sh254795/anaconda3/envs/mne/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 1047, in _common_field_schema
>     schema = self._apply_annotations(
>   File "/home/sh254795/anaconda3/envs/mne/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 1749, in _apply_annotations
>     schema = get_inner_schema(source_type)
>   File "/home/sh254795/anaconda3/envs/mne/lib/python3.10/site-packages/pydantic/_internal/_schema_generation_shared.py", line 82, in __call__
>     schema = self._handler(__source_type)
>   File "/home/sh254795/anaconda3/envs/mne/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 1730, in inner_handler
>     schema = self._generate_schema(obj)
>   File "/home/sh254795/anaconda3/envs/mne/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 739, in _generate_schema
>     schema = self._post_process_generated_schema(self._generate_schema_inner(obj))
>   File "/home/sh254795/anaconda3/envs/mne/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 766, in _generate_schema_inner
>     return self.match_type(obj)
>   File "/home/sh254795/anaconda3/envs/mne/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 849, in match_type
>     return self._match_generic_type(obj, origin)
>   File "/home/sh254795/anaconda3/envs/mne/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 873, in _match_generic_type
>     return self._union_schema(obj)
>   File "/home/sh254795/anaconda3/envs/mne/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 1117, in _union_schema
>     choices.append(self.generate_schema(arg))
>   File "/home/sh254795/anaconda3/envs/mne/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 501, in generate_schema
>     schema = self._generate_schema(obj)
>   File "/home/sh254795/anaconda3/envs/mne/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 739, in _generate_schema
>     schema = self._post_process_generated_schema(self._generate_schema_inner(obj))
>   File "/home/sh254795/anaconda3/envs/mne/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 746, in _generate_schema_inner
>     return self._annotated_schema(obj)
>   File "/home/sh254795/anaconda3/envs/mne/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 1681, in _annotated_schema
>     schema = self._apply_annotations(source_type, annotations)
>   File "/home/sh254795/anaconda3/envs/mne/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 1749, in _apply_annotations
>     schema = get_inner_schema(source_type)
>   File "/home/sh254795/anaconda3/envs/mne/lib/python3.10/site-packages/pydantic/_internal/_schema_generation_shared.py", line 82, in __call__
>     schema = self._handler(__source_type)
>   File "/home/sh254795/anaconda3/envs/mne/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 1831, in new_handler
>     schema = metadata_get_schema(source, get_inner_schema)
>   File "/home/sh254795/anaconda3/envs/mne/lib/python3.10/site-packages/pydantic/functional_validators.py", line 156, in __get_pydantic_core_schema__
>     schema = handler(source_type)
>   File "/home/sh254795/anaconda3/envs/mne/lib/python3.10/site-packages/pydantic/_internal/_schema_generation_shared.py", line 82, in __call__
>     schema = self._handler(__source_type)
>   File "/home/sh254795/anaconda3/envs/mne/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 1730, in inner_handler
>     schema = self._generate_schema(obj)
>   File "/home/sh254795/anaconda3/envs/mne/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 739, in _generate_schema
>     schema = self._post_process_generated_schema(self._generate_schema_inner(obj))
>   File "/home/sh254795/anaconda3/envs/mne/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 766, in _generate_schema_inner
>     return self.match_type(obj)
>   File "/home/sh254795/anaconda3/envs/mne/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 853, in match_type
>     return self._unknown_type_schema(obj)
>   File "/home/sh254795/anaconda3/envs/mne/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 397, in _unknown_type_schema
>     raise PydanticSchemaGenerationError(
> pydantic.errors.PydanticSchemaGenerationError: Unable to generate pydantic-core schema for <class 'mne.channels.montage.DigMontage'>. Set `arbitrary_types_allowed=True` in the model_config to ignore this error or implement `__get_pydantic_core_schema__` on your type to fully support it.
> 
> If you got this error by calling handler(<some type>) within `__get_pydantic_core_schema__` then you likely need to call `handler.generate_schema(<some type>)` since we do not call `__get_pydantic_core_schema__` on `<some type>` otherwise to avoid infinite recursion.
hoechenberger commented 6 months ago

@larsoner Would you have time to take a look at this, please? 🙏

larsoner commented 6 months ago

This should already be fixed in main from https://github.com/mne-tools/mne-bids-pipeline/pull/839/files#diff-db33f4aac5381d0cae0b4665054e17ae00a13be2d73a7e09a61d0fd4256f63feR372 , can you try it?

SophieHerbst commented 6 months ago

Yes, problem solved. Many thanks @larsoner !

SophieHerbst commented 6 months ago

I still get this warning though, is it known :


> (mne) sh254795@is152869:/neurospin/meg/meg_tmp/TimeInWM_Izem_2019/BIDS_anonymized/code$ mne_bids_pipeline --config=/neurospin/meg/meg_tmp/TimeInWM_Izem_2019/BIDS_anonymized/code/config_sophie.py --steps=preprocessing
> <frozen importlib._bootstrap>:241: FutureWarning: mne.io.pick.pick_types is deprecated will be removed in 1.6, use documented public API instead. If no appropriate public API exists, please open an issue on GitHub.
> <frozen importlib._bootstrap>:241: FutureWarning: mne.io.pick.pick_channels_regexp is deprecated will be removed in 1.6, use documented public API instead. If no appropriate public API exists, please open an issue on GitHub.
> <frozen importlib._bootstrap>:241: FutureWarning: mne.io.pick.channel_type is deprecated will be removed in 1.6, use documented public API instead. If no appropriate public API exists, please open an issue on GitHub.
larsoner commented 6 months ago

For that one you probably need to update mne-bids

larsoner commented 6 months ago

... and MNE 1.6.1 is out so you should use that as well!

SophieHerbst commented 6 months ago

I updated MNE today, but not mne-bids. Will do! Thanks