gfn.gym.chip_design¶
GFlowNet environment for chip placement.
Classes¶
GFlowNet environment for chip placement. |
|
A class to represent the states of the chip design environment. |
|
Pre-computed cost statistics for a netlist. |
Module Contents¶
- class gfn.gym.chip_design.ChipDesign(netlist_file=SAMPLE_NETLIST_FILE, init_placement=SAMPLE_INIT_PLACEMENT, std_cell_placer_mode='fd', wirelength_weight=1.0, density_weight=1.0, congestion_weight=0.5, device=None, debug=False, singularity_image=None, cd_finetune=True, reward_norm=None, reward_temper=1.0, reward_norm_samples=100, cost_stats=None)¶
Bases:
gfn.env.DiscreteEnvGFlowNet environment for chip placement.
The state is a vector of length n_macros, where state[i] is the grid cell location of the i-th macro to be placed. Unplaced macros have a location of -1.
Actions are integers from 0 to n_grid_cells - 1, representing the grid cell to place the current macro on. Action n_grid_cells is the exit action.
- Parameters:
netlist_file (str)
init_placement (str)
std_cell_placer_mode (str)
wirelength_weight (float)
density_weight (float)
congestion_weight (float)
device (str | None)
debug (bool)
singularity_image (Optional[str])
cd_finetune (bool)
reward_norm (Optional[str])
reward_temper (float)
reward_norm_samples (int)
cost_stats (Optional[CostStats])
- States: type[ChipDesignStates]¶
- __del__()¶
- Return type:
None
- _apply_state_to_plc(state_tensor)¶
Applies a single state tensor to the plc object.
- Parameters:
state_tensor (torch.Tensor)
- _backward_step(states, actions)¶
Wraps parent _backward_step and updates masks.
- Parameters:
states (gfn.states.DiscreteStates)
actions (gfn.actions.Actions)
- Return type:
- _estimate_cost_stats(n_samples)¶
Estimates cost distribution from random placements.
- Parameters:
n_samples (int)
- Return type:
None
- _hard_macro_indices¶
- _normalize_cost(cost)¶
Applies reward normalization to a raw cost value.
- Parameters:
cost (float)
- Return type:
float
- _sorted_node_indices¶
- _step(states, actions)¶
Wraps parent _step and updates masks.
- Parameters:
states (gfn.states.DiscreteStates)
actions (gfn.actions.Actions)
- Return type:
- analytical_placer()¶
Places standard cells using an analytical placer.
- backward_step(states, actions)¶
Performs a backward step in the environment.
- Parameters:
states (ChipDesignStates)
actions (gfn.actions.Actions)
- Return type:
- cd_finetune = True¶
- close()¶
Closes the PlacementCost subprocess to free resources.
- Return type:
None
- congestion_weight = 0.5¶
- density_weight = 1.0¶
- log_reward(final_states)¶
Computes the log reward of the final states.
- Parameters:
final_states (ChipDesignStates)
- Return type:
torch.Tensor
- make_states_class()¶
Creates the ChipDesignStates class.
- Return type:
type[ChipDesignStates]
- n_grid_cells¶
- n_macros¶
- plc¶
- reset(batch_shape, random=False, sink=False, seed=None, conditions=None)¶
Resets the environment and computes initial masks.
- Parameters:
batch_shape (int | Tuple[int, Ellipsis])
random (bool)
sink (bool)
seed (Optional[int])
conditions (Optional[torch.Tensor])
- Return type:
- reward_norm = None¶
- reward_temper = 1.0¶
- std_cell_placer_mode = 'fd'¶
- step(states, actions)¶
Performs a forward step in the environment.
- Parameters:
states (ChipDesignStates)
actions (gfn.actions.Actions)
- Return type:
- update_masks(states)¶
Updates the forward and backward masks of the states.
- Parameters:
states (ChipDesignStates)
- Return type:
None
- wirelength_weight = 1.0¶
- class gfn.gym.chip_design.ChipDesignStates(tensor, current_node_idx=None, conditions=None, device=None, debug=False)¶
Bases:
gfn.states.DiscreteStatesA class to represent the states of the chip design environment.
- Parameters:
tensor (torch.Tensor)
current_node_idx (Optional[torch.Tensor])
conditions (Optional[torch.Tensor])
device (Optional[torch.device])
debug (bool)
- __getitem__(index)¶
Gets a subset of the states.
- Return type:
- __setitem__(index, value)¶
Sets a subset of the states.
- Parameters:
value (ChipDesignStates)
- Return type:
None
- clone()¶
Creates a copy of the states.
- Return type:
- current_node_idx = None¶
- extend(other)¶
Extends the states with another states.
- Parameters:
other (ChipDesignStates)
- Return type:
None
- n_actions: ClassVar[int]¶
- s0: ClassVar[torch.Tensor]¶
- sf: ClassVar[torch.Tensor]¶
- classmethod stack(states)¶
Stacks the states with another states.
- Parameters:
states (Sequence[ChipDesignStates])
- Return type:
- state_shape: ClassVar[tuple[int, Ellipsis]]¶
- class gfn.gym.chip_design.CostStats¶
Pre-computed cost statistics for a netlist.
- mean: float¶
- min: float¶
- static precompute(netlists, n_samples=100, wirelength_weight=1.0, density_weight=1.0, congestion_weight=0.5, singularity_image=None)¶
Pre-compute cost statistics for multiple netlists.
- Parameters:
netlists (List[Tuple[str, str]]) – List of
(netlist_file, init_placement)tuples.n_samples (int) – Number of random placements per netlist.
wirelength_weight (float) – Wirelength weight for cost computation.
density_weight (float) – Density weight for cost computation.
congestion_weight (float) – Congestion weight for cost computation.
singularity_image (Optional[str]) – Optional singularity image path.
- Returns:
Dict mapping netlist file paths to their
CostStats.- Return type:
Dict[str, CostStats]
- range: float¶
- std: float¶