Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/source/constraints.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ condition without knowing the details of what that condition is.

my_i = my_cls()

with my_i.randomize()
my_i.randomize()

with my_i.randomize_with() as it:
it.a_small()
Expand Down
1 change: 1 addition & 0 deletions doc/source/features.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ PyVSC Features

Constraint Features

The short-circuit operators, ``and`` and ``or``, in Python can cannot be overloaded by PyVSC and shouldn't be used in constraints.

========================= ====== ============= === ===========
Feature PyVSC SystemVerilog PSS Description
Expand Down
10 changes: 6 additions & 4 deletions src/vsc/model/field_composite_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,15 @@ def pre_randomize(self):

def post_randomize(self):
"""Called during the randomization process to propagate `post_randomize` event"""


# If randomize is called inside post_randomize with caching enabled, which
# value should be written? Prioritize writing current field values before re-randomizing.
for f in self.field_l:
f.post_randomize()

# Perform a phase callback if available
if self.is_used_rand and self.rand_if is not None:
self.rand_if.do_post_randomize()

for f in self.field_l:
f.post_randomize()

def accept(self, v):
v.visit_composite_field(self)
Expand Down
20 changes: 19 additions & 1 deletion src/vsc/model/field_scalar_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#
# @author: ballance

from copy import deepcopy

from vsc.model.field_model import FieldModel
from vsc.model.rand_gen_data import RandGenData
Expand All @@ -44,7 +45,24 @@ def __init__(self,
self.rand_if = rand_if
self.var = None
self.val = ValueScalar(0)


def __deepcopy__(self, memo):
cls = self.__class__
result = cls.__new__(cls)
memo[id(self)] = result
for k, v in self.__dict__.items():
if k not in ['var']:
setattr(result, k, deepcopy(v, memo))

# TODO This is a workaround for the deepcopy in do_randomize somewhere getting
# access to Boolector objects, which in turn can't be deepcopied.
result.var = None

# NOTE Deepcopy everything except val, keep it as reference so top level can get value
result.val = self.val

return result

def set_used_rand(self, is_rand, level=0):
# Field is considered rand when
# - It is a root field, on which 'randomize' is called
Expand Down
4 changes: 3 additions & 1 deletion src/vsc/model/rand_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ class RandState(object):

def __init__(self, seed):
self.rng = random.Random()
self.rng.seed(f"{seed}")
self.init_seed = f"{seed}"
self.rng.seed(self.init_seed)

def clone(self) -> 'RandState':
randState = RandState("")
randState.rng.setstate(self.rng.getstate())
randState.init_seed = self.init_seed
return randState

def rand_u(self):
Expand Down
Loading