Skip to content

Commit cc0f365

Browse files
committed
Add initial rand seed to call hash string
Sometimes the rand stability test would fail due to a call hash repeating triggering the cache_enabled path. This is probably due to the randstate obj ID being reused, so this adds the initial seed to that as well. Not sure if this is the proper fix yet.
1 parent c22f9a0 commit cc0f365

3 files changed

Lines changed: 9 additions & 5 deletions

File tree

src/vsc/model/rand_state.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ class RandState(object):
99

1010
def __init__(self, seed):
1111
self.rng = random.Random()
12-
self.rng.seed(f"{seed}")
12+
self.init_seed = f"{seed}"
13+
self.rng.seed(self.init_seed)
1314

1415
def clone(self) -> 'RandState':
1516
randState = RandState("")
1617
randState.rng.setstate(self.rng.getstate())
18+
randState.init_seed = self.init_seed
1719
return randState
1820

1921
def rand_u(self):

src/vsc/model/randomizer.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
from vsc.model.rand_if import RandIF
4444
from vsc.model.rand_info import RandInfo
4545
from vsc.model.rand_info_builder import RandInfoBuilder
46+
from vsc.model.rand_state import RandState
4647
from vsc.model.variable_bound_model import VariableBoundModel
4748
from vsc.visitors.array_constraint_builder import ArrayConstraintBuilder
4849
from vsc.visitors.constraint_override_rollback_visitor import ConstraintOverrideRollbackVisitor
@@ -553,7 +554,7 @@ def _collect_failing_constraints(self,
553554

554555
@staticmethod
555556
def do_randomize(
556-
randstate,
557+
randstate: RandState,
557558
srcinfo : SourceInfo,
558559
field_model_l : List[FieldModel],
559560
constraint_l : List[ConstraintModel] = None,
@@ -705,9 +706,10 @@ def do_randomize(
705706

706707

707708
@staticmethod
708-
def get_pretty_call_hash(randstate, field_model_l, constraint_l):
709+
def get_pretty_call_hash(randstate: RandState, field_model_l, constraint_l):
709710
call_hash = ''
710711
call_hash += f'{hex(id(randstate))}\n'
712+
call_hash += f'{randstate.init_seed=}\n'
711713
if field_model_l is not None:
712714
for fm in field_model_l:
713715
# TODO This pretty print is an expensive call. Need a better way

ve/unit/test_constraint_dist.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ def show_it(obj, rs):
690690
print()
691691

692692
def run_obj(obj):
693-
cnt = 6
693+
cnt = 100
694694

695695
print(f'Using {type(obj).__name__}')
696696
print('------------------')
@@ -703,4 +703,4 @@ def run_obj(obj):
703703
obj = With_Dist()
704704
run_obj(obj)
705705

706-
706+

0 commit comments

Comments
 (0)