Skip to content

Commit

Permalink
Make all objects besides egraphs threadsafe
Browse files Browse the repository at this point in the history
  • Loading branch information
saulshanabrook committed Mar 26, 2024
1 parent ae3757e commit e2d2233
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ _This project uses semantic versioning_

- Upgrade [egglog](https://github.com/egraphs-good/egglog/compare/4cc011f6b48029dd72104a38a2ca0c7657846e0b...0113af1d6476b75d4319591cc3d675f96a71cdc5)
- Adds subsume action
- Makes all objects besides EGraphs "sendable" aka threadsafe ([#129](https://github.com/egraphs-good/egglog-python/pull/129))

## 6.0.1 (2024-02-28)

Expand Down
15 changes: 12 additions & 3 deletions python/tests/test_bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import pytest

from egglog.bindings import *
from egglog.bindings import Datatype, RewriteCommand, RunSchedule


def get_egglog_folder() -> pathlib.Path:
Expand Down Expand Up @@ -214,12 +215,20 @@ class TestThreads:
Verify that objects can be accessed from multiple threads at the same time.
"""

def test_run_program(self):
def test_cmds(self):
cmds = (
Datatype("Math", [Variant("Add", ["Math", "Math"])]),
RewriteCommand("", Rewrite(Call("Add", [Var("a"), Var("b")]), Call("Add", [Var("b"), Var("a")])), False),
RunSchedule(Repeat(10, Run(RunConfig("")))),
)

_thread.start_new_thread(EGraph().run_program, cmds)
_thread.start_new_thread(EGraph().run_program, cmds)
_thread.start_new_thread(print, cmds)

@pytest.mark.xfail(reason="egraphs are unsendable")
def test_egraph(self):
_thread.start_new_thread(EGraph().run_program, (Datatype("Math", [Variant("Add", ["Math", "Math"])]),))

def test_serialized_egraph(self):
egraph = EGraph()
serialized = egraph.serialize([])
_thread.start_new_thread(print, (serialized,))
1 change: 0 additions & 1 deletion src/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::collections::HashMap;
use pyo3::prelude::*;

#[pyclass(
unsendable,
text_signature = "(py_object_sort=None, *, fact_directory=None, seminaive=True, terms_encoding=False)"
)]
pub struct SerializedEGraph {
Expand Down
2 changes: 1 addition & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ macro_rules! convert_enums {
}
);*) => {
$($(
#[pyclass(unsendable, frozen, module="egg_smol.bindings"$(, name=$py_name)?)]
#[pyclass(frozen, module="egg_smol.bindings"$(, name=$py_name)?)]
#[derive(Clone, PartialEq, Eq$(, $trait_inner)?)]
pub struct $variant {
$(
Expand Down

0 comments on commit e2d2233

Please sign in to comment.