File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -583,6 +583,11 @@ cdef class ForbiddenCallableRelation(ForbiddenRelation):
583
583
The ForbiddenCallable uses two hyperparameters as input to a
584
584
specified callable, which returns True if the relationship
585
585
between the two hyperparameters is forbidden.
586
+
587
+ A ForbiddenCallableRelation may not be serializable.
588
+ :func:`ConfigSpace.read_and_write.write` will attempt to pickle and base64 encode
589
+ the callable with pickle_callables=True. However, the unpicklability
590
+ of the callable cannot be assured.
586
591
587
592
>>> from ConfigSpace import ConfigurationSpace, ForbiddenCallableRelation
588
593
>>>
Original file line number Diff line number Diff line change 1
1
import os
2
2
import unittest
3
+ from dataclasses import dataclass
3
4
4
- from ConfigSpace .forbidden import ForbiddenLessThanRelation
5
+ from ConfigSpace .forbidden import ForbiddenLessThanRelation , ForbiddenCallableRelation
5
6
from ConfigSpace .read_and_write .json import read , write
6
7
from ConfigSpace .read_and_write .pcs import read as read_pcs
7
8
from ConfigSpace .read_and_write .pcs_new import read as read_pcs_new
12
13
)
13
14
14
15
16
+ @dataclass
17
+ class ProductGreaterThan :
18
+ limit : int
19
+
20
+ def __call__ (self , a , b ):
21
+ return a * b > self .limit
22
+
23
+
15
24
class TestJson (unittest .TestCase ):
16
25
17
26
def test_serialize_forbidden_in_clause (self ):
@@ -27,6 +36,10 @@ def test_serialize_forbidden_relation(self):
27
36
cs .add_forbidden_clause (ForbiddenLessThanRelation (a , b ))
28
37
write (cs )
29
38
39
+ cs .add_forbidden_clause (ForbiddenCallableRelation (a , b , ProductGreaterThan (3 )))
40
+ self .assertRaises (ValueError , write , cs )
41
+ write (cs , pickle_callables = True )
42
+
30
43
def test_configspace_with_probabilities (self ):
31
44
cs = ConfigurationSpace ()
32
45
cs .add_hyperparameter (
You can’t perform that action at this time.
0 commit comments