SymbolicTracingUtils is a lightweight abstraction layer designed to simplify switching between symbolic tracing packages like Symbolics.jl and FastDifferentiation.jl.
Unlike other abstraction layers such as DifferentiationInterface.jl, this package is not limited to automatic differentiation use cases but also supports scenarios where symbolic tracing is used to generate efficient implementations of user-defined functions (irrespective of derivative computation).
- Seamless integration with both
Symbolics.jlandFastDifferentiation.jl. - Consistent APIs for creating symbolic variables, building callable functions, and computing gradients or Jacobians.
- Support for both dense and sparse Jacobian computation.
- Lightweight and minimalistic design.
To install SymbolicTracingUtils, use the Julia package manager:
using Pkg
Pkg.add("SymbolicTracingUtils")using SymbolicTracingUtils
backend = SymbolicsBackend()
x = make_variables(backend, :x, 3) # Creates a 3-element vector of symbolic variables `x[1]`, `x[2]`, `x[3]`f_symbolic = x[1]^2 + x[2]*x[3]
f_callable = build_function(f_symbolic, x; in_place = false)
result = f_callable([1.0, 2.0, 3.0]) # Evaluate the functiongrad_symbolic = gradient(f_symbolic, x)
grad_callable = build_function(grad_symbolic, x; in_place = false)
grad_callable([1.0, 2.0, 3.0])f_vector = [x[1]^2, x[2]*x[3]]
jac_symbolic = jacobian(f_vector, x) # Dense Jacobian
sparse_jac_symbolic = sparse_jacobian(f_vector, x) # Sparse JacobianThis project is licensed under the MIT License.
Contributions, bug reports, and feature requests are welcome!