Fast food chains:

Below I'm listing some fast food chains and the vegetarian menu iems available at those chains, that me or my kids liked. These were reasonably priced, and filling enough and not too bad in taste I guess (since my kids finshed them w/o complaining) !! If you are looking for dine in formal restaurants, check out the "restaurant" section.

 

Mcdonalds:

A couple of options here. One of them is pie - Apple pie, pumpkin pie, etc. These sell for about $1 including tax. These are filling enough where 1 pie is good for one kid.

Macdonalds GC are not on sale that often. I've bough these GC on sale for 20% off at HEB, grocery chain in Texas. I usually buy enough that will last me a couple of years, considering I spend < $50 a year at Mcdonalds.

 

Chipotle:

Here you can get cheap mexican food. Nothing fancy about the food. It's filling and it costs < $10. You can buy Chipotle GC for 20% off couple of times a year at grocery stores, amazon, paypal, drug stores, etc. They also have BOGO offers from time to time. If you make an account at chipotle, and don't have any activity on your online account, then they will drop you few offers from time to time. I've gotten few BOGO offers that way. Sometimes they will have online quizzes and first 10K or so get BOGO offers (you can search for these on slickdeals). On an avg, BOGO offers are may be 1-2 times a year.

 

Subway:

Subway is one of the cheapest fast Food restaurant. They primarily serve sandwiches - veggie and meat. Their veggie sandwiches are really great.

Regularly you can get their GC for 20% off ($50 GC for $40). Couple of times a year, subway.com itself gives these out. Sometimes they are available on sale at grocery stores, paypal website, etc. On top of that, Subway usually has Buy 1, Get 1 Free (BOGO) offer. Normally their foot long sandwiches are $7, but with this promo, they give you 2 subway for the price of $7 or less. You also get 2 free cookies for filling survey. With 20% off GC, and rewards you earn + free cookies with survey, you end up getting two 1 foot subs for < $5. Not sure if you can make it that cheap at home. Make it 2X for all the fillings to make it twice as many calories. 2 footlong subs are good to feed 4 people, or < $1.25 per person per meal. Can't get any cheaper than that !! For the rewards, you will need to make an account at subway.com.

For vegetarian sandwiches - you can get veggie patties too to go in between the sandwiches. It will cost a dollar extra, but it's well worth the price. It tastes really good, and is very high in protein and calories - fills you up really well. Subway is my favorite fast food go to place, as it gives you the best value per dollar.

 

Dominos Pizza:

Dominos pizza is the cheapest Pizza chain (among the big pizza chain - Papa Johns, Pizza Hut and Dominos).

You can regularly get $25 Dominos GC for $20. They are available on sale at grocery stores, paypal website, etc. It's the most readily available sale of all the fast food GC sale. Dominos also has rewards program where you earn 10 points for every order $10 or more. 60 points gets you a free Medium 2 topping pizza. So, $60 in spending gets you $6 worth of pizza, or equivalent to 10% cashback.

For medium pizza, Dominos always has the deal: $5.99 $6.99 (prices raised in 2023) each when you buy 2, with 2 toppings each. You can also add more items for $5.99 $6.99 each (doesn't have to be pizza. this applies to even the first 2 items).

For large pizza, Dominos always has the deal: $7.99 for a large pizza with 3 toppings (as of 2022). Price for large pizza remained the same for 2023, but number of toppings has gone down from 3 to 1.

There's a deal every once in a while, where you get max of 7 toppings on a large pizza for $10 only. This is a great deal, and I'll share it below when available.

Below are different Pizza offered by Dominos:

1. Medium/Large Hand Tossed Pizza: This pizza is available in both medium and large.  It has 190 calories/slice. So total for 8 slices = 190*8=1500 calories per pizza. This is second favorite crust at my home after the "Crunchy Thin crust" pizza.

2. Medium/Large Crunchy Thin crust pizza: This pizza is available in both medium and large. This is very thin crust and crunchy. This is the best tasting pizza, but also has the fewest calories.

3. Medium Handmade pan pizza: This pizza is only available in medium as it's crust is very thick. It Costs $2 extra. So, medium pizza will cost $7.99 $8.99 (as of 2023). It has 310 calories/slice. So total for 8 slices = 310*8=2500 calories per pizza. It has significantly more calories, as it has much thicker crust. This is more filling but not as tasty.

 

Papa Johns Pizza:

Papa Johns pizza is the most popular pizza, but it's little bit more expensive than Dominos pizza.Papa Johns also has their reward program, where you get 1 point for every dollar spent. When you reach 75 points, you get $10 worth of dough that you can use on getting free pizza or anything under $10. So, $75 in spending gets you $10 worth of pizza, or equivalent to 15% cash back.

For medium pizza, Papa Johns always has the deal: $6.99 each when you buy 2, with 1 topping each. You can also add more items for $7 each (doesn't have to be pizza. this applies to even the first 2 items).

For large pizza, Papa Johns always has the deal: $8.99 for a large pizza with 1 topping. However this is location specific, and may be higher or lower.

Their large pizza is 2200 cal, while medium is 1500 cal (almost same as that at Dominos).

Some added bonus with Papa Johns pizza:

  • They include 1 garlic sauce + 1 banana pepper free with each veg pizza.
  • They give unlimited packets of cheese and pepper.
  • They have base which you may choose to be cheese, meat or veg. If you choose veg, the base itself will have vegetables in it (toppings that you choose will be in the base too). That seems to make it yummier.
  • The large pizza is $1 more expensive than Dominos, but when you consider the free items included, it's almost at par with Dominos.

 

Taco Bell:

Taco Bell is a very popular mexican food place. It used to be cheap, but is getting pricier now. Burritos, Nachos and Tacos are the most popular mexican food in these fast food places. Few popular veg menu items:

  • Cheese Quesadilla => It costs about $4 and has 500 calories. It's favorite of my younger one.
  • Veg Burrito => Burritos are things with veg/beans filled inside and wrapped around the tortilla. Few varieties are Bean burrito, rice and bean burrito and Fiesta Veggie burrito. Burritos are the cheapest items on Taco Bell's menu. They cost between $1-$2 and provide around 500 cal of energy.
  • Nachos => Nachos is one other very favorite mexican dish. It's basically chips with beans, cream, veg, etc spread on it. It tastes nice. However, it's expensive as it's not very filling, and costs about $5. Nachos Bell Grande costs about $5 and has 750 cal.
  • Tacos =>  Tacos are crsipy or soft shell filled with beans, veg, etc. Nacho Cheese Doritos Locos Tacos cost about $2.50 and has 170 cal, so per calorie it's expensive. Cheapest item here is "spicy potato soft taco" costing a dollar. Tacos in general do taste good.

Taco Bell has offers on their website all the time, where you can get a combo or a box with more items in it for a lower price. However, you get those prices, only when ordering thru the app. So, always look on their website or app for offers before ordering (check in offers/rewards section of their app). They also have free items from time to time.

 

IHOP:

Another fast food chain. It sells pancakes which are decent price. Their pancakes are very filling. They also have kids menu, which is cheaper. It's good chain when your kids are bored with everything else, and you just want to try something different. Tmobile thru it's Tmobile Tuesday app offers free pancakes at IHOP from time to time.

You can get IHOP GC for 20% off a couple of times in grocery stores, amazon, etc.

 

 


 

DEALS:

 

All Gift Card deals for fast food are in gift card section. Consider buying those GC where possible and then get these deals.

 

 

 


 

Subway Offer - BOGO (select restaurants) offer multiple times a year => expires every few months

https://slickdeals.net/f/16059892-subway-buy-one-footlong-get-one-free-w-code-ymmv

The deal always shows up with new promo code (or some older code). Every time it comes, it's valid for 1-2 months. Need to order online or from app. Best value is 2 foot long sub for $7 (Now $8 as of 2023). The ones with veggie patty in it go for about $10. You also get rewards if you have signed up, which equates to $2 every 4-5 of BOGO orders. Not bad :)

UPDATE Sept 2025: Subway doesn't have veggie patty at any of the stores anymore. Their website errors out most of the times with "access denied" error. Their app also has glitches, where it will shut down saying "encountered problem" or seem to be stuck or very slow during order placement. On final screen after placing the order it will be processing and seem to be stuck, but on refreshing (by swiping on the app from top to bottom), it will show that the order went thru. With all these issues, not sure if it's worth the food.

NOTE: Many codes of subway still work many times even though they expired a whileback. Try these codes if you can't find a code:

  • B2GO codes (3 Footlong): FTL1799
  • BOGO codes (2 Footlong): BOGOFTL, FREEFL, FLBOGO, FTLBOGO, FTL1299, FL1299, 1299FL, FL1399, FOOTLONG (need to add drink),
  • Individual codes (1 Footlong): FTL699,

Deals:

 


 

Dominos Offer - multiple times a year => expires in a week or so 

Noteworthy offers:

 

 


  

 

2026:

 

 


 

02/12/2026: IHOP Offer - Free Pancake on 03/03/2026 => valid from 7AM to 8PM

https://www.doctorofcredit.com/ihop-free-short-stack-of-pancakes-3-4-25/

Free on 03/03/2026 (NOT today), which happens to be a Tuesday. Mark your calendars. I've always gotten free ones without any hassles.

 


 

 

2025:

 

 


 

12/03/2025: Chipotle Offer - BOGO on multiple days => valid after 4pm on 12/06/2025, 12/13/2025 and 12/20/2025

https://www.doctorofcredit.com/chipotle-bogo-after-4pm-on-12-6-12-13-12-20/

Follow directions on what is free when.

 


 

07/22/2025: Pizza Hut Offer - 1 Topping Personal Pan Pizza for $2 (limit 4) => every Tuesday

https://slickdeals.net/f/18475066-pizza-hut-select-locations-1-topping-personal-pan-pizza-2-valid-for-carryout-only-till-promotion-ends-tuesday-s-only?src=frontpage

Not all locations, and ones which have may be sold out quickly.

 


 

02/14/2025: 7-11 Offer - Free Slurpee every Friday in Feb (No app needed) => expires end of Feb

https://www.doctorofcredit.com/7-eleven-free-slurpee-friday-during-february-2025/

No app needed. Just walk in and get a small slurpee for free.

 


 

02/10/2025: Dominos Offer - Large 7 topping Pizza for $10 => expires 03/02/2025

https://slickdeals.net/f/18111496-domino-s-pizza-large-any-crust-any-toppings-pizza-10-valid-thru-3-2-for-online-purchase-only

Great deal after a long time. These 7 toppings themselves are worth $5.

 


 

01/07/2025: Taco bell Offer - BOGO or free item on app  => expires 01/13/2025

https://slickdeals.net/f/18042708-taco-bell-rewards-members-cravings-value-menu-b1g1-free-cantina-chicken-bowl-5-more-in-app-at-participating-locations?src=frontpage

There are multiple choices. "Love" which gives you a BOGO item for anything on "cravings menu" is the best deal, since you get $3 free item.  On app only. You have 7 days from the day you choose your offer to redeem it, so if you sign up on 01/13/25, you have until 01/20/25 to use it.

 


 

 

2024:

 

 


 

08/20/2024: Chipotle Offer - BOGO by answering quiz questions => valid from 08/20/2024 - 08/22/2024

https://slickdeals.net/f/17702445-chipotle-coupon-offer-burrito-bowl-salad-or-tacos-bogo-free-w-quiz-limited-availability-daily-thru-8-22

The answers to the quiz for each day are provided in the comments section. Offer is thru out the day, but BOGO is given every hour to first few folks, so try right on the hour. If you get only 25 points and no BOGO showed up, then you missed your chance as you will not be eligible any more for that day. Try again another day. The code is valid instore, online and from app.

 


 

08/10/2024: Cici's Pizza - Buffet for $5 only (valid on Mondays and Tuesdays only) => expires Nov 12, 2024

Valid on Dine in only on Mondays and Tuesdays. Great deal, since Buffet includes not only pizza, but also desert, salads, etc. You can also ask them to make you a custom pizza with your selected topping for no additional price. Do NOT waste please.

https://slickdeals.net/f/17683254-cicis-pizza-brings-back-4-99-buffet-on-mondays-and-tuesdays-until-november-12-2024-in-store-coupon-code-23063-show-coupon-before-ordering

 


 

07/01/2024: 7-Eleven Stores - Free small slurpee only on 07/11 (Thursday) => expires July 11, 2024

Valid only on 07/11. This offer comes every year on 07/11. No app requirement. Just show up in store and get one.  7-eleven is a gas station chain and may not have a presence in all the states.

https://www.doctorofcredit.com/7-eleven-free-small-slurpee-7-11-only/

 


 

04/28/2024: Taco Bell - Discovery box for $5, valid only on Tuesdays => expires June 4, 2024

Valid only on Tuesday.  3 different types of tacos included for $5. You can swap as well as customize to make it veg only (by substituting chicken with beans). Make sure you swap that basic crunchy taco for another Doritos Loco or even a soft taco supreme for free. Makes it an even better deal.

https://slickdeals.net/f/17449566-participating-taco-bell-restaurants-taco-discovery-box-5-tuesdays-only-through-june-4?src=frontpage

 


 

04/22/2024: Dominos Offer - Large 2 topping Pizza for $7 => expires 04/28/2024

https://slickdeals.net/f/17446341-domino-s-pizza-large-2-topping-pizza-6-99-carryout-only

 


 

01/24/2024: Dominos Offer - Large 2 topping Pizza for $7 => expires 01/28/2024

https://slickdeals.net/f/17248609-dominos-large-2-toppings-pizzas-6-99-carryout-only?src=frontpage

 



 

 

2023:

 

 


 

10/30/2023: Taco Bell - Free Doritos locos Tacos in app => expires Nov 5, 2023

Free Doritos locos tacos for everyone (only via the app). This in addition to the offer, where they offer a free Doritos locos tacos for guessing who will steal the first base in the 2023 World Series.

https://slickdeals.net/f/16970113-free-doritos-locos-taco-for-taco-bell-steal-a-base-steal-a-taco-promo-free?src=frontpage

 


 

10/11/2023: Dominos Offer - 1 Free Medium Pizza with online order of $7.99 or more (incl Tax) => expires 02/11/2024

https://slickdeals.net/f/16975834-domino-s-pizza-medium-2-topping-pizza-free-w-7-99-qualifying-order-valid-for-delivery-or-carryout

Plenty of time to redeem this offer, as it ends after 4 months. Even if you cancel the original order, you still get free medium pizza. However, it's limit of 1 per account. People try to get multiple of these offers by making multiple fake accounts.

 


 

10/03/2023: National Taco Day deals - Oct 4 only

Lots of BOGO and other cheap Taco offers on Oct 4.

Various Fast Food chains on Oct 4: https://slickdeals.net/f/16961173-national-taco-day-megathread-wednesday-october-4th

Taco Bell $10 monthly subscription for 1 free taco per day (sign up by Oct 4): https://slickdeals.net/f/16961758-national-taco-day-2023-taco-lover-s-pass-taco-bell-10

 


 

08/09/2023: Taco Bell - Free Doritos locos Tacos every Tuesday from 08/15 - 09/05:

Free Doritos locos tacos for everyone (only via the app, probably click on the offer under "offers"?).

https://www.doctorofcredit.com/taco-bell-free-taco-every-tuesday-8-15-9-5/

 


 

01/01/2023: Dominos Offer - $3 Tip for carryout order of $5 or more (incl Tax) => expires 03/26/2023

https://carryouttips.dominos.com/

This offer is back for 2023, It's same as what was offered last few times. You get $3 Tip for any order placed for > $5 (incl tax). You can order a large pizza with 1 topping (for $7.99). You will get $3 tip to use next week from Monday-Sunday. You can place next order for $7.99, and put this code in the PROMO section. It'll charge you $4.99+tax, and will also give you $3 tip to use on your next order. Thus every week, you can order 1 pizza for $4.99+tax until expiry date. Combined with 20% off for Dominos GC, You are getting a large pizza for ~$4, which is at par with what it would cost if you were to make one at home. Enjoy your Pizza !!

NOTE: Unless to live in one of the 5 states with no sales tax, you can order $7.99 large pizza for this offer. However, if you have no sales tax in your state, then your total will be $4.99 (after applying the tip), which will disqualify you from getting $3 Tip on your current order. In such a case, add an extra topping (for $1 more) or go with Brooklyn style extra large pizza (for $2 more).

 


 

 

2022:

 

 


 

11/03/2022: Subway Offer - BOGO (select restaurants): PROMO: FLBOGO => expiry unknown

https://slickdeals.net/f/16145170-select-subway-restaurants-buy-one-footlong-sub-get-one-footlong-sub-free

This offer is back with new promo code, It's same as what was offered last few times. Need to order online or from app. Best value is 2 footlong sub for $7.

 


 

10/31/2022: Taco Bell - Free Doritos locos Tacos (via app only): Expires 11/09/2022

Free Doritos locos tacos for everyone (only via the app, click on redeem offer under "offers").

https://www.doctorofcredit.com/taco-bell-free-taco-when-somebody-steals-a-base-in-the-world-series-2/

 


 

09/30/2022: Subway Offer - BOGO (select restaurants): PROMO: FREEFOOTLONG => expiry unknown

https://slickdeals.net/f/16059892-subway-buy-one-footlong-get-one-free-w-code-ymmv

This offer is back with new promo code, It's same as what was offered last few times. Need to order online or from app. Best value is 2 footlong sub for $7.

 


 

08/30/2022: Subway Offer - BOGO (select restaurants): PROMO: FREESUB => expiry unknown

https://slickdeals.net/f/16002784-select-subway-restaurants-buy-one-footlong-sub-get-one-footlong-sub-free-with-coupon-code-freesub

This offer is back with new promo code, It's same as what was offered last few times. Need to order online or from app. Best value is 2 footlong sub for $7.

 


 

08/22/2022: Chipotle Offer - BOGO by answering quiz questions => valid from 08/22/2022 - 08/26/2022

https://slickdeals.net/f/15993382-chipotle-burrito-bowl-salad-or-tacos-bogo-free-w-quiz-online-mobile-orders-only

The answers to the quiz for each day are provided in the comments section. You can retry infinite times if you don't get all 10 questions right. Offer start at 9AM PST each day and runs out of codes in 3-4 hours. Codes are valid for 7 days. You can get 1 code each day for each phone number provided. Need to order online or from app.

 


 

06/20/2022: Taco Bell - $5 box (online or via app): Expires 06/22/2022

This deal is for $5 box with chalupa, taco, twists and drink. An ok deal.

https://slickdeals.net/f/15846961-toasted-cheddar-chalupa-crunchy-taco-cinnamon-twists-fountain-drink-m-5

 


 

06/18/2022: Subway Offer - BOGO (select restaurants): PROMO: FREEFOOTLONG => expires 08/22/2022

https://slickdeals.net/f/15854488-new-subway-coupon-codes-for-june-buy-one-footlong-get-one-free-more-subway-via-app-purchase

This offer is back with same promo code, It's same as what was offered last few times. Need to order online or from app. Best value is 2 footlong sub for $7.

 


 

03/29/2022: Subway Offer - BOGO (select restaurants): PROMO: FREEFOOTLONG

https://slickdeals.net/f/15695377-select-subway-restaurants-5-99-footlong-7-99-meal-3-49-6-inch-5-99-meal-bogo-and-more

This offer is back, It's same as what was offered last few times. Need to order online or from app. Seems like fewer restaurants are participating in this promo code, so try few around you to see if it works for any.

 


 

12/31/2021: Subway Offer - BOGO: PROMO: FREEFOOTLONG => expires 02/13/2022

https://slickdeals.net/f/15532663-select-subway-restaurants-buy-one-footlong-sub-get-one-footlong-sub-free-more

This offer is back, after a gap of few months. It's same as what was offered last few times, and just like previous offers, runs for more than a month. It's buy one, get one free = effectively 2 subway for price of one. Can't beat the price. Need to order online or from app.

 


 

 

Quotes: Various quotes here from all over the place:

Ancient Chinese Quotes on Youtube: https://www.youtube.com/watch?v=8vOojviWwRk

Three things never come back = Time, words and opportunity. So, never waste your time, choose your words, and never miss an opportunity - Confucius

There are 1000 lessons in a defeat, but only 1 in a victory - Confucius

Learn as if you are constantly lacking in knowledge, and as if you are constantly afraid of losing your knowledge - Confucius

Nature does not hurry, yet everything is accomplished - Lao Tzu

The one who asks a question is a fool for a moment but the one who never asks any is a fool for life - unknown

“If you only do what you can do, you will never be more than who you are” - Master Shifu

Strong minds discuss ideas, average minds discuss events, weak minds discuss people - Socrates

Smart people learn from everything and everyone, average people learn from their experiences, stupid people already have all their answers - Socrates

The only true wisdom is in knowing you know nothing - Socrates

The right question is usually more important than the right answer - Plato

The person who says he knows what he thinks but cannot express it usually does not know what he thinks. — Mortimer Adler

 Courage is the ability to go from one failure to another without losing enthusiasm - Churchill

 There are two ways to conquer and enslave a nation. One is by the sword. The other is by debt. – John Adams 1826

As our circle of knowledge expands, so does the circumference of darkness surrounding it. ― Albert Einstein

 As areas of knowledge grow, so too do the perimeters of ignorance - Neil deGrasse Tyson

There is no greater education than one that is self-driven. — Neil deGrasse Tyson

The empire, long divided, must unite; long united, must divide  -- from Historic novel - Romance of the three kingdom. This simply states the obvious that Unity succeeds division and division follows unity. One is bound to be replaced by the other after a long span of time. This is the way with things in the world.

Difference between understanding and knowing - understanding is more important and thus the goal of learning.
 
"work expands so as to fill the time available for its completion" => Parkinson's Law
 
“EVERYONE IS A GENIUS! But if you judge a fish by its ability to climb a tree it will live its whole life believing that it is stupid.” — Albert Einstein.
 
“Education is not the learning of facts, but the training of the mind to think.”— Albert Einstein.
 
"We are better understood as a collection of minds in a single body than as having one mind per body" - Unknown. The gist of this is that when we are able to accept other people's view by keeping our minds open, we are going to go a long way towards being accepted and having constructive arguments.
 
"If you wish to make an apple pie from scratch, you must first invent the universe" - Carl Sagan
 
 Puzzle: Rich people need it. Poor people have it. If you eat it, you die. And when you die, you take it with you. What is it? => NOTHING

 A Woman's Loyalty is judged when the man has nothing And The Man's Loyalty is judged when he has everything => Somebody

 “Knowledge is not power. Knowledge is potential power. Execution of your knowledge is power” =>   Tony Robbins

"If I owe you $1K, I've a problem, but if I owe you $1M, yo have a problem" => old saying

So many people spend their health gaining wealth, and then have to spend their wealth to regain their health. => unknown

 Taste success once, come once more => movie "83"

“What I cannot create, I do not understand.” – Richard Feynman

The best things in life we don’t choose — they choose us => Unknown

“All ideas are second-hand, consciously and unconsciously drawn from a million outside sources.” => Mark Twain

"Great genial power, one would almost say, consists in not being original at all; in being altogether receptive; in letting the world do all, and suffering the spirit of the hour to pass unobstructed through the mind." => Ralph Waldo Emerson

Optimism is Force Multilpier => Steve Ballmer's speech

“The stock market is a device for transferring money from the impatient to the patient” - Warren Buffett

"Innovation is taking two things that exist and putting them together in a new way" - Tom Freston

“The best time to plant a tree was 20 years ago. The second best time is now.” - Unknown

"The world is not driven by greed. It's driven by envy." - Charles T Munger (Warren Buffett's partner and a billionaire)

"The best thing a human being can do is to help another human being know more." - Charles T Munger 

If you don't find a way to make money while you sleep, you are going to work until you die - Warren Buffett

Inactivity strikes us as an intelligent behaviour (mainly related to stock market, where sitting on your investments and not doing frequent buying/selling is smarter) - Warren Buffett

Duniya mein itna gum hai, mera gum to kitna kum hai (There's so much sorrow in the world, that my sorrow is negligible) => Hindi Movie song

 "If you are not willing to learn, no one can help you. If you are determined to learn, no one can stop you." => unknown

 There are only three ways a smart person can go broke: liquor, ladies and leverage (the 3 L's LLL) => Charlie Munger (told by Warren Buffett in a shareholder meeting)

“My game in life was always to avoid all standard ways of failing, You teach me the wrong way to play poker and I will avoid it. You teach me the wrong way to do something else, I will avoid it. And, of course, I’ve avoided a lot, because I’m so cautious.” - Charlie Munger

The easiest person to fool is yourself => Richard Feynman (American Physicist)

Why is pizza made round, then packed in a square box but eaten as a triangle? => Unknown

"Everyone needs to watch out from oneself. The law of Nature is => Eat or be eaten" => Dialogue in Movie

"Do the arithmetic or be doomed to talk nonsense." => Quote on the license plate of John McCarthy, one of the founding fathers of AI, to highlight the importance of Maths education.

"In looking for people to hire, you look for three qualities: integrity, intelligence, and energy (hard working or industrious). And if they don't have the first, the other two will kill you." — Warren Buffett

 


 

Practical Aspects of Deep Learning: Course 2 - Week 1

This course goes over how to choose various parameters for your NN. Designing NN is very iterative process. We have to decide on the number of layers, number of hidden units in each layer, the learning rate to choose, what activation function to use for each layer, etc. Depending on the field or application where NN is being applied, these choices may vary a lot. The only way to find out what works, is to try a lot of possible combinations and see what works best.

 We looked at data set in ML, that typically is divided into training set and test set. We also have a dev set which is a set that we use to test out our various implementation of NN, and once we narrow it down to couple of NN that work best, we try those on test set to finally pick one. Training set is usually 99% of all data, while dev and test set are each small at 1% or less.

Bias and variance:

Underfitting: High Bias: Here training data doesn't fit too well with our ML implementation. The training set error is high, and dev set error is equally high. To resolve underfitting issues, we need NN with more layers, so that we can fit better

Overfitting: High variance: Here training data over fits with our implementation. The training set error is low, but dev set error is high. to resolve overfitting, we use more training data or use regularization schemes (discussed later).

Right fitting: Here data is neither under fitting nor over fitting.

Ideally we want low bias and low variance: implying training set error is low and dev set error is also low. Worst case is when we have high bias and high variance: implying training set error is high and dev set error is even higher, so out ML implementation did bad everywhere. We solve both issues of high bias and high variance by selecting our ML implementation carefully and then deploying additional tactics to reduce bias and variance.

In small data era, we used to do trade offs b/w bias and variance, as improving one worsened the other. But in big data era, we can reduce both bias and variance. Bias can be reduced by adding more layers to our network, while variance can be reduced by adding more training data.

Regularization: 

This is a technique used to reduce the problem of over fitting or high variance. The basic way we prevent over fitting is by spreading out weights, so that we don't allow over reliance on only a small set of weights. This makes our data fit less accurately, and by doing that it prevents over fitting. There are many techniques used to achieve this. Below are 2 of such techniques.

A. L1/L2 regularization:

This is done by lowering the overall weight values so that the weight terms are closer to 0. That way they have less of an impact. You can think of the new NN with lower weights as a reduced NN, where some of the weight terms in that network have vanished. Other way to see is that by having weights close to 0, our activation functions like sigmoid and tanh remain in liner region of their plot, so the whole NN becomes more like linear NN where we are just adding linear portions of all activation functions. This then becomes same as logistic regression, which is just a single layer linear NN.

To achieve regularization, we add sum of weights to the cost term, and try to minimize the new cost (including the weight terms). Then the cost lowering method, will try to keep weights also low so that overall sum of weights remain low. There are 2 types of Regularization:

L1 Regularization: Here we add modulus of weights to cost function:

For Logistic Regression: J(w,b) = 1/m * ∑ L(...) + λ/(2m) ∑ |w| = 1/m * ∑ L(...) + λ/(2m).||w|| , where w is summed over all i/p (i=1 to i=nx).

For L layer NN: Here w is a matrix for each layer. Here Regularization term added is λ/(2m) ∑ ||w[l]|| where we sum over all layers (layer 1 to layer L), adding all weight terms in matrix of each layer. i.e

||w[l]|| =   ∑ ∑ |w[l]i,j| where i=1 to n[l-1], j=1 to n[l], => all terms of matrix are added together (in L layer NN, dim of w[l] is (n[l], n[l-1])

L2  Regularization: Here we add modulus of square of weights to cost function:

For Logistic Regression:  J(w,b) = 1/m * ∑ L(...) + λ/(2m) ∑ |w|2 = 1/m * ∑ L(...) + λ/(2m) ||w||2, where ||w||2 is w.wT over all i/p (i=1 to i=nx).

For L layer NN: This is same as for L1 regularization, except that we do square of each weight term. Here Regularization term added is λ/(2m) ∑ ||(w[l])2|| where we sum over all layers (layer 1 to layer L), adding squares of all weight terms in matrix of each layer. i.e

||(w[l])2||  =   ∑ ∑ (w[l]i,j)2 where i=1 to n[l-1], j=1 to n[l], => all terms of matrix are squared and then added together. This is known as Frobenious norm instead of L2 normalization for historical reasons. L2 normalization is used when dealing with single summation as in Logistic Regression

 When calculating dw[l] (i.e dJ/dw) for L layer NN, we need to differentiate this extra term also. So, it adds an extra term λ/(m).w[l]. Then we updating w[l] = w[l] - α.dw[l] , we now have this extra term. So, w[l] = w[l] - α.(dw[l] + λ/(m).w[l]), where dw[l] refers to original dw[l] that was there before the regularization.

So, new w[l] = (1- α.λ/(m)).w[l] - α.(dw[l]) => So, we see that eqn remains of same form as earlier, except that w gets multiplied by a factor (1- α.λ/(m)). Since this  factor is less than 1, so weights are reduced from their original values. This is why L2 regularization is also called "weight decay", as we are kind of decaying weights by added L2 regularization.

λ = It's called as regularization parameter. It's another hyper parameter that needs to be tuned to see what works best for a given NN. lambda is a reserved keyword in python, so instead of using lambda, we use lambd as variable name for lambda

NOTE: in both cases above, we don't sum "b" (i.e we don't do + λ/(2m).b or + λ/(2m).b2) as that has negligible impact on reducing over fitting.

B. Dropout Regularization:

Here, we achieve regularization by dropping out weight terms, w, randomly on each iteration of cost optimization. This causes our algorithm to not depend on any weight term or a set of weight terms very heavily, since that term may disappear at any time, during any iteration of optimization. This causes the weights to be more evenly distributed, reducing the problem of over fitting. It may seem hanky-panky kind of scheme, but it works well in practice.

Inverted Dropout: A revised and more effective implementation of Dropout is inverted Dropout, where we multiply the activation values appropriately, so that our activation values remain unchanged, irrespective of how many hidden units we dropped.

NOTE: Dropout regularization is always applied only on training data, and NOT on test data. This is obvious, since once the weights are finalized by running dropout on training data, we have to use all those weights on test data.

C. Other Regularization:

1. data augmentation: We'll always achieve better regularization with more data. Instead of getting more data, we can use existing data to augment our triaing set. This can be done by using mirror images of pictures, zoomed in pictures, rotated pictures, etc.

2. Early stopping: This is another approach where we stop our cost optimization loop after a certain number of iteration, instead of allowing it to go for a large number of iterations. This reduces over fitting. L2 regularization is preferred over early stopping, as you can mostly get same oe better variance with L2 regularization than with early stopping.

Normalize inputs:

We normalize input vector x by subtracting it by mean, and dividing it by std deviation (or sq root of variance).

So, Xnormal = (Xorig -µ) / σ where mean (µ) = 1/m * Σ X(i)orig where we sum m samples for each X, and std deviation (σ ) = 1/m *√ ( Σ (X(i)orig- µ)2)

If there are 5 i/p vectors X1,...,X5, then we do this for each of the 5 vectors for all m examples. This helps, as subtracting i/p vectors by mean centers each X around origin. Similarly dividing it by std deviation, normalizes it so that for each dimention, X is scattered around by same range for all dimensions. This makes our i/p vector X more symmetrical, and so finding optimal cost goes more smoothly and faster.

Vanishing/Exploding gradients:

With very deep NN, we have the problem of vaishing or exploding gradients, i.e gradients become too small or too big. Prof Andrew shows it with an example, on how the final weight matrix becomes a matrix with exponent of "L". So, values greater than 1 in weight matrix, start exploding, while values less than 1 start vanishing (as they start going to 0). One of the ways to partially solve this is to initialize the weight matrix correctly.

Initializing Weight matrix:

For any layer l, o/p Z = w1.x1+....+wn.xn. If the number of weights is large, then we want weights w1..wn to be small, so that Z doesn't becomes too large. so, we divide each weight matrix element by n (In reality, we divide it by square root of n). This ensures that our weight elements don't get too big. Initializing to "0" doesn't work, as it's not able to break symmetry.

For random initialization, we multiply as follows:

1. tanh activation function: For tanh. it's called Xavier init, and is done as follows: W[l] = np.random.randn(shape) * np.sqrt(1/n[l-1]). We use size of layer (l-1) instead of "l", since we divide it by input layer size, and size for i/p of layer "l" is n[l-1].

2. Relu activation function. For Relu, it's observed that np.sqrt(2/n[l-1]) works better.

3. Others: Many other variants can be used, and we'll have to just try and see what works best.

Gradient Checking:

Definition of differentiaition of X: dF(x) = Lim(e->0) F(x+e) - F(x-e) / 2e, where e goes to 0 in limiting case.

We use this definition to check for gradient by comparing the value obtained using eqn above compared to the real gradient calculated using our formula. If the difference is large (i.e > 0.001), then we need to doubt the gradients of dw and db calculated using the pgm.

 

Programming Assignment 1: here we learn about how different initialization to weight matrix, results in totally different training accuracy.  We apply our different init mechanism to 3 layer NN:

  • zero initialization: doesn't work, unable to break symmetry. Gives worst accuracy on training set
  • large random initialization: very large weights cause vanishing/exploding gradient problem, so gives poor accuracy on training set.
  • He initialization: This works perfect, as weights are divided by "n" to have lower initial weights, resulting in very high training accuracy

Here's the link to pgm assigment:

Initialization(1).html

This project has 2 python pgm.

A. init_utils.py => this pgm defines various functions similar to what we used in previous assignments

init_utils.py

B. test_cr2_wk1_ex1.py => This pgm calls functions in init_utils. It does all 3 initialization as discussed above. We unknowingly did He initialization in previous week exercise.

test_cr2_wk1_ex1.py

 

Programming Assignment 2: here we use the same 3 layer NN as above. Now we apply different regularization techniques to see which works best. These are the 3 different  regularization applied.

  • No regularization: here test accuracy is lower than training accuracy. This is due to overfitting. Gives high accuracy on training set, but low accuracy on test set
  • L2 regularization: here we apply L2 regularization, which results in lower accuracy on training set, but better accuracy on test set. The parameter lambda can be tuned to achieve higher smoothing or lower smoothing of fitting curve. Very high lambda can result in under fitting, resulting in high bias.
  • Dropout regularization: This works best as we get lower training accuracy, but highest test accuracy.

Here's the link to pgm assigment:

Regularization_v2a.html

This project has 3 python pgm.

A. testCases.py => There are bunch of testcases here to test your functions as you write them. In my pgm, I've them turned off.

testCases.py

B. reg_utils.py => this pgm defines various functions similar to what we used in previous assignments.

reg_utils.py

C. test_cr2_wk1_ex2.py => This pgm calls functions in reg_utils. It does all 3 regularization discussed above (inluding no regularization)

test_cr2_wk1_ex2.py

 

Programming Assignment 3: here we employ the technique of gradient checking to find out if our back propagation is computing gradient correctly. This is an optional exercise that can be omitted, as it's not really needed in further AI courses.

Here's the link to pgm assigment:

Gradient+Checking+v1.html

This project has 3 python pgm.

A. testCases.py => There are bunch of testcases here to test your functions as you write them. In my pgm, I've them turned off.

testCases.py

B. gc_utils.py => this pgm defines various functions similar to what we used in previous assignments.

gc_utils.py

C. test_cr2_wk1_ex3.py => This pgm calls functions in gc_utils. It does the gradient checking

test_cr2_wk1_ex3.py

 

Course 2 - Improving Deep Neural Networks: Hyperparameter tuning, Regularization and Optimization

 

This course bulids on deep NN. It has various techniques to optimize our NN to predict better. In absence of right parameters, your NN may not even work. It is a course that can be finished at a good speed. It has multiple python exercises, which should be completed. It has 3 sections:

1. Practical Aspects of Deep Learning: This talks about how to adjust parameters like initialization values, and how to choose initial values that will make our NN work. Can be watched in fast mode. However, the 3 exercises whould be finished. They don't take too much time.

2. Optimization algorithms: This goes over how to optimize the algo for finding thew lowest cost. It talsk about techniques of gradient descent (gd) as mini batch, gd with momentum, gd with RMs prop, gd with Adam and learning rate decay. There is a programming assignment to apply these various techniques on a NN, and observe the impact.

3. Hyperparameter tuning, Batch Normalization and Programming frameworks: This introduces google's framework called TensorFlow where we write a program to classify sign digits from 0 to 5.

 

PT flow:

Any STA signoff tool needs to be run separately for all the timing corners after synthesizing and doing final PnR netlist. This ensures that timing is met across all corners, including those that haven't been checked in synthesis or the PnR flow. Here we detail the flow for running Primetime from Synopsys.

Ex Dir=> /project/Primetime/digtop

Setup:

Before running PT, we need to have .synopsys_pt.setup in this dir. This is similar to .synopsys_dc.setup, that we use for DC. Only difference is that link library now has *_CTS.db, as the gate level netlist has CTS cells.CTS cells are clock cells, they may be named differently in other libs. This has lib path, etc (look in "synthesis DC" for more details). We don't specify target_library and link_library in this file, but when running PT for each corner, as we have to use diff .db files for diff corners.
1. search_path: set to path where all .db files are located.
set search_path "$search_path /home/pdk/lib270/r3.0.0/synopsys/bin \
../../Memories/sram220x64/cad_models"
2. target_library: set to min corner library
set target_library MSL270_W_125_2.5_CORE.db => optional as it's specified again when running diff corners.
3. link_library (or link_path my also be used): set to mem and target library.
set link_library { * PML30_W_150_1.65_CORE.db PML30_W_150_1.65_CTS.db } => optional as it's specified again when running diff corners.

So, only step 1 is needed. Other steps not needed.

Invoking PT:

to run PT in cmd line, type

$ pt_shell -2011.12 => If we don't provide version number (-2011.06 or -2011.12 etc), it picks up default version, set by sysadmin. Once pt_shell comes up, from within PT shell, we can write PT cmds.
$ pt_shell> source file_name => executes scripts in file_name.

To execute cmd script upon startup, start pt shell as:(In this case, the script runs automatically w/o any manual cmds from user. This is the preferred way for running PT once you have debugged the script, and it's working correctly)
$ pt_shell -2011.12 -f file_name

GUI mode:

Apart from writing cmds or running script in pt_shell, you can also invoke gui from within PT. Once pt shell comes up, type below cmd

pt_shell> gui_start

Now we can select a cell, pin, wire etc on the schematic, and we'll see this cmd indicating our selection on the shell

pt_shell> change_selection [get_pins mod1/sync_2/out1] => This way it's lot easy to get pin names, etc instead of figuring it out by looking athe design

pt_shell> get_selection => This will show whatever was selected.i.e for above selection, it'll show "mod1/sync_2/out1"

pt_shell> report_timing -thr [get_selection] => This will report timing through the pins selected.

Running PT cmd script:

There are 2 PT scripts we run. One for running design across various PVT corners, and the other for generating SDF files. First let's look at run_pt_all script which runs STA across all corners. Next we'll run sdf generation script. sdf files are needed only for running gate level sims (GLS). So, if you don't plan to run GLS, then you can skip generation of SDF.

1. run_pt_all:  We run "run_pt_all" script, which calls PT shell for all runs. PT is run across various PVT corners. For 130nm or higher tech nodes, just running it across fastest PVT corner and slowest PVT corner suffices. However, when you run timing for lower node designs (ones below 130nm), we need to run PT across lot more corners, as just the fastest PVT and slowest PVT may not capture all timing paths in design(due to large variations in transistors across the chip, which may result in some worst case paths showing up in intermediate PVT corners). Generally PT is run for 2 cases based on functionality:

  1. Functional mode (No scan): This is the normal functional run of chip. Here "scan_mode" is set to 0.
  2. Scan mode (includes Scan Shift and Scan Capture):This is when the part is put in scan mode to test scan chains. Here "scan_mode" is set to 1.
  3. Scan_Vbox mode (optional): This runs scan mode on chip, the same as 2 above, but here we apply much larger voltage than the PVT max corner and much lower voltage than PVT min corner. These voltages are supposed to be bounding boxes for our PVT corner. We run these ultra high or ultra low voltages for scan mode only (not functional), as we want to see if the chip still functions in scan mode.

Running PT for 6 cases noscan(min/max), scan(min/max), scan_vbox(min/max). max refers to max delay lib being used, while min refers to min delay lib being used for that run. Below we show which reports are being generated for each mode.


A. NO SCAN: scan_mode_in set to 0 (in case_analysis.tcl). so normal clks used. If we don't set scan_mode to 0, then there will be too many paths to analyze as both scan_mode=0 and scan_mode=1 timing analysis is run. So, we separate them out.


1. nonscan_max: max delay lib being used
rpts/digtop.max_timing_post_noscan.max.rpt => setup check with max PVT delay (W, 150C, 1.65V) and max interconnect delay (max.spef) slow corner (PCR=max)
rpts/digtop.min_timing_post_noscan.max.rpt => hold check with max PVT delay (W, 150C, 1.65V) and max interconnect delay (max.spef) slow corner (PCR=max)
rpts/digtop.post_noscan.max.rpt => comprehensive report combining both setup and hold checks for slow corner.


2. nonscan_min: min delay lib being used
rpts/digtop.max_timing_post_noscan.min.rpt => setup check with min PVT delay (S, -40C, 1.95V) and min interconnect delay (min.spef) fast corner (PCR=min)
rpts/digtop.min_timing_post_noscan.min.rpt => hold check with min PVT delay (S, -40C, 1.95V) and min interconnect delay (min.spef) fast corner (PCR=min)
rpts/digtop.post_noscan.min.rpt => comprehensive report combining both setup and hold checks for fast corner.

B. SCAN: scan_mode_in set to 1 (in scan.sdc). In scan, spi_clk used as clock for shift and capture. scan.sdc has clk_defn for spi_clk, case_analysis to set scan_mode to 1 and all IO delay set wrt scan_clk. It should not have any false paths as all of the digital logic is run by spi_clk. spi_clk is run at lower freq, and i/o delays are set wrt spi_clk.
IMP NOTE: scan_enable pin IO delay should be matched to real Tetramax delay. Otherwise even if scan_en is not buffered appr and has large transition delays, it may still be able to meet timing wrt rising edge of clk. Thus it may not be captured as a violation here but may show up in Tetramax gate level sims. scan_en is the only IO pin that has real timing path to CLK in DUT. So, it should never be tied to 0 or 1 (by setting set_case_analysis), as that will cause constant propagation, so we will not get a path with rising/falling edge of scan_en pin (it will be reported as unconstrained path in PT). That may hide real failure on this path.

1. scan_max: max delay lib being used

2. nonscan_min: min delay lib being used

C. VBOX: vbox tests run during scan to see if the chip still functions (simple Iddq patterns run to see if lkg is within limits). We choose just 2 corners: vbox_hi=strong tran at high voltage (min delay), and vbox_lo=weak tran at low voltage (max delay), to see if setup, hold etc passes.
#NOTE: We mostly care about vbox_hi rpts to be clean, as that indicates that there is enough hold slack (setup rpts will be clean at vbox_hi anyway as it's run at much faster corner). vbox_lo will be mostly clean for hold, but may have violations for setup as it's a very slow corner. In nutshell, there should be no hold viol at any of vbox_lo/hi, but only setup viol at vbox_lo (assuming design is barely meeting setup timing).


1. scan_vbox_hi: digtop.post_scan.vbox_hi.rpt: high voltage vbox conditions with min PVT delay (S, 25C, 3.2V) and min interconnect delay (min.spef) fast corner at 25C (PCR=vbox_hi). Run at normal freq (12MHz)


2. scan_vbox_lo: digtop.post_scan.vbox_lo.rpt: low voltage vbox conditions with max PVT delay (W, 25C, 0.95V) and max interconnect delay (max.spef) slow corner at 25C (PCR=vbox_lo). Run at 1/2 normal freq (here it's 6.25MHz, as high freq may not be supported at vsuch low voltages)

details of run_pt_all: run_pt_all script calls pt_shell 6 times as shown above for 6 different corners. We only show the script for noscan_max (case A, bullet 1 above) and scan_max (case B, bullet 1 above). Similarly we have it for noscan_min, scan_min, vbox_max and vbox_min

All scripts below run these basic steps:

  1. Read Library: set target_lib and link_lib to appr PVT corner
  2. Read Netlist and SPEF: read verilog gate netlist (from PnR tool), and spef file (from QRC extraction for appr PVT corner).
  3. Read constraints: read constraints for clk,false_paths,case_analysis,etc (func has func.sdc while scan has scan.sdc)
  4. Report timing: report_timing for both max_delay(setup) and min_delay(hold)

no scan max script (check_timing_post_nonscan_max.tcl): Runs functional PT run for max delay corner (i.e worst PVT, that gives max delay). This is for case A, bullet 1 above.

pt_shell -2010.06 -f scripts/check_timing_post_nonscan_max.tcl | tee logs/run_pt_post_nonscan_max.log  => This script sources below 2 scripts:
source -echo scripts/import_post_max.tcl => This runs step 1 and 2 (Read lib, netlist and spef)
source -echo scripts/constrain_post_nonscan.tcl => This runs step 3 and 4 (Read constraints, report timing)

1. import_post_max.tcl => This script is called for 2 max corners above. We have similar import_post_min.tcl for 2 min corners above

#1. Read Library: Read max delay lib. For min corner, we read min delay lib.

set target_library { LIB_W_150_1.65_CORE.db LIB_W_150_1.65_CTS.db } => IMP: whenever, we have new line starting it should have "\" to continue on next line. If starting/closing braces { } are not on same line as file name, then we should have "\" to continue on next line. else we get linking error.
set link_library { * LIB_W_150_1.65_CORE.db LIB_W_150_1.65_CTS.db } => IMP: same as above. "\" should be used when starting new line, or we get linking error.

NOTE: target_library above refers to max delay library. This max delay lib is used for both setup/hold runs. If we want to use max delay lib for setup and min delay lib for hold, we should do this:
set_min_library LIB_W_150_1.65_CORE.db -min_version LIB_S_-40_1.95_CORE.db => specifies max lib, and corresponding min lib by using -min_version.
#For OCV runs, where we want to have min/max library for data/clk path for both setup/hold, in set_operating_condition, we should specify max and min libraries to use for ocv runs.

We can also use following 2 cmds instead of previous 2 cmds:
#set link_path "* LIB_W_150_1.65_CORE.db LIB_W_150_1.65_CTS.db"
#set default_lib "LIB_W_150_1.65_CORE.db LIB_W_150_1.65_CTS.db"

#To make sure, that when any link is unresolved, we get appr error, set the var below in .synopsys_pt.setup
set link_create_black_boxes false => this prevents PT from creating blackbox for unlinked ref, and decalring linking as successful

#2A. Read netlist: read gate netlist generated from PnR tool
read_verilog /db/.../final_pnr_files/digtop_final_route.v

set TOP "digtop"
current_design $TOP => working design for PT.
link => link design to resolve all references in design. shows all lib that are being used to link design. No module/gate should be unresolved here, as that would mean missing module/gate defn

#additional cmds for debug
list_libraries => lists all libraries and their paths
report_design => lists attr of current design, incl min/max op cond used, WLM, design rules, etc.
report_cell => This reports all cells in current design, and .lib they refer to. If current_design is set to DIG_TOP, then it only shows cells for DIG_TOP and NOT for sub-modules within it. This is helpful to find out which .lib is used for timing run (especially if multiple .lib have been loaded in memory)
report_cell "dig_top/cell1" => This reports cell1, it's ref, it's area and other attr.

report_reference => This shows .lib references for cells in current design

#2B. Read spef: read max spef file (generated from rc extractor from within PnR tool)
read_parasitics -format spef /db/.../final_pnr_files/digtop_qrc_max_coupled.spef

2. constrain_post_nonscan.tcl: This file contains all the constraints for functional mode runs. This sources functional sdc file.

#these below settings can be done in .synopsys_pt.setup too.
set timing_self_loops_no_skew true
set timing_disable_recovery_removal_checks "false"

current_design $TOP

#3A. Read constraints: We have 2 options for importing constraints in PT

#OPTION 1:  we source all constraints files individually that we used in DC (instead of using autogenerated file in DC). We don't source env_constraints.tcl (that was used in DC) in PT as we don't want "set_operating_conditions" and set wire load model directives in this file to be used in PT. 
source -echo /db/Synthesis/digtop/tcl/clocks.tcl => clks defined (no scan clk in this)
source -echo /db/Synthesis/digtop/tcl/constraints.tcl => all i/o delays + environment specified.Use same values as used in synthesis. See sdc section (Synopsys (standard) design constraints) for details of these cmds. The units are not specified in below cmds, but are instead based on "set_units" cmd or cap units from the lib that was the last one to be loaded.

  • set_driving_cell => to set i/p driver cell. If driving cell is not set, then we need to set i/p tran time via: set_input_transition 100 [get_ports IN_*] => sets tran time to 100 units. In this case, it's 100ps as lib has "time_unit : "1ps".
  • set_load => to set specified load on ports and nets. We set it on ports only (as we don't want to specify our own cap on internal nets, we let tool calc cap on nets). -max or -min options specify max or min cap to be used in max or min corner runs (as we may not want to use same cap for both max and min runs, applicable only when running timing in max/min mode)
    • ex: set_load 5 [get_ports OUT_*] => sets load of 5 units on all ports OUT_*. Units are based on lib units loaded. In this case, it's 5 ff as lib has "capacitive_load_unit (1.000000, ff);" defined
    • report_port => this cmd used to to report cap + other attr on all ports (or specified port if port specified, i.e report_port [get_ports OUT_*]
  • set_input_delay / set_output_delay => sets i/p, o/p delay on ports


source -echo /db/Synthesis/digtop/tcl/false_paths.tcl => false paths
source -echo /db/Synthesis/digtop/tcl/multicycle_paths.tcl
source -echo /db/Synthesis/digtop/tcl/case_analysis.tcl => scan mode is set to 0. other flops set for func mode. case_analysis.tcl has following:

  • set_case_analysis 0 scan_mode_in => turn OFF scan mode.

#OPTION 2: Instead of sourcing all the above constraints files, we can use constraints.sdc file that is autogenerated by DC to get all the constraints.
source -echo /db/Synthesis/digtop/tcl/constraints.sdc => It has env _constraints (pin loads, driving cells), clks, i/o delays, false paths, case-analysis, dont_touch, etc (basically all the constraints in option 1 above, except the env_constraints). Since the env constraints is also present in this file, we get section that has "set_operating_conditions" set for 1 PVT corner for which we ran DC (it comes from env_constraints.tcl file that was used for DC). So when running PT for other corners, we 'll get errors like "Error: Nothing matched for lib (SEL-005)". So, we'll need to comment out that line when running PT with the above autogenerated file. Or we can comment out the whole env_constraints section.

#after applying path exceptions, do report_exceptions to see list of timing exceptions applied
report_exceptions => -ignored will show those cmds too that are fully ignored. This is important to do as it will tell us if any of the FP/MCP are getting applied or dropped due to syntax errors, path not existing, etc.

#3B. Other constraints: We set clk to propagated, and analysis type to ocv.

#propagate clks: clk is propagated here (In DC, we didn't use propagated clk, so clk was treated as ideal, that means even gate delays in clk path weren't included anywhere in timing reports. We treat clk as ideal in DC, because buffers are going to be inserted later during PnR, so we don't want DC fixing clk paths, with it's own buffers). With this setting, all gate+buffer delays included in clk delay, when running timing.
set_propagated_clock [all_clocks] => Very imp to set this, else timing reports will be all incorrect.

#We set analysis type to OCV even when running it in single mode (specifying only max library for max run, and only min library for min run). So, in reality it's not running ocv here, as we have only one lib loaded to run on all paths. OCV is necessary for PBTA (path based timing analysis to be discusse later) to work.

set_operating_conditions -analysis_type on_chip_variation => This cmd explained in detail in "PT - OCV" section.

#4: Reports: Timing reports generated below. report_timing is the main cmd that causes PT engine to run timing.

#rpt file for setup (-delay max)
set rptfilename [format "%s%s" $mspd_rpt_path $TOP.max_timing_post_noscan.$PCR.rpt]
redirect $rptfilename {echo "digtop constrain_post_noscan.tcl run : [date]"}
redirect -append $rptfilename {report_timing -delay max -path full_clock_expanded -max_paths 100} => provides timing, most powerful cmd in PT.

#rpt file for hold (-delay min)
set rptfilename [format "%s%s" $mspd_rpt_path $TOP.min_timing_post_noscan.$PCR.rpt]
redirect $rptfilename {echo "chip constrain_post_noscan.tcl run : [date]"}
redirect -append $rptfilename {report_timing -delay min -path full_clock_expanded -max_paths 100}

#rpt file for all violations
set rptfilename [format "%s%s" $mspd_rpt_path $TOP.post_noscan.$PCR.rpt]
redirect $rptfilename {echo "digtop constrain_post_noscan.tcl run : [date]"}
redirect -append $rptfilename {report_clocks }
redirect -append $rptfilename {check_timing -verbose} => check_timing checks for constrain problems.
redirect -append $rptfilename {report_disable_timing} => You can also eliminate paths from timing consideration by using the set_disable_timing command. report_disable_timing reports such paths. It shows disabled timing arcs for all the cells. Most of them are "u=user-defined" paths. Spare cell paths are reported as "p=propagated constant" since all i/p pins are tied, so no paths exist. Some paths get reported with"c=case-analysis" since case analysis ties some pins.
ex:

Cell or Port                From    To      Sense                 Flag  Reason
--------------------------------------------------------------------------------
Mod1/req/u4             A1      ZN      positive_unate     C     A2 = 0 => Arc from pin A1 to pin ZN of cell u4 is disabled.

redirect -append $rptfilename {report_constraint -all_violators} => reports the results of constraint checking done by PrimeTime. -all_violators reports all violations incl setup, hold, max cap, max FO, max transition time (slew rate or transition time is measured 10/90 or 20/80 or whatever based on the characterized lib and slew derate factor), min pulse width, clk gating checks, recovery checks and removal checks. {report_constraint -all_vio -verb} gives verbose info about violations

#report_global_timing -group [get_path_group CLK*] => generates a top-level summary of the timing for the design. Here generates a report of violations in the current design for path groups whose name starts with 'clk'. If we run this in a for loop with all path_groups, then we get separate reports for each group.
ex: foreach_in_collection path_group [get_path_groups] { report_global_timing -group $path_group >> viol_summary.rpt } => reports timing for groups = **async_default**, **clock_gating_default**, **default**, CLK10, SYSCLK20, and other clocks in design.

#report_analysis_coverage => Generates a report about the coverage of timing checks
#report_analysis_coverage -status_details {untested} -check_type {setup} => Once we see coverage missing, we can get detailed report about status of untested, violated or met checks. Check types can be "setup, hold, recovery, removal, clock_gating_setup, clock_gating_hold, min_pulse_width, min_period, nochange".

#report_clock_timing -type summary -clock [get_clocks *] => lists clock timing info summary, which lists max/min of skew, latency and transition time over given clk n/w.
# report_clock_timing -type skew -setup -verbose -clock [get_clocks *] => This gives more detailed info about given clk attr (over here for skew). By default, the report displays the values of these attributes only at sink pins (that is, the clock pins of sequential devices) of the clock network. Use the -verbose option to display source-to-sink path traces.

#PBTA: pbta is path based timing analysis. By default, pba_mode is set to "none" => pbta is not applied (gba is applied). It's useful as PBA doesn't have pessimism of GBA, so we always use PBA though at expense of runtime.
#report_timing -pba_mode path => pba applied to paths after collecting, but worst case may not be reported. It takes the worst slack path, and just recalcualtes it, but it's possible that next worst case path right behind it, doesn't get as much improvement from pba, and so might become worst case path, but we never analyzed this next worst case path.
#report_timing -pba_mode exhaustive => provides worst case path after recalc. It looks at all the paths to a particular endpoint, and applies pba on each path to that endpoint. Path with worst slack after applying recalc to all paths to each endpoint is shown. so, the optimism inherent with "-pba_mode path" is not present anymore.

#rpt file for pbta setup (-delay max)
set rptfilename [format "%s%s" $mspd_rpt_path $TOP.pbta_max_timing_post_nonscan.$PCR.rpt]
redirect -append $rptfilename {report_timing -pba_mode exhaustive -crosstalk_delta -transition_time -delay max -path full_clock_expanded -nworst 10 -max_paths 500 -slack_lesser 1.0} => -crosstalk_delta reports delta delay and delta transition time, which were calculated during crosstalk SI analysis (provided PTSI is enabled). -transition_time reports transition time which is helpful to figure out nets which have very slow transition due to crosstalk.

#rpt file for pbta hold (-delay min)
set rptfilename [format "%s%s" $mspd_rpt_path $TOP.pbta_min_timing_post_nonscan.$PCR.rpt]
redirect -append $rptfilename {report_timing -pba_mode exhaustive -crosstalk_delta -transition_time -delay min -path full_clock_expanded -nworst 10 -max_paths 500 -slack_lesser 1.0}

scan max script (check_timing_post_nonscan_max.tcl): Runs scan PT run for max delay corner (i.e worst PVT, that gives max delay). This is for case B, bullet 1 above.

pt_shell -2010.06 -f scripts/check_timing_post_scan_max.tcl | tee logs/run_pt_post_scan_max.log  => This script sources below 2 scripts:
source -echo scripts/import_post_max.tcl => This runs step 1 and 2 (Read lib, netlist and spef)
source -echo scripts/constrain_post_scan.tcl => This runs step 3 and 4 (Read constraints, report timing)

1. import_post_max.tcl => This script is same as what we used in func mode above

2. constrain_post_scan.tcl: This file is used for scan runs (and is diff than func script above). This sources scan sdc file. No other constraints files are sourced when running scan. This is because the constraints for scan are totally different than ones in func mode.
source -echo /db/.../scan.sdc
#scan.sdc has following:
create_clock -name spi_clk -period 66 -waveform { 0 33 } [get_ports {spi_clk}] => create clk for PT and specify its characteristics. rising edge at 0ns and falling edge at 33ns.
set_propagated_clock [get_clocks {spi_clk}]
set_case_analysis 1 [get_ports {scan_mode_in}] => turn ON scan mode.
set_input_delay 10 [all_inputs ] => i/p timing conditions
set_output_delay 10 [all_outputs ] => o/p timing requirements
set_dont_touch scan_inp_iso
set_driving_cell -lib_cell IV110 [all_inputs]
set_load 4.2 [all_outputs]

 

2. SDF generation script: Once we have run PT across all 6 corners as shown above, we use PT to generate SDF files. Thses are delay files that will be used in gate level simulations. If we don't plan to run GLS, then we don't need to run this step.

sdf file generation requires:

  • .lib files => for all cells/macros as they have cell delays, setup/hold timing checks, c2q arcs etc.
  • gate level verilog netlist => netlist is needed so that all nodes of netlist are appened with appr cell delay and net delay. nets which are not connected to anything are reported as driverless nets
  • spef file => has R,C info for all nets (no dly info for nets and cells)

NOTE: we don't require verilog model files for cells, macros, etc as we are just generating delay file. All arc info comes from .lib files. Delays for sdf are calculated from R,C in spef file and cell delay (with appr load for that cell coming from spef file) from .lib file.

we've 2 scripts for generating max and min sdf. Each net and instance in verilog is matched with a net parasitic in spef file, and a cell timing in .lib file. target library and link library are set to *.db (liberty files for gates) for that particular corner, just as we do in DC.


1. max sdf: (for max delay, so worst timing corner)
> pt_shell -2010.06 -f scripts/MaxSDF.tcl | tee logs/run_GenMaxSDF.log

#MaxSDF.tcl has following: read .lib files, verilog file and max.spef file (generated from EDI). write_sdf writes final sdf file, other options in write_sdf needed to have aligned sdf, otherwise when we do sdf annotation, we may not get sdf file arcs aligned with verilog model file arcs. sdf file arcs come from .lib arcs, while during annotation, we check it against arcs in verilog model files.

set target_library { PML48_W_125_1.35_COREL.db \
PML48_W_125_1.35_CTSL.db \
felb2x01024064040_W_125_1.35.db }
set link_library { * \
PML48_W_125_1.35_COREL.db \
PML48_W_125_1.35_CTSL.db \
felb2x01024064040_W_125_1.35.db }
echo $target_library

read_verilog /db/NIGHTWALKER/design1p0/HDL/FinalFiles/digtop/digtop_final_route.v
current_design digtop
link

read_parasitics -format spef /db/NIGHTWALKER/design1p0/HDL/FinalFiles/digtop/digtop_qrc_max_coupled.spef

#timing checks
check_timing -verbose => report shows all endpoints as unconstrained as no sdc file provided. OK
report_timing => report shows no constrained paths, as no clk provided. OK
report_annotated_parasitics -max_nets 150 -list_not_annotated => Provides a report of nets annotated with parasitics in the current design for both internal and port nets. -list_not_annotated lists nets that are not back annotated.
write_sdf -version 3.0 \ => SDF version 1.0, 2.1 or 3.0
-exclude {default_cell_delay_arcs} \ => specifies which timing values are to be excluded from sdf file. default_cell_delay_arcs indicates that all default cell delay arcs are to be omitted from the SDF file if conditional delay arcs are present. If there are no conditional delay arcs, the default cell delay arcs are written to the SDF file. NOTE: This may be an issue when running gatesims, as verilog models will have default_delay_arcs, while those will be missing from sdf files, so annoatation will have "missing annotation" warnings.
-include {SETUPHOLD RECREM} \ => SETUPHOLD:combine SETUP and HOLD constructs into SETUPHOLD. RECREM:combine RECOVERY and REMOVAL constructs into RECREM.
-context verilog \ => context for writing bus names for verilog, vhdl or none, so that [], () are not escaped.
-no_edge \ => SDF should not include any edges (posedge or negedge) for both comb and seq IOPATHs. It takes the worst of posedge/negedge values and assigns it to the delay arc
-no_negative_values {cell_delays net_delays} \ => Specifies a list of timing value types whose negative values are to be zeroed out when writing to the SDF file. Allowed values for timing values are timing checks, cell delays and net delays.
sdf/digtop_max.pt.sdf
quit

#look in logs/run_GenMaxSDF.log for errors.
A. look "report_annotated_parasitics" section detailed info. Here all internal nets (nets connected only to cell pins) and boundary/port nets (net connected to any I/O port of top level design, this should match the number of I/O ports in design) are reported. These nets are classified into pin to pin nets, driverless nets and loadless nets. All nets should connect from pin to pin, unless they are either floating o/p (loadless nets) or floating i/p (driverless nets). Nets which have no driver and no load are counted as driverless nets. Nets are everything reported as wires in digtop_final_route.v file. Any wire in this netlist that it's not able to find associated with any cell, it reports those as "floating nets". NOTE: parasitics from spef file are only annotated on nets, and not to cells. These parasites cause INTERCONNECT delay on nets, and eventually affect the loading on cells. Eventually cell arc from .lib file is used to find out real delay based on cell o/p pin load.
B. look warnings in "write_sdf" section. Most common one is "The sum of the setup and hold values in the cell 'soc_top/i2cBlk/i2cLink/sdaOut_reg' for the arc between pins 'CLK' and 'SCAN' is negative, which is not allowed. To make it positive, the minimum hold value has been adjusted from -0.613501 to -0.594033. (SDF-036)". This is because setup+hold should be > 0

2. Min sdf: for min delay, so fastest timing corner chosen.
> pt_shell -2010.06 -f scripts/MinSDF.tcl | tee logs/run_GenMinSDF.log

#MinSDF.tcl has following: only diff is min delay lib, and min spef chosen

set target_library { PML48_S_-40_1.65_COREL.db \
PML48_S_-40_1.65_CTSL.db \
felb2x01024064040_S_-40_1.65.db }
set link_library {* \
PML48_S_-40_1.65_COREL.db \
PML48_S_-40_1.65_CTSL.db \
felb2x01024064040_S_-40_1.65.db }

echo $target_library

read_verilog /db/NIGHTWALKER/design1p0/HDL/FinalFiles/digtop/digtop_final_route.v
current_design digtop
link

read_parasitics -format spef /db/NIGHTWALKER/design1p0/HDL/FinalFiles/digtop/digtop_qrc_min_coupled.spef

check_timing -verbose
report_timing
report_annotated_parasitics -max_nets 150 -list_not_annotated
write_sdf -version 3.0 \
-exclude {default_cell_delay_arcs} \
-include {SETUPHOLD RECREM} \
-context verilog \
-no_edge \
-no_negative_values {cell_delays net_delays} \
sdf/digtop_min.pt.sdf
quit

 

PT reports:
----------
PT reports timing for clk and data path. 1st section "data_arrival_time" refers to data path from start point, while 2nd section "data_required_time" refers to clk path of end point. 1st section shows path from clk to data_out of seq element and then thru the combinational path all the way to data_in of next seq element, while 2nd section shows primarily the clk path of final seq element, ending at clk pin. In the 2nd section, it shows the final "data check setup time" inferred from .lib file for that cell.

reports are shown for per stage. A stage consists of a cell together with its fan out net. So, transition time reported is at the i/p of next cell. delay shown is combined delay from i/p of cell to o/p of cell going thru the net to the i/p of next cell. & in report indicates parasitic data.

Ex: a typical path from one flop to other flop
Point Incr Path
------------------------------------------------------------------------------
clock clk_800k (rise edge) 1.00 1.00 => start point of 1st section
clock network delay (propagated) 3.41 4.41
.....
Imtr_b/itrip_latch_00/SZ (LAB10) 0.00 7.37 r
data arrival time 7.37
-----
clock clk_800k (rise edge) 101.00 101.00 => start point of 2nd section (usually starts at 1 clk cycle delay, 100 ns is the cycle time here)
clock network delay (propagated) 3.85 104.85
.....
data check setup time -0.04 105.76 => setup time implies wrt clk, data has to setup. So, we subtract setup time from .lib file to get data required time (as +ve setup time means data should come earlier)
data required time 105.76
------------------------------------------------------------------------------
data required time 105.76
data arrival time -7.37
------------------------------------------------------------------------------
slack (MET/VIOLATED) 98.39