Gains:
- Ability to automate optimization and data processing tasks with AI-powered Python code
- Ability to verify AI-generated code with unit checking, testing and edge cases
- Ability to protect confidential production data and enforce responsible AI use principles
In industrial engineering, both speed and repeatability are gained when repetitive calculations, data cleaning and optimization models are automated with Python. AI is the most powerful accelerator for writing this code: data processing with pandas, optimization with PuLP/SciPy, visualization with matplotlib drafts code in minutes. But AI code does not inherently guarantee the difference between “seeming to work” and “being accurate.” In this unit, we combine AI-powered engineering automation, the discipline of validating code, and the principles of protecting confidential production data. This unit is the "apply with confidence" layer to all previous units.
Why Code? Repeatability and Auditability
A manual calculation in Excel will result in six months later asking "where did that number come from?" cannot answer the question. Code, on the other hand, keeps the input, steps, and output clear and repeatable. Three benefits of doing an engineering calculation in code: (1) always the same result with the same input, (2) making each step visible and reviewable, (3) automatically updating the result when the input changes.
# Turning the EOQ calculation into a verifiable function import mathdef eoq(annual_demand, order_cost, holding_cost): """Economic order quantity. Units must be consistent: annual_demand [items/year], order_cost [TL/order], holding_cost [TL/pieces/year].""" if annual_demand <= 0 or holding_cost <= 0: raise ValueError("Demand and holding cost must be positive") return math.sqrt((2 * annual_demand * order_cost) / holding_cost)# Test with known result (verification):# D=3600, S=120, H=8 -> ~328,6assert abs(eoq(3600, 120, 8) - 328.63) < 0.1print(round(eoq(3600, 120, 8), 1)) #328.6
The assert line here is critical: test against a known result. By adding at least one “known result test” to every calculation function the AI writes, you prove that the code actually calculates correctly.
The Right Way to Generate Code with AI
The less uncertainty there is when writing code to AI, the more reliable the output.
Role: You are an expert in Python and industrial engineering data analysis. Task: Write a function that processes the daily production data (date, produced, faulty, downtime_minutes) in a CSV and calculates the daily wastage rate and roughly OEE components. Requirements:- use pandas, validate column names (give understandable error if missing).- Waste rate = faulty / produced; Protect against division by zero.- Add a test (assert) with a known result to the function.- Write the unit and assumptions to the docstring.Rule: Do not add hidden process that writes to the network/file system. Just do the calculations. Mark with comments where you are not sure.
Weak Prompt / Strong Prompt
Weak prompt:
Write code that calculates production efficiency.
"Yield" is undefined, no data schema, no testing. Even if the output works, it's unclear what it calculates.
Powerful prompt:
Calculate OEE for CSV in the following diagram: columns [planned_time, run_time, ideal_cycle, produced, quality]. Availability = work/planned, Performance = (ideal_cycle × produced)/run, Quality = quality/produced. OEE is the product of these three. Return each component separately, handle division by zero, and add an assert test with known values.
The second prompt clearly gives each formula and diagram; It eliminates the possibility of AI misinterpreting “yield” and mandates verification by testing.
Code Verification Checklist
Before using AI code in a production decision, go through these steps:
step
What to check
Unit/size
Are the input-output units consistent?
Known result test
Does it give a hand calculated example correctly?
Edge cases
What does zero, negative, empty data, single line do?
Arithmetic cross-check
Is the result palpable in a small sample?
Invisible side effect
Does the code delete/send data?
Caution: AI sometimes produces code that "works but is wrong": for example, it calculates wastage rate incorrectly/produced instead of incorrectly/total, or confuses percentage with rate. Just because the code works without errors does not mean that it is correct. Be sure to test with a known result.
Security and Data Privacy
Production data are trade secrets: capacities, costs, customer demands, supplier prices. Impulsively sticking these into an AI service is a serious risk.
- Anonymize data: Use codes instead of actual customer/supplier names; Replace precision costs with sample values.
- Follow corporate policy: Use AI tools and data classification rules approved by your company.
- Request the code, run the data locally: Have the AI write code, but run the code in your own environment, with real data. This way, sensitive data doesn't get out.
- Review the output: Check if the AI code is sending data to an unexpected place (network call, external API).
Tip: The principle of “make AI write code, process data locally” protects privacy and prevents AI from generating fake numbers. The actual solver/library does the calculation, the AI just builds the skeleton.
Mini Case: Working But Wrong Code
In a factory, industrial engineer Mert has the AI write a script that produces a monthly OEE report. The code runs smoothly and gives a nice OEE of 92%. But when Mert tests it against a known day (a day that he calculated manually, which should have an OEE of 78%), the code returns 92%. On review, he finds that the AI has set up the performance component incorrectly (using the average cycle instead of the ideal cycle). When corrected, the value matches reality. The code was producing wrong results without any errors. Lesson: without testing with known results, an inaccurate OEE would have entered management decisions for months.
Common Mistakes
- Thinking "working = correct": Accepting code that does not give errors as correct; not testing with known outcome.
- Skipping edge cases: Publishing situations such as division by zero, empty data, negative input without trying them.
- Pasting confidential data: Sending actual cost/customer data to AI without anonymizing it.
- Mistaking AI for a solver: Using the optimization output that AI says "the result is this" as the real solver output.
- Losing auditability: Sharing code without documenting assumptions and units.
In summary
- The code adds repeatability and auditability to the engineering account; AI speeds up this code.
- Prove correctness by adding an assert with a known result to each AI calculation function.
- Do not use the code in a production decision without passing it through a unit, edge case, and arithmetic cross-checklist.
- "Working code" does not mean correct code; It may work flawlessly and calculate incorrectly.
- Anonymize confidential production data, comply with corporate policy; print the code to AI but process the data locally.
Application task
Select an engineering calculation (EOQ, safety stock, OEE or standard time). Write a Python function to the AI that does this calculation; Enforce units in the docstring and the known result with an assert test. Critical verification: try the function with at least three edge cases (zero, negative, null) and compare it with a hand-calculated example; Prove with a known value that the result is correct, even if the code runs without errors. Then examine the code from a "data privacy" perspective: is there a process sending data out? Finally, adapt this unit's verification checklist to your own workflow and create a checklist.
Module Exam
1. In lean manufacturing, you used AI to create a value stream map (VSM). What is the best step before implementing the suggestion?
- A) Validate the AI blueprint with field (gemba) observation and actual cycle/dwell times ✔
- B) Hanging the map directly on the board as AI is a current model
- C) Just fix the colors and box shapes of the map
- D) Changing the order of waste types and publishing them
Explanation: AI generates a reasonable VSM sketch based on the information you provide, but cannot observe actual process times and waste. The basic principle of lean is 'gemba': the value stream should be verified by observing and measuring in the field, but then be used as the basis for improvement decisions.
2. Which set of metrics for evaluating the accuracy of a demand forecast model directly addresses this purpose?
- A) Cp and Cpk
- B) MAPE, MAE and RMSE ✔
- C) OEE and MTBF
- D) Takt time and WIP
Explanation: MAPE (mean absolute percent error), MAE and RMSE are metrics that measure forecast error; It allows you to evaluate the accuracy of the model by comparing forecast with actual demand. Cp/Cpk is the process capability and OEE is the equipment efficiency metric.
3. In the reorder point (ROP) calculation, AI gave you a value. What should you do first to use the result safely?
- A) Round the result up and enter it directly into ERP
- B) Ask the AI 'are you sure?' and be satisfied with the answer 'yes'
- C) Print the formula, inputs and units used and reproduce the calculation manually/with code ✔
- D) Completely reset the safety stock
Explanation: It works with the formula ROP = average demand × lead time + safety stock. It is necessary to verify the result the AI gives by explicitly printing out the formula it uses and the inputs (demand rate, lead time, safety stock) and recalculating it manually/in code; otherwise the unit or arithmetic error will not be noticed.
4. What does the shortest processing time (SPT) rule typically improve in job scheduling?
- A) It only resets the setup times
- B) Physically increases the number of machines
- C) Guaranteedly reduces energy consumption by half
- D) Tends to reduce average flow time and average latency ✔
Description: The SPT (Shortest Processing Time) rule tends to reduce the average flow time and average latency by bringing short jobs forward. However, he can constantly postpone long tasks; If the delivery date is critical, rules such as EDD are more appropriate. Rule selection should be justified by purpose.
5. What does it mean if the Cpk value is significantly lower than Cp in SPC?
- A) Process average has shifted from the tolerance center (centering problem) ✔
- B) The variance of the process is zero
- C) It shows that the number of samples is large
- D) Proves that the control chart is unnecessary
Explanation: Cp is the proficiency index that takes into account the ratio of the process spread to the tolerance width, and Cpk is the adequacy index that also takes into account the shift of the average relative to the tolerance center. If Cpk is lower than Cp, it indicates that the process is off-center (the average is away from the target); Even though the spread is the same, there is a centering problem.
6. You use the formula given by AI when calculating standard time in time study. Standard time is obtained correctly by which of the following?
- A) Standard time = Observed time, margin and tempo are not taken into account
- B) Standard time = Normal time × (1 + share ratio); Normal time = Observed time × pace ✔
- C) Standard time = Observed time ÷ number of machines
- D) Standard time is always the time of the fastest operator
Explanation: Calculated as Standard time = Normal time × (1 + Share ratio); Normal time is found by Observed time × Tempo (rating). It is mandatory to add shares (rest, personal, delay). AI can give the formula, but tempo and share values must be verified by actual observation and company policy.
7. AI said it gave the 'best' solution to a vehicle routing (VRP) problem. Which is the most accurate assessment?
- A) Sending the route directly to drivers because the AI says 'best'
- B) Validate the solution against capacity, time window and cost constraints ✔
- C) Just reduce the number of stops and publish
- D) Visualizing the map and ignoring the constraints
Explanation: AI may incorrectly model constraints (vehicle capacity, time windows, driving time) or present a suboptimal solution as 'best'. Solution; It should be checked against capacity, time window and total distance/cost constraints, and if possible, reproduced and compared with a solver.
8. OEE (Overall Equipment Effectiveness) is the product of which three components?
- A) Demand, stock and cost
- B) Cp, Cpk and sigma
- C) Usability, performance and quality ✔
- D) Takt, cycle and delivery time
Explanation: OEE = Availability × Performance × Quality. Availability reflects downtime, performance reflects speed losses, and quality reflects faulty products. If AI gives an OEE value, it is necessary to ensure that these three components are calculated and multiplied separately.
9. What is the most critical verification step when interpreting the output of a discrete-event simulation?
- A) Validating input distributions and assumptions with real data ✔
- B) Shorten the working time and make a decision in a single condition
- C) Improving the color palette of graphics
- D) Hiding the random seed and making the result unrepeatable
Explanation: Simulation output is only as good as the input assumptions. Distributions, inter-arrival time, service times and scenario parameters should be compared and validated with real data; Additionally, it should be checked that the model has been established correctly (verification). Otherwise, 'garbage in, garbage out'.
10. Which is mandatory before using an AI-generated Python optimization script in a production decision?
- A) Applying the result directly since the code works without errors
- B) Testing with known results, validating with unit checking and edge cases, and protecting data confidentiality ✔
- C) Shorten variable names and delete comments
- D) Uploading the script with all production data to a public service
Description: AI code may contain incorrect unit conversion, incorrect constraint, or incorrect result in edge cases. Code; Small test inputs with known results should be verified by unit/size control and edge cases, and confidential production data should not be sent to external services without permission. The result is confirmed by engineering judgment.