Expand description
TensorLogic CLI Library
Version: 0.1.0-alpha.2 | Status: Production Ready
This library provides programmatic access to the TensorLogic CLI functionality, allowing you to use the parser, executor, optimizer, and other components directly from Rust code without shelling out to the command-line interface.
§Features
- Expression Parsing: Parse logical expressions into TensorLogic IR
- Compilation: Compile expressions to einsum graphs with various strategies
- Execution: Execute compiled graphs with multiple backends
- Optimization: Apply optimization passes to improve performance
- Analysis: Analyze graph complexity and computational costs
- Benchmarking: Measure compilation and execution performance
- Format Conversion: Convert between different input/output formats
§Quick Start
use tensorlogic_cli::{parser, CompilationContext};
use tensorlogic_compiler::{compile_to_einsum_with_context, CompilationConfig};
// Parse an expression
let expr = parser::parse_expression("pred1(x) AND pred2(x, y)").unwrap();
// Create compiler context with configuration
let config = CompilationConfig::soft_differentiable();
let mut ctx = CompilationContext::with_config(config);
ctx.add_domain("D", 100);
// Compile to einsum graph
let graph = compile_to_einsum_with_context(&expr, &mut ctx).unwrap();
// Execute the graph (requires appropriate setup)
// let result = executor::execute_graph(&graph, &backend_config).unwrap();§Module Overview
parser: Parse logical expressions from stringsexecutor: Execute compiled einsum graphsoptimize: Apply optimization passesbenchmark: Performance benchmarking utilitiesanalysis: Graph analysis and metricsconversion: Format conversion utilitiesconfig: Configuration management (internal)output: Output formatting and colors
§Library Mode Benefits
Using TensorLogic as a library instead of a CLI provides:
- Better Performance: No process spawning overhead
- Type Safety: Compile-time error checking
- Integration: Direct embedding in Rust applications
- Flexibility: Fine-grained control over compilation and execution
- Testing: Easier unit and integration testing
§Example: Full Compilation Pipeline
use tensorlogic_cli::{parser, analysis, CompilationContext};
use tensorlogic_compiler::{compile_to_einsum_with_context, CompilationConfig};
// Parse expression
let expr = parser::parse_expression(
"EXISTS x IN Person. (pred1(x) AND pred2(x, y))"
).unwrap();
// Setup compilation context
let config = CompilationConfig::soft_differentiable();
let mut ctx = CompilationContext::with_config(config);
ctx.add_domain("Person", 100);
ctx.add_domain("D", 100);
// Compile
let graph = compile_to_einsum_with_context(&expr, &mut ctx).unwrap();
// Analyze complexity
let metrics = analysis::GraphMetrics::analyze(&graph);
println!("Graph has {} tensors and {} nodes", metrics.tensor_count, metrics.node_count);
println!("Estimated FLOPs: {}", metrics.estimated_flops);Re-exports§
pub use tensorlogic_adapters;pub use tensorlogic_compiler;pub use tensorlogic_infer;pub use tensorlogic_ir;pub use tensorlogic_scirs_backend;
Modules§
- analysis
- Graph analysis and metrics for TensorLogic CLI
- benchmark
- Benchmarking module for CLI
- cache
- Persistent compilation cache for TensorLogic
- conversion
- Format conversion utilities
- error_
suggestions - Error handling with helpful suggestions
- executor
- Provides execution capabilities for compiled TensorLogic graphs with:
- ffi
- FFI (Foreign Function Interface) bindings for tensorlogic-cli
- macros
- Macro system for defining reusable logical patterns
- optimize
- Graph optimization pipeline for CLI
- output
- Colored output formatting for TensorLogic CLI
- parser
- Enhanced expression parser for TensorLogic CLI
- simplify
- Expression simplification and normalization
- snapshot
- Snapshot testing for output consistency
Structs§
- Cache
Config - Cache configuration
- Config
- Configuration structure
- Repl
Config - Watch
Config
Constants§
Type Aliases§
- Compilation
Context - Type alias for compilation context used throughout the library
- Einsum
Graph - Type alias for einsum graphs
- Result
- Library result type
- TLExpr
- Type alias for TensorLogic expressions