Skip to content

Commit a7300a6

Browse files
Merge pull request #369 from marvin-hansen/main
Refactored the Causaloid context to use Arc<RwLock>,
2 parents 3ec5a2a + 5236fcb commit a7300a6

File tree

31 files changed

+436
-93
lines changed

31 files changed

+436
-93
lines changed

Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

MODULE.bazel

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ module(name = "deep_causality")
55
# https://registry.bazel.build/
66
###############################################################################
77
bazel_dep(name = "aspect_bazel_lib", version = "2.16.0")
8-
bazel_dep(name = "bazel_skylib", version = "1.8.1")
8+
bazel_dep(name = "bazel_skylib", version = "1.8.2")
99
bazel_dep(name = "platforms", version = "1.0.0")
10-
bazel_dep(name = "rules_rust", version = "0.65.0")
10+
bazel_dep(name = "rules_rust", version = "0.67.0")
1111

1212
###############################################################################
1313
# Rust toolchain
1414
# https://github.com/bazelbuild/rules_rust/releases
1515
###############################################################################
1616
RUST_EDITION = "2024"
1717

18-
RUST_VERSION = "1.90.0"
18+
RUST_VERSION = "1.91.0"
1919

2020
rust = use_extension("@rules_rust//rust:extensions.bzl", "rust")
2121
rust.toolchain(

MODULE.bazel.lock

Lines changed: 10 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

deep_causality/src/alias/alias_function.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Copyright (c) "2025" . The DeepCausality Authors and Contributors. All Rights Reserved.
44
*/
55
use crate::{AssumptionError, CausalityError, Context, PropagatingEffect};
6-
use std::sync::Arc;
6+
use std::sync::{Arc, RwLock};
77

88
// Fn aliases for assumable, assumption, & assumption collection
99
/// Function type for evaluating numerical values and returning a boolean result.
@@ -39,5 +39,5 @@ pub type CausalFn = fn(effect: &PropagatingEffect) -> Result<PropagatingEffect,
3939
pub type ContextualCausalFn<D, S, T, ST, SYM, VS, VT> =
4040
fn(
4141
effect: &PropagatingEffect,
42-
context: &Arc<Context<D, S, T, ST, SYM, VS, VT>>,
42+
context: &Arc<RwLock<Context<D, S, T, ST, SYM, VS, VT>>>,
4343
) -> Result<PropagatingEffect, CausalityError>;

deep_causality/src/types/causal_types/causaloid/getters.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ where
1616
VS: Clone,
1717
VT: Clone,
1818
{
19-
pub fn context(&self) -> &Option<Arc<Context<D, S, T, ST, SYM, VS, VT>>> {
19+
pub fn context(&self) -> &Option<Arc<RwLock<Context<D, S, T, ST, SYM, VS, VT>>>> {
2020
&self.context
2121
}
2222

deep_causality/src/types/causal_types/causaloid/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ where
3535
causal_type: CausaloidType,
3636
causal_fn: Option<CausalFn>,
3737
context_causal_fn: Option<ContextualCausalFn<D, S, T, ST, SYM, VS, VT>>,
38-
context: Option<Arc<Context<D, S, T, ST, SYM, VS, VT>>>,
38+
context: Option<Arc<RwLock<Context<D, S, T, ST, SYM, VS, VT>>>>,
3939
// The last calculated effect of this causaloid. It's an Option because a
4040
// causaloid may not have been evaluated yet.
4141
effect: ArcRWLock<Option<PropagatingEffect>>,
@@ -90,7 +90,7 @@ where
9090
pub fn new_with_context(
9191
id: IdentificationValue,
9292
context_causal_fn: ContextualCausalFn<D, S, T, ST, SYM, VS, VT>,
93-
context: Arc<Context<D, S, T, ST, SYM, VS, VT>>,
93+
context: Arc<RwLock<Context<D, S, T, ST, SYM, VS, VT>>>,
9494
description: &str,
9595
) -> Self {
9696
Causaloid {
@@ -140,7 +140,7 @@ where
140140
pub fn from_causal_collection_with_context(
141141
id: IdentificationValue,
142142
causal_coll: Arc<Vec<Causaloid<D, S, T, ST, SYM, VS, VT>>>,
143-
context: Arc<Context<D, S, T, ST, SYM, VS, VT>>,
143+
context: Arc<RwLock<Context<D, S, T, ST, SYM, VS, VT>>>,
144144
description: &str,
145145
) -> Self {
146146
Causaloid {
@@ -190,7 +190,7 @@ where
190190
pub fn from_causal_graph_with_context(
191191
id: IdentificationValue,
192192
causal_graph: Arc<CausaloidGraph<Causaloid<D, S, T, ST, SYM, VS, VT>>>,
193-
context: Arc<Context<D, S, T, ST, SYM, VS, VT>>,
193+
context: Arc<RwLock<Context<D, S, T, ST, SYM, VS, VT>>>,
194194
description: &str,
195195
) -> Self {
196196
Causaloid {

deep_causality/src/types/causal_types/causaloid/setters.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
use crate::{Causaloid, Context, Datable, SpaceTemporal, Spatial, Symbolic, Temporal};
7-
use std::sync::Arc;
7+
use std::sync::{Arc, RwLock};
88

99
// Constructors
1010
#[allow(clippy::type_complexity)]
@@ -18,7 +18,7 @@ where
1818
VS: Clone,
1919
VT: Clone,
2020
{
21-
pub fn set_context(&mut self, context: Option<Arc<Context<D, S, T, ST, SYM, VS, VT>>>) {
21+
pub fn set_context(&mut self, context: Option<Arc<RwLock<Context<D, S, T, ST, SYM, VS, VT>>>>) {
2222
self.context = context;
2323
}
2424
}

deep_causality/src/types/csm_types/csm/eval.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ where
143143
if let Some((ethos, tags)) = &self.effect_ethos {
144144
if let Some(context) = state.context() {
145145
let proposed_action = self.create_proposed_action(state, effect)?;
146-
let verdict = ethos.evaluate_action(&proposed_action, context, tags)?;
146+
let context_guard = context.read().unwrap();
147+
let verdict = ethos.evaluate_action(&proposed_action, &context_guard, tags)?;
147148

148149
if verdict.outcome() == TeloidModal::Impermissible {
149150
let explanation = ethos.explain_verdict(&verdict)?;

deep_causality/src/types/csm_types/csm_state/getter.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::{
77
CausalState, Causaloid, Context, Datable, PropagatingEffect, SpaceTemporal, Spatial, Symbolic,
88
Temporal, UncertainParameter,
99
};
10-
use std::sync::Arc;
10+
use std::sync::{Arc, RwLock};
1111

1212
impl<D, S, T, ST, SYM, VS, VT> CausalState<D, S, T, ST, SYM, VS, VT>
1313
where
@@ -36,7 +36,7 @@ where
3636
}
3737

3838
#[allow(clippy::type_complexity)]
39-
pub fn context(&self) -> &Option<Arc<Context<D, S, T, ST, SYM, VS, VT>>> {
39+
pub fn context(&self) -> &Option<Arc<RwLock<Context<D, S, T, ST, SYM, VS, VT>>>> {
4040
self.causaloid.context()
4141
}
4242

deep_causality/src/types/model_types/model/getters.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use crate::{
77
Assumption, Causaloid, Context, Datable, Model, SpaceTemporal, Spatial, Symbolic, Temporal,
88
};
9-
use std::sync::Arc;
9+
use std::sync::{Arc, RwLock};
1010

1111
#[allow(clippy::type_complexity)]
1212
impl<D, S, T, ST, SYM, VS, VT> Model<D, S, T, ST, SYM, VS, VT>
@@ -35,7 +35,7 @@ where
3535
&self.causaloid
3636
}
3737

38-
pub fn context(&self) -> &Option<Arc<Context<D, S, T, ST, SYM, VS, VT>>> {
38+
pub fn context(&self) -> &Option<Arc<RwLock<Context<D, S, T, ST, SYM, VS, VT>>>> {
3939
&self.context
4040
}
4141
}

0 commit comments

Comments
 (0)