Constraint solver failure on a rand variable with rand_mode(0)

Hi everyone,

I’ve encountered the following failure:

Solver failed when solving following set of constraints
bit[31:0] id = 32’h0;
rand packet_direction_vt my_variable= TRANSMIT; // rand_mode = OFF
constraint my_variable_c // (from this) (constraint_mode = ON)
{
((id % 2) == 0) → my_variable== RECEIVE;
}

Here is a representation of my code:

typedef enum {
    RECEIVE  = 0,
    TRANSMIT = 1
} packet_direction_vt;

class base_class extends uvm_object;
  
    rand packet_direction_vt my_variable;
    int id;
    
    constraint my_variable_c {((id % 2) == 0) -> my_variable== RECEIVE;}

endclass : base_class

class extended_class extends base_class; // Overriding the base_class in my test, using UVM factory

    function void pre_randomize();
        super.pre_randomize();
 
        my_variable.rand_mode(0);

        my_variable = TRANSMIT;

    endfunction : pre_randomize

endclass : extended_class

class my_env extends uvm_component;

    function create_class();
        
        base_class my_base_class_object;

        my_base_class_object.randomize(); // Fail on this line !

    endfunction : create_class

endclass : my_env

Please note that the base_class is overriden with the extended_class using UVM factory.

Could someone explain me why I am failing on a constraint solver issue, despite the fact that my variable is set as rand_mode(0) ?

Thanks in advance

In reply to rubendah:

Constraints remain active regardless of whether they contain active random variables or not. You need to turn off my_variable_c.constraint_mode(0). I suggest turning off the modes in the class constructor.

In reply to rubendah:

Here id which is of int data type will have default value 0 which is an even number.

The constraint says if id is even, my_variable should be receive, but as the rand mode is turned off & the value assigned to my variable is transmit conflicts with the constraint. So the randomize is failed.

Thanks & Regards,
Shanthi
www.maven-silicon.com

Thanks for your quick responses !