Skip to content
DenseChip
Learn
PracticeCode labInterview

DenseChip

Navigate

Menu

LearnPracticeCode labInterview

Tools

All toolsSV editorCode repoResume
DenseChip

Practice, courses, and chip-design tools in one focused workspace.

LearnPracticeCode labInterviewToolsLearning paths

© 2026 DenseChip

AboutRoadmapCareersInternshipsFAQContactPrivacyTerms
Skip to lesson

Course contents

  • Getting Started with AI for VLSI Engineers5
  • Just Enough AI: Models and Context15
  • Prompting13
  • Trust and Verification14
  • Using AI for Engineering Work17
    • RTL and Testbench Assistance
    • Debugging with AI
    • Scripts and Automation
      • Reviewing Generated Scripts
      • Idempotence and Dry-Run Flags
      • Testing a Script on a Copy
      • A Small Static Checker for Scripts
    • Data, Privacy and IP
  • Engineering Walkthroughs7
  • Practical Foundations for AI Workflows4
  • Engineering Data5
  • Retrieval-Augmented Generation6
  • Agents and Tool Use18
  • Agent Design8
  • MCP and Skills6
  • Multi-Agent Design6
  • Practical Capstone6
  • Tokens, Cost and Latency12
  • Agentic Workflows for Chip Teams18
  • Interview and Judgment10
  • AI Skills: Full Course Index
  • Working with AI Glossary
  • Working with AI Cheatsheet
Loading lesson

←Scripts and Automation
  1. Topics
  2. AI Skills for VLSI Engineers
  3. Using AI for Engineering Work
  4. Scripts and Automation
  5. Idempotence and Dry-Run Flags
On this page

    Everyday Engineering AssistanceBeginner to Intermediate

    Idempotence and Dry-Run Flags

    Idempotent steps and dry-run flags that make reruns safe and previews exact.

    Idempotent steps

    A step is idempotent when running it twice leaves the same state as running it once. Directory creation and fixed-content copies qualify, while bare appends do not.

    Step

    Idempotent

    Why

    Create directory if missing

    Yes

    The second run finds the directory already there.

    Copy a fixed file over its target

    Yes

    The same bytes land on every run.

    Append a line to a log

    No

    Each run adds another line.

    Install the newest release

    No

    The newest release may differ between runs.

    Dry-run flags

    Many tools preview work with a flag such as make -n or a --dry-run spelling. The exact spelling and output vary by tool, so check the local manual.

    The transcript below is schematic, not output from a specific system. Nothing here is executed.

    plaintext
    1
    2
    3
    4
    schematic transcript (not run here):
    $ make -n clean
    rm -f build/a.o build/b.o
    the two listed paths are the whole planned effect

    Rerun arithmetic

    The program below models one setup step with a preview mode. The preview changes nothing, the live run sets four keys, and a rerun adds nothing.

    example.py
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    import sys
    
    def apply_step(state, dry_run):
        planned = ["host_list", "report_dir", "index", "stamp"]
        if dry_run:
            return list(planned)
        for key in planned:
            state[key] = 1
        return list(planned)
    
    def main():
        bad = 0
        state = {}
        preview = apply_step(state, True)
        if len(preview) != 4:
            bad += 1
        if len(state) != 0:
            bad += 1
        apply_step(state, False)
        if len(state) != 4:
            bad += 1
        before = sorted(state)
        apply_step(state, False)
        if sorted(state) != before:
            bad += 1
        if len(state) != 4:
            bad += 1
        if bad:
            print("FAIL: dry-run counts wrong")
            sys.exit(1)
        print("PASS: dry run changes 0 keys, live run sets 4 keys, rerun sets 0")
    
    main()

    Assume, as a stated example parameter, each unchecked rerun has a 0.8 chance of leaving state clean. Independence across reruns is also assumed.

    plaintext
    assume clean chance per rerun = 0.8 (stated example parameter, independent reruns)
    three reruns all clean: 0.8^3 = 0.8 x 0.8 x 0.8 = 0.512
    about 51 of 100 such triples stay clean, and the rest need repair
    plaintext
    assume 1 million input tokens cost 3 units (stated example price)
    one 20000-token log review costs 20000 / 1000000 x 3 = 0.06 units
    ten such reviews cost 10 x 0.06 = 0.6 units

    Common mistakes

    Rerunning a non-idempotent helper to fix a partial failure. The repair run appends or reinstalls on top of half-done state and doubles the mess.

    Ask the assistant for a preview flag and a fixed-version install in the same draft. Both lines are cheap to add before the first run.

    Likely probes: the definition and the preview habit.

    • Idempotent means twice leaves the state of once.

    • Preview first with the tool's own dry-run flag.

    • Rerun arithmetic needs stated parameters, never vendor figures.

    Check yourself A setup step sets four keys on the first live run. What does a correct rerun change?

    Nothing. The rerun finds all four keys already set and adds zero.

    Check yourself Each unchecked rerun has a 0.8 chance of leaving state clean. What is the chance that three independent reruns all stay clean?

    0.512. Three factors of 0.8 multiply to 0.512.

    Related topics

    • Testing a script on a copy

    • Debugging with AI

    Previous

    58 / 173

    Next: Testing a Script on a Copy

    Up next

    Up nextTesting a Script on a Copy

    Sign in to save progress

    Practice this lessonPrevious lessonReport an error

    See also

    • A Small Static Checker for Scripts