gt4sd.algorithms.generation.torchdrug.core module

Torchdrug generation algorithm.

Summary

Classes:

TorchDrugGCPN

Interface for TorchDrug Graph-convolutional policy network (GCPN) algorithm.

TorchDrugGenerator

TorchDrugGraphAF

Interface for TorchDrug flow-based autoregressive graph algorithm (GraphAF).

Reference

class TorchDrugGenerator(configuration, target=None)[source]

Bases: GeneratorAlgorithm[S, None]

__init__(configuration, target=None)[source]

TorchDrug generation algorithm.

Parameters
  • configuration (AlgorithmConfiguration) – domain and application specification, defining types and validations. Currently supported algorithm versions are: “zinc250k_v0”, “qed_v0” and “plogp_v0”.

  • target (None) – unused since it is not a conditional generator.

Example

An example for using a generative algorithm from TorchDrug:

configuration = TorchDrugGCPN(algorithm_version=”qed_v0”) algorithm = TorchDrugGenerator(configuration=configuration) items = list(algorithm.sample(1)) print(items)

get_generator(configuration, target)[source]

Get the function to sample batches.

Parameters
  • configuration (AlgorithmConfiguration[~S, None]) – helps to set up the application.

  • target (None) – context or condition for the generation. Unused in the algorithm.

Return type

Callable[[], Iterable[Any]]

Returns

callable generating a batch of items.

validate_configuration(configuration)[source]

Overload to validate the a configuration for the algorithm.

Parameters

configuration (AlgorithmConfiguration) – the algorithm configuration.

Raises

InvalidAlgorithmConfiguration – in case the configuration for the algorithm is invalid.

Return type

AlgorithmConfiguration

Returns

the validated configuration.

__abstractmethods__ = frozenset({})
__annotations__ = {'generate': 'Untargeted', 'generator': 'Union[Untargeted, Targeted[T]]', 'max_runtime': 'int', 'max_samples': 'int', 'target': 'Optional[T]'}
__doc__ = None
__module__ = 'gt4sd.algorithms.generation.torchdrug.core'
__orig_bases__ = (gt4sd.algorithms.core.GeneratorAlgorithm[~S, NoneType],)
__parameters__ = (~S,)
_abc_impl = <_abc._abc_data object>
class TorchDrugGCPN(*args, **kwargs)[source]

Bases: TorchDrugGCPN, Generic[T]

Interface for TorchDrug Graph-convolutional policy network (GCPN) algorithm. Currently supported algorithm versions are “zinc250k_v0”, “qed_v0” and “plogp_v0”.

algorithm_type: ClassVar[str] = 'generation'

General type of generative algorithm.

domain: ClassVar[str] = 'materials'

General application domain. Hints at input/output types.

algorithm_version: str = 'zinc250k_v0'

To differentiate between different versions of an application.

There is no imposed naming convention.

get_conditional_generator(resources_path)[source]

Instantiate the actual generator implementation. :type resources_path: str :param resources_path: local path to model files.

Return type

GCPNGenerator

Returns

instance with sample method for generation.

classmethod get_filepath_mappings_for_training_pipeline_arguments()[source]

Get filepath mappings for the given training pipeline arguments. :type training_pipeline_arguments: TrainingPipelineArguments :param training_pipeline_arguments: training pipeline arguments.

Return type

Dict[str, str]

Returns

a mapping between artifacts’ files and training pipeline’s output files.

__annotations__ = {'algorithm_application': 'ClassVar[str]', 'algorithm_name': 'ClassVar[str]', 'algorithm_type': typing.ClassVar[str], 'algorithm_version': <class 'str'>, 'domain': typing.ClassVar[str]}
__dataclass_fields__ = {'algorithm_application': Field(name='algorithm_application',type=typing.ClassVar[str],default='TorchDrugGCPN',default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=<dataclasses._MISSING_TYPE object>,_field_type=_FIELD_CLASSVAR), 'algorithm_name': Field(name='algorithm_name',type=typing.ClassVar[str],default='TorchDrugGenerator',default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=<dataclasses._MISSING_TYPE object>,_field_type=_FIELD_CLASSVAR), 'algorithm_type': Field(name='algorithm_type',type=typing.ClassVar[str],default='generation',default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=<dataclasses._MISSING_TYPE object>,_field_type=_FIELD_CLASSVAR), 'algorithm_version': Field(name='algorithm_version',type=<class 'str'>,default='zinc250k_v0',default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=False,_field_type=_FIELD), 'domain': Field(name='domain',type=typing.ClassVar[str],default='materials',default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=<dataclasses._MISSING_TYPE object>,_field_type=_FIELD_CLASSVAR)}
__dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,order=False,unsafe_hash=False,frozen=False)
__doc__ = '\n    Interface for TorchDrug Graph-convolutional policy network (GCPN) algorithm.\n    Currently supported algorithm versions are "zinc250k_v0", "qed_v0" and "plogp_v0".\n    '
__eq__(other)

Return self==value.

__hash__ = None
__init__(*args, **kwargs)
__match_args__ = ('algorithm_version',)
__module__ = 'gt4sd.algorithms.generation.torchdrug.core'
__orig_bases__ = (<class 'types.TorchDrugGCPN'>, typing.Generic[~T])
__parameters__ = (~T,)
__pydantic_complete__ = True
__pydantic_config__ = {}
__pydantic_core_schema__ = {'cls': <class 'gt4sd.algorithms.generation.torchdrug.core.TorchDrugGCPN'>, 'config': {'title': 'TorchDrugGCPN'}, 'fields': ['algorithm_version'], 'frozen': False, 'metadata': {'pydantic_js_annotation_functions': [], 'pydantic_js_functions': [functools.partial(<function modify_model_json_schema>, cls=<class 'gt4sd.algorithms.generation.torchdrug.core.TorchDrugGCPN'>, title=None)]}, 'post_init': False, 'ref': 'types.TorchDrugGCPN:94662758981984', 'schema': {'collect_init_only': False, 'computed_fields': [], 'dataclass_name': 'TorchDrugGCPN', 'fields': [{'type': 'dataclass-field', 'name': 'algorithm_version', 'schema': {'type': 'default', 'schema': {'type': 'str'}, 'default': 'zinc250k_v0'}, 'kw_only': False, 'init': True, 'metadata': {'pydantic_js_functions': [], 'pydantic_js_annotation_functions': [<function get_json_schema_update_func.<locals>.json_schema_update_func>]}}], 'type': 'dataclass-args'}, 'slots': True, 'type': 'dataclass'}
__pydantic_decorators__ = DecoratorInfos(validators={}, field_validators={}, root_validators={}, field_serializers={}, model_serializers={}, model_validators={}, computed_fields={})
__pydantic_fields__ = {'algorithm_version': FieldInfo(annotation=str, required=False, default='zinc250k_v0', init=True, init_var=False, kw_only=False)}
__pydantic_serializer__ = SchemaSerializer(serializer=Dataclass(     DataclassSerializer {         class: Py(             0x00005618641f6160,         ),         serializer: Fields(             GeneralFieldsSerializer {                 fields: {                     "algorithm_version": SerField {                         key_py: Py(                             0x00007f1dcae691b0,                         ),                         alias: None,                         alias_py: None,                         serializer: Some(                             WithDefault(                                 WithDefaultSerializer {                                     default: Default(                                         Py(                                             0x00007f1dc39197f0,                                         ),                                     ),                                     serializer: Str(                                         StrSerializer,                                     ),                                 },                             ),                         ),                         required: true,                     },                 },                 computed_fields: Some(                     ComputedFields(                         [],                     ),                 ),                 mode: SimpleDict,                 extra_serializer: None,                 filter: SchemaFilter {                     include: None,                     exclude: None,                 },                 required_fields: 1,             },         ),         fields: [             Py(                 0x00007f1ea52ed250,             ),         ],         name: "TorchDrugGCPN",     }, ), definitions=[])
__pydantic_validator__ = SchemaValidator(title="TorchDrugGCPN", validator=Dataclass(     DataclassValidator {         strict: false,         validator: DataclassArgs(             DataclassArgsValidator {                 fields: [                     Field {                         kw_only: false,                         name: "algorithm_version",                         py_name: Py(                             0x00007f1ea52ed250,                         ),                         init: true,                         init_only: false,                         lookup_key: Simple {                             key: "algorithm_version",                             py_key: Py(                                 0x00007f1dcae6b500,                             ),                             path: LookupPath(                                 [                                     S(                                         "algorithm_version",                                         Py(                                             0x00007f1dcae69cf0,                                         ),                                     ),                                 ],                             ),                         },                         validator: WithDefault(                             WithDefaultValidator {                                 default: Default(                                     Py(                                         0x00007f1dc39197f0,                                     ),                                 ),                                 on_error: Raise,                                 validator: Str(                                     StrValidator {                                         strict: false,                                         coerce_numbers_to_str: false,                                     },                                 ),                                 validate_default: false,                                 copy_default: false,                                 name: "default[str]",                                 undefined: Py(                                     0x00007f1ea71db950,                                 ),                             },                         ),                         frozen: false,                     },                 ],                 positional_count: 1,                 init_only_count: None,                 dataclass_name: "TorchDrugGCPN",                 validator_name: "dataclass-args[TorchDrugGCPN]",                 extra_behavior: Ignore,                 extras_validator: None,                 loc_by_alias: true,             },         ),         class: Py(             0x00005618641f6160,         ),         fields: [             Py(                 0x00007f1ea52ed250,             ),         ],         post_init: None,         revalidate: Never,         name: "TorchDrugGCPN",         frozen: false,         slots: true,     }, ), definitions=[], cache_strings=True)
__repr__()

Return repr(self).

__signature__ = <Signature (algorithm_version: str = 'zinc250k_v0') -> None>
__wrapped__

alias of TorchDrugGCPN

class TorchDrugGraphAF(*args, **kwargs)[source]

Bases: TorchDrugGraphAF, Generic[T]

Interface for TorchDrug flow-based autoregressive graph algorithm (GraphAF). Currently supported algorithm versions are “zinc250k_v0”, “qed_v0” and “plogp_v0”.

algorithm_type: ClassVar[str] = 'generation'

General type of generative algorithm.

domain: ClassVar[str] = 'materials'

General application domain. Hints at input/output types.

algorithm_version: str = 'zinc250k_v0'

To differentiate between different versions of an application.

There is no imposed naming convention.

get_conditional_generator(resources_path)[source]

Instantiate the actual generator implementation. :type resources_path: str :param resources_path: local path to model files.

Return type

GAFGenerator

Returns

instance with samples method for generation.

classmethod get_filepath_mappings_for_training_pipeline_arguments()[source]

Get filepath mappings for the given training pipeline arguments. :type training_pipeline_arguments: TrainingPipelineArguments :param training_pipeline_arguments: training pipeline arguments.

Return type

Dict[str, str]

Returns

a mapping between artifacts’ files and training pipeline’s output files.

__annotations__ = {'algorithm_application': 'ClassVar[str]', 'algorithm_name': 'ClassVar[str]', 'algorithm_type': typing.ClassVar[str], 'algorithm_version': <class 'str'>, 'domain': typing.ClassVar[str]}
__dataclass_fields__ = {'algorithm_application': Field(name='algorithm_application',type=typing.ClassVar[str],default='TorchDrugGraphAF',default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=<dataclasses._MISSING_TYPE object>,_field_type=_FIELD_CLASSVAR), 'algorithm_name': Field(name='algorithm_name',type=typing.ClassVar[str],default='TorchDrugGenerator',default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=<dataclasses._MISSING_TYPE object>,_field_type=_FIELD_CLASSVAR), 'algorithm_type': Field(name='algorithm_type',type=typing.ClassVar[str],default='generation',default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=<dataclasses._MISSING_TYPE object>,_field_type=_FIELD_CLASSVAR), 'algorithm_version': Field(name='algorithm_version',type=<class 'str'>,default='zinc250k_v0',default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=False,_field_type=_FIELD), 'domain': Field(name='domain',type=typing.ClassVar[str],default='materials',default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=<dataclasses._MISSING_TYPE object>,_field_type=_FIELD_CLASSVAR)}
__dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,order=False,unsafe_hash=False,frozen=False)
__doc__ = '\n    Interface for TorchDrug flow-based autoregressive graph algorithm (GraphAF).\n    Currently supported algorithm versions are "zinc250k_v0", "qed_v0" and "plogp_v0".\n    '
__eq__(other)

Return self==value.

__hash__ = None
__init__(*args, **kwargs)
__match_args__ = ('algorithm_version',)
__module__ = 'gt4sd.algorithms.generation.torchdrug.core'
__orig_bases__ = (<class 'types.TorchDrugGraphAF'>, typing.Generic[~T])
__parameters__ = (~T,)
__pydantic_complete__ = True
__pydantic_config__ = {}
__pydantic_core_schema__ = {'cls': <class 'gt4sd.algorithms.generation.torchdrug.core.TorchDrugGraphAF'>, 'config': {'title': 'TorchDrugGraphAF'}, 'fields': ['algorithm_version'], 'frozen': False, 'metadata': {'pydantic_js_annotation_functions': [], 'pydantic_js_functions': [functools.partial(<function modify_model_json_schema>, cls=<class 'gt4sd.algorithms.generation.torchdrug.core.TorchDrugGraphAF'>, title=None)]}, 'post_init': False, 'ref': 'types.TorchDrugGraphAF:94662829305264', 'schema': {'collect_init_only': False, 'computed_fields': [], 'dataclass_name': 'TorchDrugGraphAF', 'fields': [{'type': 'dataclass-field', 'name': 'algorithm_version', 'schema': {'type': 'default', 'schema': {'type': 'str'}, 'default': 'zinc250k_v0'}, 'kw_only': False, 'init': True, 'metadata': {'pydantic_js_functions': [], 'pydantic_js_annotation_functions': [<function get_json_schema_update_func.<locals>.json_schema_update_func>]}}], 'type': 'dataclass-args'}, 'slots': True, 'type': 'dataclass'}
__pydantic_decorators__ = DecoratorInfos(validators={}, field_validators={}, root_validators={}, field_serializers={}, model_serializers={}, model_validators={}, computed_fields={})
__pydantic_fields__ = {'algorithm_version': FieldInfo(annotation=str, required=False, default='zinc250k_v0', init=True, init_var=False, kw_only=False)}
__pydantic_serializer__ = SchemaSerializer(serializer=Dataclass(     DataclassSerializer {         class: Py(             0x0000561868506db0,         ),         serializer: Fields(             GeneralFieldsSerializer {                 fields: {                     "algorithm_version": SerField {                         key_py: Py(                             0x00007f1dc39362e0,                         ),                         alias: None,                         alias_py: None,                         serializer: Some(                             WithDefault(                                 WithDefaultSerializer {                                     default: Default(                                         Py(                                             0x00007f1dc39197f0,                                         ),                                     ),                                     serializer: Str(                                         StrSerializer,                                     ),                                 },                             ),                         ),                         required: true,                     },                 },                 computed_fields: Some(                     ComputedFields(                         [],                     ),                 ),                 mode: SimpleDict,                 extra_serializer: None,                 filter: SchemaFilter {                     include: None,                     exclude: None,                 },                 required_fields: 1,             },         ),         fields: [             Py(                 0x00007f1ea52ed250,             ),         ],         name: "TorchDrugGraphAF",     }, ), definitions=[])
__pydantic_validator__ = SchemaValidator(title="TorchDrugGraphAF", validator=Dataclass(     DataclassValidator {         strict: false,         validator: DataclassArgs(             DataclassArgsValidator {                 fields: [                     Field {                         kw_only: false,                         name: "algorithm_version",                         py_name: Py(                             0x00007f1ea52ed250,                         ),                         init: true,                         init_only: false,                         lookup_key: Simple {                             key: "algorithm_version",                             py_key: Py(                                 0x00007f1dc3936330,                             ),                             path: LookupPath(                                 [                                     S(                                         "algorithm_version",                                         Py(                                             0x00007f1dc3936380,                                         ),                                     ),                                 ],                             ),                         },                         validator: WithDefault(                             WithDefaultValidator {                                 default: Default(                                     Py(                                         0x00007f1dc39197f0,                                     ),                                 ),                                 on_error: Raise,                                 validator: Str(                                     StrValidator {                                         strict: false,                                         coerce_numbers_to_str: false,                                     },                                 ),                                 validate_default: false,                                 copy_default: false,                                 name: "default[str]",                                 undefined: Py(                                     0x00007f1ea71db950,                                 ),                             },                         ),                         frozen: false,                     },                 ],                 positional_count: 1,                 init_only_count: None,                 dataclass_name: "TorchDrugGraphAF",                 validator_name: "dataclass-args[TorchDrugGraphAF]",                 extra_behavior: Ignore,                 extras_validator: None,                 loc_by_alias: true,             },         ),         class: Py(             0x0000561868506db0,         ),         fields: [             Py(                 0x00007f1ea52ed250,             ),         ],         post_init: None,         revalidate: Never,         name: "TorchDrugGraphAF",         frozen: false,         slots: true,     }, ), definitions=[], cache_strings=True)
__repr__()

Return repr(self).

__signature__ = <Signature (algorithm_version: str = 'zinc250k_v0') -> None>
__wrapped__

alias of TorchDrugGraphAF