Skip to content

Add Registration for Custom Cost Models #25

Description

@saulshanabrook

I am working on adding support to the Python bindings for custom cost models, so that you could define them in pure Python.

I was wondering if it might be appropriate to provide a way to register custom cost models with an EGraph and then be able to use them with the builtin extract command.

Currently, the set_cost cost model in the experimental repo has to define a new extract command that effectively duplicates the existing one but changes the cost model provided. It doesn't currently support the extract report as well.

So if I wanted to allow others in Python to define custom cost models, I would have to support exposing the Extractor object directly, creating a larger API surface area than might be neccessary.

Instead, what if we:

  1. (egglog core): Allowed user to register custom cost models on an egraph from Rust, attaching a name to them.
  2. (egglog core): Allow you to change the "default" cost model used in the EGraph.
  3. (egglog core): Change the extract command to use the default cost model, unless the name of another cost model is specified.
  4. (egglog experimental): Remove the additional extract command and replace it with registering the SetCost cost model and setting it as default

This would work similarly to how custom schedulers are supported, registering them from rust then referencing them in the egglog program.

Activity

  1. saulshanabrook commented on Sep 5, 2025

    @saulshanabrook
    MemberAuthor

    I moved this issue to experimental. Now with the structured output PR, we could add custom custom model registration only to experimental to work with that custom command.

  2. added a commit that references this issue on Dec 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions