DIGITAL DESIGN OPTIMIZATION FROM SCHEMATIC WITH AI
By: Yesha Karathiya
Tags: Opencv Python, Digital Design, Optimization, Shape Detection, AI

The extent of device integration on a single chip has shoot up vigorously since the semiconductor was originated. In reality, it has doubled about every two years for several decades. This development is customarily mentioned to as Moore’s law entitled after Gorden Moore. Presently, it is feasible to integrate more than one billion transistors on a single die. There are predominantly two design obstacles that need to be reviewed as the level of integration increases. The first is related to reducing dimensions of on- chip components and the latter is relative increase in length of interconnection. As the components dimensions are decreased, physical strands which could formerly be dilapidated must now be appraised. The supplementary design challenge that becomes more tangled as component density increases is associated to design complexity. More efficient methods are mandatory as large number of transistors that can be integrated onto a single chip makes design very complex and it is challenging too. The aspiration is that the finalized product should be as optimal as possible in terms of cost, performance and power consumption. The above mentioned purpose is gratified in this solution to optimize digital system design using AI algorithms and CAD tools (algorithms).

Figure 1: Digital design schematic

This proposed solution contains various sections such as a various terminologies for Digital design , optimization techniques for logic building blocks and shape detection algorithm to detect logic blocks. Furthermore it needs to extract text from schematic to know logic function of the block and then after need to optimize it and replace with the original one. Firstly we need to understand terminologies to get idea about given solution.

What is DIGITAL SYSTEM?

A digital system is a system that stores data in a discrete way. Usually, digital systems store the information in a binary way; that is, every bit of information cannot have a value other than zero (off) or one (on). A typical Digital system has four basic functional elements: input-output equipment, main memory, control unit, and arithmetic-logic unit. Any of a number of devices is used to enter data and program instructions into a computer and to gain access to the results of the processing operation. Examples of digital systems are mobile phones, radio, megaphones and many more.

What is SCHEMATIC?

Schematic is a graphical representation of an electrical circuit which is made with different logic blocks or logic gates connected with a wire. it is shown in figure1. DESIGN PROCESS: starts with a word problem, functional specifications and a block diagram. WORD PROBLEM: Design a circuit to select one of two inputs depending on the value of a control variable. FUNCTIONAL SPECIFICATION: It is used to define inputs, outputs, control lines and also describes circuit functions. BLOCK DIAGRAM: It is pictorial and consists of major functional modules and interconnections. we will go step by step to achieve our ultimate goal to optimize circuit which is as below:

Figure 2: flowchart

What is OPTIMIZATION & what we are gonna do?

Design optimization is an engineering design methodology using a mathematical formulation of a design problem to support selection of the optimal design. Design optimization involves the following stages: ~ Variables : Describe the design alternatives ~ Objective: Elected functional combination of variables (to be maximized or minimized) ~ Constraints: Combination of Variables expressed as equalities or inequalities that must be satisfied for any acceptable design alternative ~ Feasibility: Values for set of variables that satisfies all constraints and minimizes/maximizes Objective. Here, design optimization includes three things to be optimized and they are: Firstly, a device should be able to process the input at faster rate which provides the higher frequency required. Secondly, a device should consume very low area which helps to reduce the cost of the system. Thirdly, device should consume very low power (LPC). Area optimization can also be done by Logical optimization. Logical optimization: It is the process of finding an equivalent representation of the specified logic circuit under one or more specified constraints. Generally the circuit is constrained to minimum chip area meeting a specified delay. The problem with having a complicated circuit is that each element takes up physical space in its implementation and costs time and money to produce in itself. Circuit minimization may be one form of logic optimization used to reduce the area of complex logic in integrated circuits. While there are many ways to minimize a circuit, this is an example that minimizes a Boolean function.

Let’s Visualize problem statement and proposed solution:-

Consider the circuit used to represent some Boolean expression which includes two AND gates and one OR gate, that can simplified by just using one WIRE as shown in the below figure. This leads to less number of gates used in the circuit that results in area optimization (less space occupied) and faster processing of input i.e. speed is increased and consumes less time to deliver output which provides higher frequency.

Figure 3: Schematic 1

Where O= AB + A~B; I.e. Output O is logical Oring between U1 and U2. Where U1= AB; I.e. Output U1 is logical Anding between A and B. Where U2=A~B; I.e. Output U2 is logical Anding between A and negated B.

Figure 4: schematic 2

By using Minimizing Technique of Boolean Algebra; Output O= AB + A~B = A(B + ~B) =A This design is more optimized than previous one so previous design will be replaced by optimized design.

OpenCV Shape Detection from the schematic

What are contours?

Contours can be explained simply as a curve joining all the continuous points (along the boundary), having same color or intensity. The contours are a useful tool for shape analysis and object detection and recognition. A contour is a closed curve joining all the continuous points having some color or intensity, they represent the shapes of objects found in an image. Contour detection is a useful technique for shape analysis and object detection and recognition.

Figure 5: Contours

Contour approximation is predicated on the assumption that a curve can be approximated by a series of short line segments. This leads to a resulting approximated curve that consists of a subset of points that were defined by the original curve. Contour approximation is actually already implemented in OpenCV via the cv2.approxPolyDP method

Let’s find logic blocks with OpenCv

Figure 6: im2.png , input schematic

Firstly we are importing necessary libraries which we will gonna use afterwords.

# import the necessary packages



import argparse

import imutils

import cv2

from google.colab.patches import cv2_imshow

Here i used google colab to implement project. So we need to import drive from google colab as input images are stored in my google drive.

from google.colab import drive #to import google drive data drive.mount('/content/drive') #to mount the drive data into colab cloud and enter the activation code cd /content/drive/"My Drive"

let’s pre-process our image:

Load the image and resize it to a smaller factor so that the shapes can be approximated better.

image = cv2.imread("AI/im2.png") resized = imutils.resize(image, width=300) ratio = image.shape[0] / float(resized.shape[0])

convert the resized image to grayscale, blur it slightly, and threshold it.

gray = cv2.cvtColor(resized, cv2.COLOR_BGR2GRAY) blurred = cv2.GaussianBlur(gray, (5, 5), 0) thresh = cv2.threshold(blurred, 60, 255, cv2.THRESH_BINARY)[1]

Defining our shape detector

class ShapeDetector: def __init__(self): pass def detect(self, c): # initialize the shape name and approximate the contour shape = "unidentified" peri = cv2.arcLength(c, True) approx = cv2.approxPolyDP(c, 0.04 * peri, True)

# if the shape is a triangle, it will have 3 vertices if len(approx) == 3: shape = "triangle" # if the shape has 4 vertices, it is either a square or a rectangle elif len(approx) == 4: # compute the bounding box of the contour and use the # bounding box to compute the aspect ratio (x, y, w, h) = cv2.boundingRect(approx) ar = w / float(h) # a square will have an aspect ratio that is approximately # equal to one, otherwise, the shape is a rectangle shape = "square" if ar >= 0.95 and ar <= 1.05 else "rectangle" # if the shape is a pentagon, it will have 5 vertices elif len(approx) == 5: shape = "pentagon" # otherwise, we assume the shape is a circle else: shape = "circle" # return the name of the shape return shape

In order to perform shape detection, we’ll be using contour approximation. It’s important to understand that a contour consists of a list of vertices. We can check the number of entries in this list to determine the shape of an object. For example, if the approximated contour has three vertices, then it must be a triangle . If a contour has four vertices, then it must be either a square or a rectangle . To determine which, we compute the aspect ratio of the shape, which is simply the width of the contour bounding box divided by the height. If the aspect ratio is ~1.0, then we are examining a square (since all sides have approximately equal length). Otherwise, the shape is a rectangle. If a contour has five vertices, we can label it as a pentagon. Otherwise, by process of elimination (in context of this example, of course), we can make the assumption that the shape we are examining is a circle . Finally, we return the identified shape to the calling method.

find contours in the thresholded image and initialize the shape detector

cnts = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE) cnts = imutils.grab_contours(cnts) sd = ShapeDetector()

Loop over the contours

for c in cnts: # compute the center of the contour, then detect the name of the # shape using only the contour M=cv2.moments(c) if(M["m00"]== 0): M["m00"]=0.01 cX=int((M["m10"] / M["m00"]) * ratio) cY=int((M["m01"] / M["m00"]) * ratio) shape=sd.detect(c) # multiply the contour (x, y)-coordinates by the resize ratio, # then draw the contours and the name of the shape on the image c = c.astype("float") c *= ratio c = c.astype("int") cv2.drawContours(image, [c], -1, (0, 255, 0), 2) cv2.putText(image, shape, (cX, cY), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 255, 255), 2) # show the output image cv2_imshow(image) cv2.waitKey(0)

we start looping over each of the individual contours. For each of them, we compute the center of the contour, followed by performing shape detection and labeling. Since we are processing the contours extracted from the resized image (rather than the original image), we need to multiply the contours and center (x, y)-coordinates by our resize ratio. This will give us the correct (x, y)-coordinates for both the contours and centroid of the original image. Lastly, we draw the contours and the labeled shape on our image , followed by displaying our results.

Result

Figure 7: Final output with shape detection

The above proposed was implemented in Python on google colab to preprocess schematic. Shape detection technique detects shape of the logic blocks so we can identify which logic is implemented. After this I am looking forward to do text extraction from the schematic to get knowledge about logic implemented. So that we can optimize logic and replace in the main circuit. As the technology is going on developing day by day, we prefer things to be done automatically with less human interference, so a cheap and effective way of getting things done can be implemented using this digital system which is advantageous in all the aspects due to support of optimization technologies which includes less power consumption, reduced area, higher speed, low latency, reduced delay, increased frequency and much more.

Hey we did it!!

Thank you for reading . Hope it may useful in your work . For more detailed explanation please visit my video .

Resources