neuralogic packageο
Subpackagesο
- neuralogic.core package
- Subpackages
- neuralogic.core.builder package
- neuralogic.core.constructs package
- Subpackages
- Submodules
- neuralogic.core.constructs.factories module
- neuralogic.core.constructs.java_objects module
- neuralogic.core.constructs.metadata module
- neuralogic.core.constructs.predicate module
- neuralogic.core.constructs.relation module
- neuralogic.core.constructs.rule module
- neuralogic.core.constructs.term module
- Module contents
- neuralogic.core.settings package
- neuralogic.core.torch package
- Submodules
- neuralogic.core.enums module
- neuralogic.core.model module
- neuralogic.core.neural_module module
- neuralogic.core.sources module
- Module contents
AggregationBuiltDatasetCombinationFF.avgF.avg_aggF.concatF.concat_aggF.cossimF.countF.count_aggF.crossumF.elproductF.expF.identityF.inverseF.leaky_reluF.logF.lukasiewiczF.maxF.max_aggF.minF.min_aggF.normF.productF.reluF.reshapeF.reverseF.sigmoidF.signumF.sliceF.softmaxF.softmax_aggF.softmax_combF.sparsemaxF.sparsemax_combF.sqrtF.sumF.sum_aggF.tanhF.transp
GroundedDatasetGrounderMetadataModelRuleRuleBodySettingsSettingsProxySettingsProxy.chain_pruningSettingsProxy.debug_exportingSettingsProxy.default_fact_valueSettingsProxy.error_functionSettingsProxy.get_aggregation_function()SettingsProxy.get_combination_function()SettingsProxy.get_transformation_function()SettingsProxy.grounderSettingsProxy.initializerSettingsProxy.initializer_constSettingsProxy.initializer_uniform_scaleSettingsProxy.iso_value_compressionSettingsProxy.optimizerSettingsProxy.prune_only_identitiesSettingsProxy.relation_combinationSettingsProxy.relation_transformationSettingsProxy.rule_aggregationSettingsProxy.rule_combinationSettingsProxy.rule_transformationSettingsProxy.to_json()
TransformationTransformation.EXPTransformation.IDENTITYTransformation.INVERSETransformation.LEAKY_RELUTransformation.LOGTransformation.LUKASIEWICZTransformation.NORMTransformation.RELUTransformation.RESHAPETransformation.REVERSETransformation.SIGMOIDTransformation.SIGNUMTransformation.SLICETransformation.SOFTMAXTransformation.SPARSEMAXTransformation.SQRTTransformation.TANHTransformation.TRANSP
- Subpackages
- neuralogic.dataset package
- Submodules
- neuralogic.dataset.base module
- neuralogic.dataset.csv module
- neuralogic.dataset.db module
- neuralogic.dataset.file module
- neuralogic.dataset.logic module
- neuralogic.dataset.pddl module
- neuralogic.dataset.tensor module
- Module contents
- neuralogic.experimental package
- neuralogic.logging package
- neuralogic.nn package
- Subpackages
- Submodules
- neuralogic.nn.init module
- neuralogic.nn.loss module
- neuralogic.nn.torch_function module
- Module contents
APPNPConvAdamAttentionAvgPoolingCheckpointCallbackConstantCrossEntropyEarlyStoppingCallbackErrorFunctionGATv2ConvGCNConvGENConvGINConvGINEConvGRUGlorotHeInitializerLSTMLinearLongtailMAGNNLinearMAGNNMeanMLPMSEMaxPoolingMetaConvMetricModuleMultiheadAttentionNormalOptimizerPoolingPositionalEncodingProgressCallbackRGCNConvRNNResGatedGraphConvRvNNSAGEConvSGConvSGDSoftEntropySumPoolingTAGConvTrainerTrainerCallbackTrainerHistoryTrainerHistory.train_lossesTrainerHistory.val_lossesTrainerHistory.train_metricsTrainerHistory.val_metricsTrainerHistory.learning_ratesTrainerHistory.best_epochTrainerHistory.best_val_lossTrainerHistory.stopped_earlyTrainerHistory.best_epochTrainerHistory.best_val_lossTrainerHistory.learning_ratesTrainerHistory.stopped_earlyTrainerHistory.train_lossesTrainerHistory.train_metricsTrainerHistory.val_lossesTrainerHistory.val_metrics
TransformerTransformerDecoderTransformerEncoderUniformcompute_metrics()
- neuralogic.utils package
Submodulesο
neuralogic.exceptions moduleο
Exception hierarchy for PyNeuraLogic.
All library-raised exceptions inherit from NeuraLogicError so that
callers can write a single except NeuraLogicError block instead of
catching the generic Exception.
- exception BackendError[source]ο
Bases:
NeuraLogicErrorRaised when the Java backend encounters an internal error.
- exception ConfigurationError[source]ο
Bases:
NeuraLogicErrorRaised when settings, JVM, or environment configuration is invalid.
- exception DatasetError[source]ο
Bases:
NeuraLogicErrorRaised when dataset preparation or grounding fails.
- exception ModelError[source]ο
Bases:
NeuraLogicErrorRaised when the model definition or build process fails.
neuralogic.setup moduleο
- get_default_graphviz_path() str | None[source]ο
Gets the default path to Graphviz.
- Returns:
The Graphviz path or None if not set.
- Return type:
Optional[str]
- initial_seed() int[source]ο
Returns the initial/current random seed for a random number generator used in the backend.
- Returns:
The initial random seed.
- Return type:
int
- initialize(debug_mode: bool = False, debug_port: int = 12999, is_debug_server: bool = True, debug_suspend: bool = True, *, seed: int | None = None, graphviz_path: str | None = None, max_memory_size: int | None = None, log_handler: LogHandler | None = None, jar_path: str | None = None, started_check: bool = True)[source]ο
Initialize the NeuraLogic backend. This function is called implicitly when needed and should be called manually only for debugging.
- Parameters:
debug_mode (bool) β Enable/Disable JVM debug mode.
debug_port (int) β Port for the debugger to listen on. Default:
12999.is_debug_server (bool) β Act like server and listen for the debugger. Default:
Truedebug_suspend (bool) β Wait until the debugger is connected. Default:
Trueseed (Optional[int]) β The seed for the random number generator.
graphviz_path (Optional[str]) β The Graphviz path
max_memory_size (Optional[int]) β The maximum memory size (in gigabytes)
log_handler (Optional[LogHandler]) β The handler for logging
jar_path (Optional[str]) β The path to NeuraLogic java backend
started_check (bool) β Whether to check if the NeuraLogic has been started. If true and it has been started - raise an Exception
- is_initialized() bool[source]ο
Checks whether the NeuraLogic backend has been initialized.
- Returns:
True if the backend is initialized, False otherwise.
- Return type:
bool
- manual_seed(seed: int)[source]ο
Sets the seed for a random number generator used in the backend to the passed
seed.- Parameters:
seed (int) β The seed for the random number generator.
- seed() int[source]ο
Sets the seed for a random number generator used in the backend to a random seed and returns the seed.
- Returns:
The newly generated random seed.
- Return type:
int
- set_graphviz_path(path: str | None)[source]ο
Set the default path to Graphviz
- Parameters:
path (Optional[str]) β The Graphviz path
- set_jvm_options(options: List[str])[source]ο
Set the jvm options - by default
["-Xms1g"].- Parameters:
options (List[str]) β List of JVM options
- set_jvm_path(path: str | None)[source]ο
Set the JVM path.
- Parameters:
path (Optional[str]) β The JVM path
- set_max_memory_size(size: int)[source]ο
Sets the maximum memory size that can be utilized by the backend (in gigabytes).
- Parameters:
size (int) β The maximum memory size (in gigabytes).
- shutdown()[source]ο
Shut down the NeuraLogic JVM backend.
After calling this, you must call
initialize()again before using any NeuraLogic functionality. If the backend was never started, this is a no-op.Note
JPype does not support restarting a JVM within the same process, so re-initialization may fail. For reliable restart, use a fresh process.
Module contentsο
- exception BackendError[source]ο
Bases:
NeuraLogicErrorRaised when the Java backend encounters an internal error.
- exception ConfigurationError[source]ο
Bases:
NeuraLogicErrorRaised when settings, JVM, or environment configuration is invalid.
- exception DatasetError[source]ο
Bases:
NeuraLogicErrorRaised when dataset preparation or grounding fails.
- class F[source]ο
Bases:
objectUtility class providing a flat namespace for common functions. It includes transformation, combination, and aggregation functions.
- avg: CombinationFunction = <neuralogic.core.constructs.function.function.CombinationFunction object>ο
- avg_agg: AggregationFunction = <neuralogic.core.constructs.function.function.AggregationFunction object>ο
- concat: ConcatCombination = <neuralogic.core.constructs.function.concat.ConcatCombination object>ο
- concat_agg: ConcatAggregation = <neuralogic.core.constructs.function.concat.ConcatAggregation object>ο
- cossim: CombinationFunction = <neuralogic.core.constructs.function.function.CombinationFunction object>ο
- count: CombinationFunction = <neuralogic.core.constructs.function.function.CombinationFunction object>ο
- count_agg: AggregationFunction = <neuralogic.core.constructs.function.function.AggregationFunction object>ο
- crossum: CombinationFunction = <neuralogic.core.constructs.function.function.CombinationFunction object>ο
- elproduct: CombinationFunction = <neuralogic.core.constructs.function.function.CombinationFunction object>ο
- exp: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>ο
- identity: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>ο
- inverse: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>ο
- leaky_relu: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>ο
- log: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>ο
- lukasiewicz: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>ο
- max: CombinationFunction = <neuralogic.core.constructs.function.function.CombinationFunction object>ο
- max_agg: AggregationFunction = <neuralogic.core.constructs.function.function.AggregationFunction object>ο
- min: CombinationFunction = <neuralogic.core.constructs.function.function.CombinationFunction object>ο
- min_agg: AggregationFunction = <neuralogic.core.constructs.function.function.AggregationFunction object>ο
- norm: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>ο
- product: CombinationFunction = <neuralogic.core.constructs.function.function.CombinationFunction object>ο
- relu: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>ο
- reverse: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>ο
- sigmoid: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>ο
- signum: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>ο
- softmax: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>ο
- softmax_agg: SoftmaxAggregation = <neuralogic.core.constructs.function.softmax.SoftmaxAggregation object>ο
- softmax_comb: CombinationFunction = <neuralogic.core.constructs.function.function.CombinationFunction object>ο
- sparsemax: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>ο
- sparsemax_comb: CombinationFunction = <neuralogic.core.constructs.function.function.CombinationFunction object>ο
- sqrt: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>ο
- sum: CombinationFunction = <neuralogic.core.constructs.function.function.CombinationFunction object>ο
- sum_agg: AggregationFunction = <neuralogic.core.constructs.function.function.AggregationFunction object>ο
- tanh: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>ο
- transp: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>ο
- class LogHandler(output: Any, level: Level = Level.FINER, formatter: Formatter = Formatter.COLOR)[source]ο
Bases:
objectLogHandler stores settings for a log handler.
- output: Anyο
- class Model(*, model_file: str | None = None)[source]ο
Bases:
NeuralModuleModel is a collection of rules and relations that define the structure of the neural model.
- add_module(module: Module) None[source]ο
Expands the module into rules and adds them into the model.
- Parameters:
module (Module) β The module to expand and add.
- add_rule(rule: BaseRelation | WeightedRelation | Rule | PredicateMetadata) None[source]ο
Adds one rule to the model.
- Parameters:
rule (ModelEntries) β The rule to add.
- add_rules(rules: list[BaseRelation | WeightedRelation | Rule | PredicateMetadata]) None[source]ο
Adds multiple rules to the model.
- Parameters:
rules (list[ModelEntries]) β The rules to add.
- build(settings: Settings | None = None, torch: bool = False) Model[source]ο
Builds the model into a neural model.
- derivable_queries(example: list[BaseRelation | Rule] | None = None) list[BaseRelation] | dict[source]ο
Returns all derivable queries for the provided example.
- Parameters:
example (list[BaseRelation | Rule], optional) β The example to derive queries from. Default: None.
- Returns:
The list of derivable queries.
- Return type:
list[BaseRelation] | dict
- load(path: str | Path) None[source]ο
Load model weights from a file saved by
save().The model must already be built with the same architecture that produced the saved file.
- Parameters:
path (str | Path) β Path to the saved file.
- q(query: BaseRelation, examples: list[BaseRelation | Rule] | None = None) list[dict] | dict[source]ο
- query(query: BaseRelation, examples: list[BaseRelation | Rule] | None = None) list[dict] | dict[source]ο
Performs a query on the model with the provided examples.
- Parameters:
query (BaseRelation) β The query to perform.
examples (list[BaseRelation | Rule], optional) β The examples to use for the query. Default: None.
- Returns:
The list of query results (substitutions).
- Return type:
list[dict] | dict
- exception ModelError[source]ο
Bases:
NeuraLogicErrorRaised when the model definition or build process fails.
- exception NeuraLogicError[source]ο
Bases:
ExceptionBase class for all errors raised by PyNeuraLogic.
- class Settings(*, optimizer: Optimizer = <neuralogic.nn.optim.adam.Adam object>, error_function: ErrorFunction = <neuralogic.nn.loss.MSE object>, initializer: Initializer = <neuralogic.nn.init.Uniform object>, iso_value_compression: bool = True, chain_pruning: bool = True, prune_only_identities: bool = False, grounder: Grounder = Grounder.BUP)[source]ο
Bases:
object- property chain_pruning: boolο
- create_disconnected_proxy() SettingsProxy[source]ο
- create_proxy() SettingsProxy[source]ο
- property error_function: ErrorFunctionο
- property initializer: Initializerο
- property iso_value_compression: boolο
- property prune_only_identities: boolο
- add_log_handler(handler: LogHandler) None[source]ο
Add logger handler for an insight into the java backend. Overrides the default logger to stdout.
- Parameters:
handler (LogHandler) β The log handler to add.
- get_default_graphviz_path() str | None[source]ο
Gets the default path to Graphviz.
- Returns:
The Graphviz path or None if not set.
- Return type:
Optional[str]
- initial_seed() int[source]ο
Returns the initial/current random seed for a random number generator used in the backend.
- Returns:
The initial random seed.
- Return type:
int
- initialize(debug_mode: bool = False, debug_port: int = 12999, is_debug_server: bool = True, debug_suspend: bool = True, *, seed: int | None = None, graphviz_path: str | None = None, max_memory_size: int | None = None, log_handler: LogHandler | None = None, jar_path: str | None = None, started_check: bool = True)[source]ο
Initialize the NeuraLogic backend. This function is called implicitly when needed and should be called manually only for debugging.
- Parameters:
debug_mode (bool) β Enable/Disable JVM debug mode.
debug_port (int) β Port for the debugger to listen on. Default:
12999.is_debug_server (bool) β Act like server and listen for the debugger. Default:
Truedebug_suspend (bool) β Wait until the debugger is connected. Default:
Trueseed (Optional[int]) β The seed for the random number generator.
graphviz_path (Optional[str]) β The Graphviz path
max_memory_size (Optional[int]) β The maximum memory size (in gigabytes)
log_handler (Optional[LogHandler]) β The handler for logging
jar_path (Optional[str]) β The path to NeuraLogic java backend
started_check (bool) β Whether to check if the NeuraLogic has been started. If true and it has been started - raise an Exception
- is_initialized() bool[source]ο
Checks whether the NeuraLogic backend has been initialized.
- Returns:
True if the backend is initialized, False otherwise.
- Return type:
bool
- manual_seed(seed: int)[source]ο
Sets the seed for a random number generator used in the backend to the passed
seed.- Parameters:
seed (int) β The seed for the random number generator.
- seed() int[source]ο
Sets the seed for a random number generator used in the backend to a random seed and returns the seed.
- Returns:
The newly generated random seed.
- Return type:
int
- set_graphviz_path(path: str | None)[source]ο
Set the default path to Graphviz
- Parameters:
path (Optional[str]) β The Graphviz path
- set_jvm_options(options: List[str])[source]ο
Set the jvm options - by default
["-Xms1g"].- Parameters:
options (List[str]) β List of JVM options
- set_jvm_path(path: str | None)[source]ο
Set the JVM path.
- Parameters:
path (Optional[str]) β The JVM path
- set_max_memory_size(size: int)[source]ο
Sets the maximum memory size that can be utilized by the backend (in gigabytes).
- Parameters:
size (int) β The maximum memory size (in gigabytes).
- shutdown()[source]ο
Shut down the NeuraLogic JVM backend.
After calling this, you must call
initialize()again before using any NeuraLogic functionality. If the backend was never started, this is a no-op.Note
JPype does not support restarting a JVM within the same process, so re-initialization may fail. For reliable restart, use a fresh process.