Predict
Prediction functions for ndarrays of device geometries.
predict_array(device_array, model, model_type, binarize)
Predict the nanofabrication outcome of a device array using a specified model.
This function sends the device array to a serverless prediction service, which uses a specified machine learning model to predict the outcome of the nanofabrication process.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
device_array
|
ndarray
|
A 2D array representing the planar geometry of the device. This array undergoes various transformations to predict the nanofabrication process. |
required |
model
|
Model
|
The model to use for prediction, representing a specific fabrication process and
dataset. This model encapsulates details about the fabrication foundry, process,
material, technology, thickness, and sidewall presence, as defined in
|
required |
model_type
|
str
|
The type of model to use (e.g., 'p' for prediction, 'c' for correction, or 's' for SEMulate, 'b' for segmentation). |
required |
binarize
|
bool
|
If True, the predicted device geometry will be binarized using a threshold method. This is useful for converting probabilistic predictions into binary geometries. |
required |
Returns:
Type | Description |
---|---|
ndarray
|
The predicted output array. For single-level predictions, returns shape (h, w, 1). For multi-level predictions, returns shape (h, w, n) where n is the number of levels. |
Raises:
Type | Description |
---|---|
RuntimeError
|
If the request to the prediction service fails. |
ValueError
|
If the server returns an error or invalid response. |
Source code in prefab/predict.py
predict_array_with_grad(device_array, model)
Predict the nanofabrication outcome of a device array and compute its gradient.
This function predicts the outcome of the nanofabrication process for a given device array using a specified model. It also computes the gradient of the prediction with respect to the input device array, making it suitable for use in automatic differentiation applications (e.g., autograd).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
device_array
|
ndarray
|
A 2D array representing the planar geometry of the device. |
required |
model
|
Model
|
The model to use for prediction, representing a specific fabrication process. |
required |
Returns:
Type | Description |
---|---|
ndarray
|
The predicted output array. |
Raises:
Type | Description |
---|---|
RuntimeError
|
If the request to the prediction service fails. |
ValueError
|
If the server returns an error or invalid response. |
Source code in prefab/predict.py
predict_array_with_grad_vjp(ans, device_array, *args)
Define the vector-Jacobian product (VJP) for the prediction function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ans
|
ndarray
|
The output of the |
required |
device_array
|
ndarray
|
The input device array for which the gradient is computed. |
required |
*args
|
Additional arguments that aren't used in the VJP computation. |
()
|
Returns:
Type | Description |
---|---|
function
|
A function that computes the VJP given an upstream gradient |
Source code in prefab/predict.py
predict_gds(gds_path, cell_name, model, model_type, gds_layer=(1, 0), eta=0.5, output_path=None)
Predict the nanofabrication outcome for a GDS file and cell.
This function loads a GDS file, extracts the specified cell, and predicts the nanofabrication outcome using the specified model. The predicted cell is automatically added to the original GDS library and the file is written to the specified output path (or overwrites the original if no output path is provided).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
gds_path
|
str
|
The file path to the GDS file. |
required |
cell_name
|
str
|
The name of the cell within the GDS file to predict. |
required |
model
|
Model
|
The model to use for prediction, representing a specific fabrication process and
dataset. This model encapsulates details about the fabrication foundry, process,
material, technology, thickness, and sidewall presence, as defined in
|
required |
model_type
|
str
|
The type of model to use ('p' for prediction, 'c' for correction). |
required |
gds_layer
|
tuple[int, int]
|
The layer and datatype to use within the GDS file. Defaults to (1, 0). |
(1, 0)
|
eta
|
float
|
The threshold value for binarization. Defaults to 0.5. Because intermediate values cannot be preserved in the polygon data, the predicted polygons are binarized using a threshold value of eta. |
0.5
|
output_path
|
str
|
The file path where the updated GDS file will be written. If None, the original file will be overwritten. Defaults to None. |
None
|
Raises:
Type | Description |
---|---|
RuntimeError
|
If the request to the prediction service fails. |
ValueError
|
If the GDS file cannot be read, the specified cell is not found, or the server returns an error or invalid response. |
Source code in prefab/predict.py
predict_gdstk(gdstk_cell, model, model_type, gds_layer=(1, 0), eta=0.5)
Predict the nanofabrication outcome of a gdstk cell using a specified model.
This function extracts polygons from a gdstk cell, sends them to a serverless prediction service, and returns a new cell containing the predicted polygons.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
gdstk_cell
|
Cell
|
The gdstk.Cell object containing polygons to predict. |
required |
model
|
Model
|
The model to use for prediction, representing a specific fabrication process and
dataset. This model encapsulates details about the fabrication foundry, process,
material, technology, thickness, and sidewall presence, as defined in
|
required |
model_type
|
str
|
The type of model to use ('p' for prediction, 'c' for correction). |
required |
gds_layer
|
tuple[int, int]
|
The layer and datatype to use within the GDSTK cell. Defaults to (1, 0). |
(1, 0)
|
eta
|
float
|
The threshold value for binarization. Defaults to 0.5. Because intermediate values cannot be preserved in the polygon data, the predicted polygons are binarized using a threshold value of eta. |
0.5
|
Returns:
Type | Description |
---|---|
Cell
|
A new gdstk cell containing the predicted polygons. For multi-level predictions, each level's polygons will be placed on a different layer: - Level 0: (layer, 99) - Level 1: (layer, 100) |
Raises:
Type | Description |
---|---|
RuntimeError
|
If the request to the prediction service fails. |
ValueError
|
If no polygons are found in the specified layer, or the server returns an error or invalid response. |
Source code in prefab/predict.py
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 |
|