|
| 1 | +# Amazon Braket SDK Cheat Sheet |
| 2 | + |
| 3 | +A one-page, browsable reference for the most common Amazon Braket SDK calls, |
| 4 | +published as a static site to GitHub Pages and mirrored as a single flat |
| 5 | +Markdown file for LLM agents. |
| 6 | + |
| 7 | +This directory contains the **source**. The published site is built from it by |
| 8 | +the [`publish-cheat-sheet.yml`](../../.github/workflows/publish-cheat-sheet.yml) |
| 9 | +workflow on every push to `main`. |
| 10 | + |
| 11 | +## Layout |
| 12 | + |
| 13 | +``` |
| 14 | +doc/cheat_sheet/ |
| 15 | +├── _config.yml # Jekyll config + per-language UI strings |
| 16 | +├── _data/blocks.yml # the ordered list of sections (the source of truth for order) |
| 17 | +├── _includes/ |
| 18 | +│ ├── blocks.html # renders each section from blocks.yml |
| 19 | +│ ├── header.html # the language switcher |
| 20 | +│ ├── en/*.md # English sections (one Markdown table per topic) |
| 21 | +│ └── fr/*.md # French sections (same code, translated descriptions) |
| 22 | +├── _layouts/default.html # page shell |
| 23 | +├── _scripts/ |
| 24 | +│ ├── verify_snippets.py # tests the snippets against the installed SDK |
| 25 | +│ └── generate_genai_cheat_sheet.py # builds ../genai_cheat_sheet.md |
| 26 | +├── index.html # English entry point |
| 27 | +├── index.fr.html # French entry point |
| 28 | +└── cheatsheet.css # styling |
| 29 | +``` |
| 30 | + |
| 31 | +The generated companion file lives at [`../genai_cheat_sheet.md`](../genai_cheat_sheet.md). |
| 32 | + |
| 33 | +## A section is a small Markdown table |
| 34 | + |
| 35 | +Each file in `_includes/en/` is a borderless two-column table, one row per call: |
| 36 | + |
| 37 | +```markdown |
| 38 | +| Imports | `from braket.circuits import Circuit` | |
| 39 | +| Create a circuit | `circuit = Circuit()` | |
| 40 | +``` |
| 41 | + |
| 42 | +The left cell is a short description, the right cell is the code (wrap code in |
| 43 | +backticks). Use `<br>` to put several lines in one cell. |
| 44 | + |
| 45 | +### Hints for the LLM file |
| 46 | + |
| 47 | +The HTML site hides comments, but the GenAI file keeps them. Use them to add |
| 48 | +context that only a machine reader needs: |
| 49 | + |
| 50 | +```markdown |
| 51 | +| Create a circuit<!-- LLM: . Note the number of qubits is not a constructor argument--> | `circuit = Circuit()` | |
| 52 | +``` |
| 53 | + |
| 54 | +The hint text is folded into the description in `genai_cheat_sheet.md`. |
| 55 | + |
| 56 | +## Add or edit a section |
| 57 | + |
| 58 | +1. Edit the relevant file in `_includes/en/` (or create a new `NewTopic.md`). |
| 59 | +2. If it is a **new** section, register it in `_data/blocks.yml` at the position |
| 60 | + you want it to appear: |
| 61 | + ```yaml |
| 62 | + - file: NewTopic.md |
| 63 | + title: New Topic |
| 64 | + fr: Nouveau sujet |
| 65 | + ``` |
| 66 | +3. Add the matching translation in `_includes/fr/NewTopic.md`. **Keep the code |
| 67 | + identical to English** — only translate the descriptions. Every section must |
| 68 | + exist in every language or the site build fails. |
| 69 | +4. Verify and regenerate (below). |
| 70 | + |
| 71 | +## Verify your changes |
| 72 | + |
| 73 | +The snippets are executable, not decorative. Run the verifier against an |
| 74 | +installed copy of the SDK: |
| 75 | + |
| 76 | +```bash |
| 77 | +pip install . |
| 78 | +python doc/cheat_sheet/_scripts/verify_snippets.py |
| 79 | +``` |
| 80 | + |
| 81 | +It checks that: |
| 82 | + |
| 83 | +- every `import` in the cheat sheet resolves against the SDK, |
| 84 | +- every translated section carries the **same code** as English, |
| 85 | +- the GenAI Markdown file is in sync, and |
| 86 | +- the local (non-cloud) snippets actually run on `LocalSimulator` and friends. |
| 87 | + |
| 88 | +## Regenerate the GenAI file |
| 89 | + |
| 90 | +After changing any section, rebuild the flat Markdown companion: |
| 91 | + |
| 92 | +```bash |
| 93 | +python doc/cheat_sheet/_scripts/generate_genai_cheat_sheet.py |
| 94 | +``` |
| 95 | + |
| 96 | +Use `--check` to verify it is up to date without writing (this is what CI runs): |
| 97 | + |
| 98 | +```bash |
| 99 | +python doc/cheat_sheet/_scripts/generate_genai_cheat_sheet.py --check |
| 100 | +``` |
| 101 | + |
| 102 | +## Preview the site locally |
| 103 | + |
| 104 | +The site is a standard Jekyll project. The [`Gemfile`](Gemfile) here pins Jekyll |
| 105 | +so you get a faithful local preview of the same sources. (The published site is |
| 106 | +built by GitHub Pages via the publish workflow, not from this Gemfile.) |
| 107 | + |
| 108 | +### Prerequisites |
| 109 | + |
| 110 | +You need Ruby and Bundler. Check what you have: |
| 111 | + |
| 112 | +```bash |
| 113 | +ruby --version # 3.0 or newer is fine |
| 114 | +bundler --version # if this fails, run: gem install bundler |
| 115 | +``` |
| 116 | + |
| 117 | +If you do not have Ruby, follow the Jekyll install guide for your OS: |
| 118 | +https://jekyllrb.com/docs/installation/ |
| 119 | + |
| 120 | +### Build and serve |
| 121 | + |
| 122 | +From this directory: |
| 123 | + |
| 124 | +```bash |
| 125 | +cd doc/cheat_sheet |
| 126 | +bundle install # installs Jekyll and its dependencies (first time only) |
| 127 | +bundle exec jekyll serve # builds the site and starts a local server |
| 128 | +``` |
| 129 | + |
| 130 | +Then open http://127.0.0.1:4000 in your browser. The French page is at |
| 131 | +http://127.0.0.1:4000/fr/. |
| 132 | + |
| 133 | +> The `Gemfile` includes `webrick` because Ruby 3.0+ no longer ships it in the |
| 134 | +> standard library and `jekyll serve` needs it. If you ever see a `webrick` |
| 135 | +> `LoadError`, run `bundle install` again. |
| 136 | + |
| 137 | +## Add a new language |
| 138 | + |
| 139 | +See [`Translation.md`](Translation.md) for the end-to-end steps (new `_config.yml` |
| 140 | +strings, an `index.TAG.html`, and a translated `_includes/TAG/` folder). |
| 141 | + |
| 142 | +## How it is published |
| 143 | + |
| 144 | +On every push to `main`, the publish workflow builds the Jekyll site, regenerates |
| 145 | +`genai_cheat_sheet.md`, and deploys to GitHub Pages. Pull requests do **not** |
| 146 | +deploy; instead [`validate-cheat-sheet.yml`](../../.github/workflows/validate-cheat-sheet.yml) |
| 147 | +runs the verifier so broken snippets are caught before merge. |
0 commit comments