Skip to content

Commit

Permalink
add cheat sheet
Browse files Browse the repository at this point in the history
  • Loading branch information
jcjaskula-aws committed Jun 4, 2024
1 parent d5dfbf4 commit 067b4b8
Show file tree
Hide file tree
Showing 50 changed files with 994 additions and 0 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/publish-cheat-sheet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Publish Cheat Sheet

on:
push:
branches:
- main

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write

# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Pages
uses: actions/configure-pages@v5
- name: Build with Jekyll
uses: actions/jekyll-build-pages@v1
with:
source: ./doc/cheat_sheet
destination: ./_site
- name: Upload artifact
uses: actions/upload-pages-artifact@v3

deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
23 changes: 23 additions & 0 deletions doc/cheat_sheet/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
MIT License

Original (Julia cheat sheet) Copyright (c) 2015 Ian Hellström
Original (Julia cheat sheet) Copyright (c) 2016 Harris Brakmic
Modifications (Braket cheat sheet) Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
17 changes: 17 additions & 0 deletions doc/cheat_sheet/Translation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Translation Guide

TL;DR:

- See `_config.yml`, `index.br.html` and `_includes/`

The translation of this cheat-sheet requires the followings steps:

- Choose a tag for your language, such as `en` for English or `fr` for French;
- On [`_config.yml`](_config.yml), add your tag and translate the given phrases;
- Copy `index.html` to `index.TAG.html`, where TAG is your tag;
- Modify `index.TAG.html`, changing `lang: TAG` and `permalink: /TAG/`;
- Copy the folder `_includes/en/` to `_includes/TAG/`, i.e., create a folder `TAG`
inside `_includes` with a copy of all the `.md` files; **don't change the .md names**;
- On file `_data/blocks.yml`, add a ` TAG: translated title` line for each title;
- Translate each block in `_includes/TAG`.

23 changes: 23 additions & 0 deletions doc/cheat_sheet/_config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
domain: amazon-braket.github.io
title: The Fast Track to Amazon Braket
description: "The Fast Track to Amazon Braket - Braket Cheat Sheet"
github_username: amazon-braket
markdown: kramdown

t:
en:
name: "English"
fast-track: "The Fast Track to Amazon Braket"
github-1: "This page's source is"
github-2: "located here"
github-3: "Pull requests are welcome!"
github-4: "This cheat sheet is inspired by"
translate: "Help translate!" # Not used for `en`
fr:
name: "Français"
fast-track: "Aide-mémoire"
github-1: "Les sources de cette page sont"
github-2: "disponibles ici"
github-3: "Pull Requests bienvenues !"
github-4: "Cet aide-memoire est inspiré de"
translate: "Aidez à traduire !" # Not used for `en`
41 changes: 41 additions & 0 deletions doc/cheat_sheet/_data/blocks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
- file: What-is.md
title: What is…?
fr: De quoi s'agit-il ?
- file: Circuits.md
title: Circuits
fr: Circuits
- file: FreeParameters.md
title: FreeParameters
fr: Paramètres libres
- file: Tasks.md
title: Tasks
fr: Tâches
- file: Results.md
title: Results
- file: Device.md
title: Device
- file: DeviceProperties.md
title: Device Properties
- file: Pricing.md
title: Pricing
- file: HybridJobs.md
title: Hybrid Jobs
fr: Tâches
- file: Simulators.md
title: Simulators
- file: NoiseSimulation.md
title: Noise Simulation
- file: LLDC.md
title: Low-Level Device Control
- file: AHS.md
title: Analog Hamiltonian Simulation
- file: ErrorMitigation.md
title: Error Mitigation
- file: Console.md
title: Console
- file: APICalls.md
title: API Calls
- file: QiskitProvider.md
title: Qiskit Provider
- file: Resources.md
title: Resources
22 changes: 22 additions & 0 deletions doc/cheat_sheet/_includes/blocks.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<div id="contents">
<ul>
<li>
{% for block in site.data.blocks %}
<div class="box">
<div class="title">

{% if page.lang == "en" %}
<h1>{{ block.title }}</h1>
{% elsif block[page.lang] %}
<h1>{{ block[page.lang] }}</h1>
{% else %}
<h1>{{ block.title }} <small>({{ site.t[page.lang].translate }})</small> </h1>
{% endif %}
</div>
{% capture this_block %}{% include {{page.lang}}/{{ block.file }} %}{% endcapture %}
{{ this_block | markdownify }}
</div>
{% endfor %}
</li>
</ul>
</div>
7 changes: 7 additions & 0 deletions doc/cheat_sheet/_includes/en/AHS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
| Imports | `from braket.ahs import AtomArrangement, DrivingField, AnalogHamiltonianSimulation` |
| Atom arrangement | `register = AtomArrangement()` |
| Add an atom by coordinates (in meters) | `register.add((5.7e-6, 5.7e-6))` |
| Get coordinates | `register.coordinate_list(axis)` |
| Create a driving field | `DrivingField(amplitude, phase, detuning)` |
| Create an AHS program | `ahs_program = AnalogHamiltonianSimulation(register, drive)` |
| Run an AHS program | `device.run(ahs_program)` |
13 changes: 13 additions & 0 deletions doc/cheat_sheet/_includes/en/APICalls.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
| Cancel a Braket hybrid job | CancelJob |
| Cancel the specified task | CancelQuantumTask |
| Create a Braket hybrid job | CreateJob |
| Create a quantum task | CreateQuantumTask |
| Retrieve the devices available in Braket | GetDevice |
| Retrieve the specified Braket hybrid job | GetJob |
| Retrieve the specified quantum task | GetQuantumTask |
| Show the tags associated with this resource | ListTagsForResource |
| Search for devices using the specified filters | SearchDevices |
| Search for Braket hybrid jobs that match the specified filter values | SearchJobs |
| Search for tasks that match the specified filter values | SearchQuantumTasks |
| Add a tag to the specified resource | TagResource |
| Remove tags from a resource | UntagResource |
15 changes: 15 additions & 0 deletions doc/cheat_sheet/_includes/en/Circuits.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
| Imports | `from braket.circuits import Circuit, Gate, Instruction`<br>`from braket.circuits.observables import X` |
| Create a circuit | `circuit = Circuit()` |
| Add gates | `circuit.x(0).rx(1, 1.23).cnot(0, 1)` |
| Get the list of available gates | `[attr for attr in dir(Gate) if attr[0].isupper()]` |
| Apply a unitary matrix | `circuit.unitary(matrix, [0])` |
| Get the circuit unitary | `circuit.to_unitary()` |
| Add a result type | `circuit.probability(0)`<br>`circuit.expectation(0.5 * X() @ X(), target=[0, 1])` |
| List of the available result types | adjoint_gradient, amplitude, density_matrix, expectation, probability, sample, state_vector, variance |
| Add a verbatim box | `circuit.add_verbatim_box(circuit2)` |
| Gate modifiers | `circuit.x(0, control=[1, 2], control_state=[0, 1], power=-0.5)` |
| Draw a circuit | `print(circuit)` |
| Import from OpenQASM3 | `Circuit.from_ir(source=qasm_str)` |
| Export to OpenQASM3 | `Circuit.to_ir("OPENQASM")` |
| Create an instruction | `inst = Instruction(Gate.CPhaseShift(1.23), target=[0, 1])` |
| Add an instruction | `circuit.add(inst)` |
5 changes: 5 additions & 0 deletions doc/cheat_sheet/_includes/en/Console.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
The console is a web interface where you can find important up-to-date information about the Braket service and the available devices.

| Device tab | Device summary<br>Connectivity |
| Notebook | Jupyter hub |
| Braket Direct | Device reservation<br>Office hours |
5 changes: 5 additions & 0 deletions doc/cheat_sheet/_includes/en/Device.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
| Imports | `from braket.aws import AwsDevice`<br>`from braket.devices import Devices` |
| Instantiate a device | `AwsDevice("<deviceARN>")` |
| Device alias (use in place of string ARN) | `Devices.Rigetti.AspenM3` |
| Queue depth | `device.queue_depth()` |
| Gate pulse implementation | `device.gate_calibrations` |
7 changes: 7 additions & 0 deletions doc/cheat_sheet/_includes/en/DeviceProperties.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
| Connectivity graph| `device.properties.paradigm.connectivity` |
| Fidelities dictionary| `device.properties.provider.specs` |
| Native gate set| `device.properties.paradigm.nativeGateSet` |
| Cost and availability| `device.properties.service` |
| Pulse properties| `device.properties.pulse` |
| Actions properties| `action_properties = device.properties.action['braket.ir.openqasm.program']` |
| Supported gates| `action_properties.supportedOperations` |
2 changes: 2 additions & 0 deletions doc/cheat_sheet/_includes/en/ErrorMitigation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
| Debias | `device.run(circuit, shots=2500, device_parameters={"errorMitigation": Debias()})` |
| Sharpening (if debiasing used) | `result.additional_metadata.ionqMetadata.sharpenedProbabilities` |
7 changes: 7 additions & 0 deletions doc/cheat_sheet/_includes/en/FreeParameters.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
| Imports | `from braket.circuits import FreeParameter` |
| Create a free parameter | `alpha = FreeParameter(“alpha”)` |
| Use a free Parameter | `circuit.rx(0, alpha)`|
| Free parameter algebra | `beta = 2 * alpha + 1`|
| Bind a value | `circuit.make_bound_circuit({“alpha”: 0.1})`|
| Get the list of unbound FreeParameters| `circuit.parameters`|
| Inline compilation| `device.run(circuit, inputs={“alpha”: 0.1})`|
5 changes: 5 additions & 0 deletions doc/cheat_sheet/_includes/en/HybridJobs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
| Imports | `from braket.aws import AwsQuantumJob` |
| Create a job | `job = AwsQuantumJob.create(arn, source_module="algorithm_script.py", entry_point="algorithm_script:start_here", wait_until_complete=True)` |
| Queue position | `job.queue_position()` |
| Job decorator | `@hybrid_job(device=None, local=True)` |
| Records Braket Hybrid Job metrics | `log_metric(metric_name, value, iteration_number)` |
13 changes: 13 additions & 0 deletions doc/cheat_sheet/_includes/en/LLDC.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
| Imports | `from braket.pulse import PulseSequence, Frame`<br>`from braket.pulse.waveforms import *` |
| Create a new pulse sequence | `pulse_sequence = PulseSequence()` |
| Predefined ports | `device.ports` |
| Predefined frames | `device.frames` |
| Create a frame | `Frame(port, frequency[, phase])` |
| Predefined waveforms | `ConstantWaveform(length, iq)`<br>`GaussianWaveform(length, width, amplitude, zero_at_edges)`<br>`DragGaussianWaveform(length, width, amplitude, beta, zero_at_edges)` |
| Play a waveform | `pulse_sequence.play(frame, waveform)` |
| Add a delay | `pulse_sequence.delay(frame, delay)` |
| Set frequency | `pulse_sequence.set_frequency(frame, frequency)` |
| Shift frequency | `pulse_sequence.shift_frequency(frame, detuning)` |
| Set phase | `pulse_sequence.set_phase(frame, phase)` |
| Shift phase | `pulse_sequence.shift_phase(frame, phi)` |
| Get the time series | `pulse_sequence.to_time_traces()` |
5 changes: 5 additions & 0 deletions doc/cheat_sheet/_includes/en/NoiseSimulation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
| Imports | `from braket.circuits import Noise` |
| Depolarizing noise | `circuit.depolarizing(0, 0.1)` |
| Apply a Kraus operator | `circuit.kraus([0,2], [E0, E1])` |
| Phase dampling channel | `noise = Noise.PhaseDamping(0.1)` |
| Apply a noise channel | `circuit.apply_gate_noise(noise, Gate.X)` |
4 changes: 4 additions & 0 deletions doc/cheat_sheet/_includes/en/Pricing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
| Imports | `from braket.tracking import Tracker` |
| Start the cost tracker | `tracker=Tracker().start()` |
| Print costs | `tracker.qpu_tasks_cost()`<br>`tracker.simulator_tasks_cost()` |
| Cost summary | `tracker.quantum_tasks_statistics()` |
3 changes: 3 additions & 0 deletions doc/cheat_sheet/_includes/en/QiskitProvider.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
| Imports | `from qiskit_braket_provider import AWSBraketProvider` |
| Instantiate a provider | `provider = AWSBraketProvider()` |
| Instantiate a backend | `provider.get_backend(name)` |
10 changes: 10 additions & 0 deletions doc/cheat_sheet/_includes/en/Resources.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
- [Amazon Braket](https://aws.amazon.com/braket/)
- [Official documentation](https://docs.aws.amazon.com/braket/)
- [AWS Quantum blog](https://aws.amazon.com/blogs/quantum-computing/)
- [Braket Python SDK source](https://github.com/amazon-braket/amazon-braket-sdk-python)
- [Default simulator source](https://github.com/amazon-braket/amazon-braket-default-simulator-python)
- [Notebook examples](https://github.com/amazon-braket/amazon-braket-examples)
- [Algorithm library](https://github.com/amazon-braket/amazon-braket-algorithm-library/tree/main)
- [Pennylane plugin](https://github.com/amazon-braket/amazon-braket-pennylane-plugin-python)
- [Qiskit-Braket plugin](https://github.com/qiskit-community/qiskit-braket-provider)
- [Braket Julia SDK](https://github.com/amazon-braket/Braket.jl)
4 changes: 4 additions & 0 deletions doc/cheat_sheet/_includes/en/Results.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
| Retrieve results | `result = task.results()` |
| Get measurement counts | `result.measurement_counts` |
| Get measured qubits | `result.measured_qubits` |
| Get compiled circuit | `result.get_compiled_circuit()` |
2 changes: 2 additions & 0 deletions doc/cheat_sheet/_includes/en/Simulators.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
| Imports | `from braket.devices import LocalSimulator` |
| Instantiate the local simulator | `local_sim = LocalSimulator()` |
6 changes: 6 additions & 0 deletions doc/cheat_sheet/_includes/en/Tasks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
| Imports | `from braket.aws import AwsSession, AwsQuantumTask` |
| Create a quantum task by executing a circuit | `task = device.run(circuit)` |
| disable qubit rewiring| `device.run(circuit, disable_qubit_rewiring=True)` |
| Instantiate an AwsSession| `session = AwsSession(...)` |
| Recreate a quantum task| `task = AwsQuantumTask(arn[, aws_session])` |
| Queue position| `task.queue_position()` |
1 change: 1 addition & 0 deletions doc/cheat_sheet/_includes/en/What-is.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[Amazon Braket](https://aws.amazon.com/braket/) is a fully managed AWS service that helps researchers, scientists, and developers get started with quantum computing. <a class="tooltip" href="#">Quantum computing<span> My tooltip</span></a> has the potential to solve some computational problems that are beyond the reach of classical computers because it harnesses the laws of quantum mechanics to process information in new ways.
8 changes: 8 additions & 0 deletions doc/cheat_sheet/_includes/fr/AHS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
| | |
| -------------------- | ----------------------------------------------------- |
| Atom arrangement | register = AtomArrangement() |
| Add an atom | register.add((5.7e-6, 5.7e-6)) |
| Get coordinates | register.coordinate_list(axis) |
| Create a driving field | DrivingField(amplitude, phase, detuning) |
| Create an AHS program | ahs_program = AnalogHamiltonianSimulation(register, drive) |
| Run an AHS program | device.run(ahs_program) |
2 changes: 2 additions & 0 deletions doc/cheat_sheet/_includes/fr/APICalls.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
| | |
| -------------------- | ----------------------------------------------------- |
9 changes: 9 additions & 0 deletions doc/cheat_sheet/_includes/fr/Basics.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
| | |
| -------------------- | ----------------------------------------------------- |
| Assignment | `answer = 42`<br>`x, y, z = 1, [1:10; ], "A string"`<br>`x, y = y, x # swap x and y` |
| Constant declaration | `const DATE_OF_BIRTH = 2012` |
| End-of-line comment | `i = 1 # This is a comment` |
| Delimited comment | `#= This is another comment =#` |
| Chaining | `x = y = z = 1 # right-to-left`<br>`0 < x < 3 # true`<br>`5 < x != y < 5 # false` |
| Function definition | `function add_one(i)`<br>` return i + 1`<br>`end` |
| Insert LaTeX symbols | `\delta` + [Tab] |
11 changes: 11 additions & 0 deletions doc/cheat_sheet/_includes/fr/Circuits.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
| | |
| --------------------------------- | ------------------------------------------- |
| Create a circuit | `circuit = Circuit()` |
| Add gates | `circuit.x(0).cnot(0, 1)` |
| Apply a unitary matrix | `circuit.unitary(matrix, [0])` |
| Add a result type | `circuit.probability(0)` |
| Add a verbatim box | `circuit.add_verbatim_box(circuit2)` |
| Gate modifiers | `circuit.x(0, control=1, neg_control=2)` |
| Plot a circuit | `print(circuit)` |
| Observables | |
| Import from OpenQASM3 | `Circuit.from_ir(source)` |
2 changes: 2 additions & 0 deletions doc/cheat_sheet/_includes/fr/Console.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
| | |
| -------------------- | ----------------------------------------------------- |
6 changes: 6 additions & 0 deletions doc/cheat_sheet/_includes/fr/Device.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
| | |
| -------------------- | ----------------------------------------------------- |
| Instantiate a device| AwsDevice(arn)|
| Queue depth| device.queue_depth()|
| Device helper objects| Devices.Rigetti.Aspen-M3|
| Gate pulse implementation| device.gate_calibrations|
9 changes: 9 additions & 0 deletions doc/cheat_sheet/_includes/fr/DeviceProperties.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
| | |
| -------------------- | ----------------------------------------------------- |
| Connectivity graph| device.properties.paradigm.connectivity|
| Fidelities dictionary| device.properties.provider.specs|
| Native gate set| device.properties.paradigm.nativeGateSet|
| Cost and availability| device.properties.service|
| Pulse properties| device.properties.pulse|
| Actions properties| action_properties = device.properties.action['braket.ir.openqasm.program']|
| Supported gates| action_properties.supportedOperations|
4 changes: 4 additions & 0 deletions doc/cheat_sheet/_includes/fr/ErrorMitigation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
| | |
| -------------------- | ----------------------------------------------------- |
| Debias | task = device.run(circuit, device_parameters={"errorMitigation": Debias()}) |
| Sharpening | result.additional_metadata.ionqMetadata.sharpenedProbabilities |
7 changes: 7 additions & 0 deletions doc/cheat_sheet/_includes/fr/FreeParameters.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
| | |
| -------------------- | ----------------------------------------------------- |
| Create a FreeParameter | `alpha=FreeParameter(“alpha”)` |
| Use FreeParameters | `circuit.rx(0, alpha+1)`|
| Bind a FreeParameter()| `circuit.make_bound_circuit({“alpha”: 0.1})`|
| Get the list of unbound FreeParameters| `circuit.parameters`|
| Inline compilation| `device.run(circuit, inputs={“alpha”: 0.1})`|
5 changes: 5 additions & 0 deletions doc/cheat_sheet/_includes/fr/HybridJobs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
| | |
| -------------------- | ----------------------------------------------------- |
| Create a job | job = AwsQuantumJob.create(arn, source_module="algorithm_script.py", entry_point="algorithm_script:start_here", wait_until_complete=True) |
| Queue position | job.queue_position() |
| Job decorator | @hybrid_job(device=None, local=True) |
Loading

0 comments on commit 067b4b8

Please sign in to comment.