diff --git a/.github/workflows/publish-cheat-sheet.yml b/.github/workflows/publish-cheat-sheet.yml new file mode 100644 index 000000000..0e9729226 --- /dev/null +++ b/.github/workflows/publish-cheat-sheet.yml @@ -0,0 +1,50 @@ +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: Compile cheat sheet for genAI + run: sudo python3 doc/cheat_sheet/_scripts/generate_genAI_cheat_sheet.py -d _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 diff --git a/doc/cheat_sheet/LICENSE b/doc/cheat_sheet/LICENSE new file mode 100644 index 000000000..e4c408213 --- /dev/null +++ b/doc/cheat_sheet/LICENSE @@ -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. diff --git a/doc/cheat_sheet/Translation.md b/doc/cheat_sheet/Translation.md new file mode 100644 index 000000000..b5e05916e --- /dev/null +++ b/doc/cheat_sheet/Translation.md @@ -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`. + diff --git a/doc/cheat_sheet/_config.yml b/doc/cheat_sheet/_config.yml new file mode 100644 index 000000000..5ecb3d672 --- /dev/null +++ b/doc/cheat_sheet/_config.yml @@ -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` diff --git a/doc/cheat_sheet/_data/blocks.yml b/doc/cheat_sheet/_data/blocks.yml new file mode 100644 index 000000000..46423afe5 --- /dev/null +++ b/doc/cheat_sheet/_data/blocks.yml @@ -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 diff --git a/doc/cheat_sheet/_includes/blocks.html b/doc/cheat_sheet/_includes/blocks.html new file mode 100644 index 000000000..64bccbbb4 --- /dev/null +++ b/doc/cheat_sheet/_includes/blocks.html @@ -0,0 +1,22 @@ +
+ +
diff --git a/doc/cheat_sheet/_includes/en/AHS.md b/doc/cheat_sheet/_includes/en/AHS.md new file mode 100644 index 000000000..3b47bf2d7 --- /dev/null +++ b/doc/cheat_sheet/_includes/en/AHS.md @@ -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)` | diff --git a/doc/cheat_sheet/_includes/en/APICalls.md b/doc/cheat_sheet/_includes/en/APICalls.md new file mode 100644 index 000000000..b6dc0e15b --- /dev/null +++ b/doc/cheat_sheet/_includes/en/APICalls.md @@ -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 | \ No newline at end of file diff --git a/doc/cheat_sheet/_includes/en/Circuits.md b/doc/cheat_sheet/_includes/en/Circuits.md new file mode 100644 index 000000000..35f24aebd --- /dev/null +++ b/doc/cheat_sheet/_includes/en/Circuits.md @@ -0,0 +1,15 @@ +| Imports | `from braket.circuits import Circuit, Gate, Instruction`
`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)`
`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)` | \ No newline at end of file diff --git a/doc/cheat_sheet/_includes/en/Console.md b/doc/cheat_sheet/_includes/en/Console.md new file mode 100644 index 000000000..b1a113c68 --- /dev/null +++ b/doc/cheat_sheet/_includes/en/Console.md @@ -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
Connectivity | +| Notebook | Jupyter hub | +| Braket Direct | Device reservation
Office hours | diff --git a/doc/cheat_sheet/_includes/en/Device.md b/doc/cheat_sheet/_includes/en/Device.md new file mode 100644 index 000000000..8dd9fcd9f --- /dev/null +++ b/doc/cheat_sheet/_includes/en/Device.md @@ -0,0 +1,5 @@ +| Imports | `from braket.aws import AwsDevice`
`from braket.devices import Devices` | +| Instantiate a device | `AwsDevice("")` | +| Device alias (use in place of string ARN) | `Devices.Rigetti.AspenM3` | +| Queue depth | `device.queue_depth()` | +| Gate pulse implementation | `device.gate_calibrations` | diff --git a/doc/cheat_sheet/_includes/en/DeviceProperties.md b/doc/cheat_sheet/_includes/en/DeviceProperties.md new file mode 100644 index 000000000..eb83a5b56 --- /dev/null +++ b/doc/cheat_sheet/_includes/en/DeviceProperties.md @@ -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` | diff --git a/doc/cheat_sheet/_includes/en/ErrorMitigation.md b/doc/cheat_sheet/_includes/en/ErrorMitigation.md new file mode 100644 index 000000000..45e1ce0f8 --- /dev/null +++ b/doc/cheat_sheet/_includes/en/ErrorMitigation.md @@ -0,0 +1,2 @@ +| Debias | `device.run(circuit, shots=2500, device_parameters={"errorMitigation": Debias()})` | +| Sharpening (if debiasing used) | `result.additional_metadata.ionqMetadata.sharpenedProbabilities` | \ No newline at end of file diff --git a/doc/cheat_sheet/_includes/en/FreeParameters.md b/doc/cheat_sheet/_includes/en/FreeParameters.md new file mode 100644 index 000000000..68f02fa02 --- /dev/null +++ b/doc/cheat_sheet/_includes/en/FreeParameters.md @@ -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})`| diff --git a/doc/cheat_sheet/_includes/en/HybridJobs.md b/doc/cheat_sheet/_includes/en/HybridJobs.md new file mode 100644 index 000000000..8cd7ebc10 --- /dev/null +++ b/doc/cheat_sheet/_includes/en/HybridJobs.md @@ -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)` | diff --git a/doc/cheat_sheet/_includes/en/LLDC.md b/doc/cheat_sheet/_includes/en/LLDC.md new file mode 100644 index 000000000..e7245c262 --- /dev/null +++ b/doc/cheat_sheet/_includes/en/LLDC.md @@ -0,0 +1,13 @@ +| Imports | `from braket.pulse import PulseSequence, Frame`
`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)`
`GaussianWaveform(length, width, amplitude, zero_at_edges)`
`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()` | diff --git a/doc/cheat_sheet/_includes/en/NoiseSimulation.md b/doc/cheat_sheet/_includes/en/NoiseSimulation.md new file mode 100644 index 000000000..a5de9bbbd --- /dev/null +++ b/doc/cheat_sheet/_includes/en/NoiseSimulation.md @@ -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)` | \ No newline at end of file diff --git a/doc/cheat_sheet/_includes/en/Pricing.md b/doc/cheat_sheet/_includes/en/Pricing.md new file mode 100644 index 000000000..8fac5a42f --- /dev/null +++ b/doc/cheat_sheet/_includes/en/Pricing.md @@ -0,0 +1,4 @@ +| Imports | `from braket.tracking import Tracker` | +| Start the cost tracker | `tracker=Tracker().start()` | +| Print costs | `tracker.qpu_tasks_cost()`
`tracker.simulator_tasks_cost()` | +| Cost summary | `tracker.quantum_tasks_statistics()` | \ No newline at end of file diff --git a/doc/cheat_sheet/_includes/en/QiskitProvider.md b/doc/cheat_sheet/_includes/en/QiskitProvider.md new file mode 100644 index 000000000..8214683af --- /dev/null +++ b/doc/cheat_sheet/_includes/en/QiskitProvider.md @@ -0,0 +1,3 @@ +| Imports | `from qiskit_braket_provider import AWSBraketProvider` | +| Instantiate a provider | `provider = AWSBraketProvider()` | +| Instantiate a backend | `provider.get_backend(name)` | diff --git a/doc/cheat_sheet/_includes/en/Resources.md b/doc/cheat_sheet/_includes/en/Resources.md new file mode 100644 index 000000000..5143bc9ed --- /dev/null +++ b/doc/cheat_sheet/_includes/en/Resources.md @@ -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) \ No newline at end of file diff --git a/doc/cheat_sheet/_includes/en/Results.md b/doc/cheat_sheet/_includes/en/Results.md new file mode 100644 index 000000000..2eaff0f52 --- /dev/null +++ b/doc/cheat_sheet/_includes/en/Results.md @@ -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()` | diff --git a/doc/cheat_sheet/_includes/en/Simulators.md b/doc/cheat_sheet/_includes/en/Simulators.md new file mode 100644 index 000000000..f57c358f7 --- /dev/null +++ b/doc/cheat_sheet/_includes/en/Simulators.md @@ -0,0 +1,2 @@ +| Imports | `from braket.devices import LocalSimulator` | +| Instantiate the local simulator | `local_sim = LocalSimulator()` | \ No newline at end of file diff --git a/doc/cheat_sheet/_includes/en/Tasks.md b/doc/cheat_sheet/_includes/en/Tasks.md new file mode 100644 index 000000000..b4defce9f --- /dev/null +++ b/doc/cheat_sheet/_includes/en/Tasks.md @@ -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()` | diff --git a/doc/cheat_sheet/_includes/en/What-is.md b/doc/cheat_sheet/_includes/en/What-is.md new file mode 100644 index 000000000..9b587015f --- /dev/null +++ b/doc/cheat_sheet/_includes/en/What-is.md @@ -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. Quantum computing My tooltip 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. diff --git a/doc/cheat_sheet/_includes/fr/AHS.md b/doc/cheat_sheet/_includes/fr/AHS.md new file mode 100644 index 000000000..fb6c5757b --- /dev/null +++ b/doc/cheat_sheet/_includes/fr/AHS.md @@ -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) | diff --git a/doc/cheat_sheet/_includes/fr/APICalls.md b/doc/cheat_sheet/_includes/fr/APICalls.md new file mode 100644 index 000000000..365e1fda0 --- /dev/null +++ b/doc/cheat_sheet/_includes/fr/APICalls.md @@ -0,0 +1,2 @@ +| | | +| -------------------- | ----------------------------------------------------- | \ No newline at end of file diff --git a/doc/cheat_sheet/_includes/fr/Basics.md b/doc/cheat_sheet/_includes/fr/Basics.md new file mode 100644 index 000000000..b18d82602 --- /dev/null +++ b/doc/cheat_sheet/_includes/fr/Basics.md @@ -0,0 +1,9 @@ +| | | +| -------------------- | ----------------------------------------------------- | +| Assignment | `answer = 42`
`x, y, z = 1, [1:10; ], "A string"`
`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`
`0 < x < 3 # true`
`5 < x != y < 5 # false` | +| Function definition | `function add_one(i)`
` return i + 1`
`end` | +| Insert LaTeX symbols | `\delta` + [Tab] | diff --git a/doc/cheat_sheet/_includes/fr/Circuits.md b/doc/cheat_sheet/_includes/fr/Circuits.md new file mode 100644 index 000000000..1cecf5893 --- /dev/null +++ b/doc/cheat_sheet/_includes/fr/Circuits.md @@ -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)` | \ No newline at end of file diff --git a/doc/cheat_sheet/_includes/fr/Console.md b/doc/cheat_sheet/_includes/fr/Console.md new file mode 100644 index 000000000..365e1fda0 --- /dev/null +++ b/doc/cheat_sheet/_includes/fr/Console.md @@ -0,0 +1,2 @@ +| | | +| -------------------- | ----------------------------------------------------- | \ No newline at end of file diff --git a/doc/cheat_sheet/_includes/fr/Device.md b/doc/cheat_sheet/_includes/fr/Device.md new file mode 100644 index 000000000..54388b570 --- /dev/null +++ b/doc/cheat_sheet/_includes/fr/Device.md @@ -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| diff --git a/doc/cheat_sheet/_includes/fr/DeviceProperties.md b/doc/cheat_sheet/_includes/fr/DeviceProperties.md new file mode 100644 index 000000000..d18726266 --- /dev/null +++ b/doc/cheat_sheet/_includes/fr/DeviceProperties.md @@ -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| diff --git a/doc/cheat_sheet/_includes/fr/ErrorMitigation.md b/doc/cheat_sheet/_includes/fr/ErrorMitigation.md new file mode 100644 index 000000000..afbe80577 --- /dev/null +++ b/doc/cheat_sheet/_includes/fr/ErrorMitigation.md @@ -0,0 +1,4 @@ +| | | +| -------------------- | ----------------------------------------------------- | +| Debias | task = device.run(circuit, device_parameters={"errorMitigation": Debias()}) | +| Sharpening | result.additional_metadata.ionqMetadata.sharpenedProbabilities | \ No newline at end of file diff --git a/doc/cheat_sheet/_includes/fr/FreeParameters.md b/doc/cheat_sheet/_includes/fr/FreeParameters.md new file mode 100644 index 000000000..2e0096ceb --- /dev/null +++ b/doc/cheat_sheet/_includes/fr/FreeParameters.md @@ -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})`| diff --git a/doc/cheat_sheet/_includes/fr/HybridJobs.md b/doc/cheat_sheet/_includes/fr/HybridJobs.md new file mode 100644 index 000000000..2414808f2 --- /dev/null +++ b/doc/cheat_sheet/_includes/fr/HybridJobs.md @@ -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) | \ No newline at end of file diff --git a/doc/cheat_sheet/_includes/fr/LLDC.md b/doc/cheat_sheet/_includes/fr/LLDC.md new file mode 100644 index 000000000..8d08a6d0e --- /dev/null +++ b/doc/cheat_sheet/_includes/fr/LLDC.md @@ -0,0 +1,12 @@ +| | | +| -------------------- | ----------------------------------------------------- | +| Create a pulse sequence | pulse_sequence = PulseSequence() | +| Dictionary of predefined ports | device.ports | +| Dictionary of predefined frames | device.frames | +| Create a frame | Frame(port, frequency[, phase]) | +| Predefined waveforms | ConstantWaveform(length, iq) | GaussianWaveform(length, width, amplitude, zero_at_edges) | 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 and Shift frequency | pulse_sequence.set_frequency(frame, frequency).shift_frequency(frame, detuning) | +| Set and Shift phase | pulse_sequence.set_phase(frame, phase).shift_phase(frame, phi) | +| Get the time series | pulse_sequence.to_time_traces() | \ No newline at end of file diff --git a/doc/cheat_sheet/_includes/fr/NoiseSimulation.md b/doc/cheat_sheet/_includes/fr/NoiseSimulation.md new file mode 100644 index 000000000..681107ad4 --- /dev/null +++ b/doc/cheat_sheet/_includes/fr/NoiseSimulation.md @@ -0,0 +1,6 @@ +| | | +| -------------------- | ----------------------------------------------------- | +| 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) | \ No newline at end of file diff --git a/doc/cheat_sheet/_includes/fr/Pricing.md b/doc/cheat_sheet/_includes/fr/Pricing.md new file mode 100644 index 000000000..5e4f342c1 --- /dev/null +++ b/doc/cheat_sheet/_includes/fr/Pricing.md @@ -0,0 +1,5 @@ +| | | +| -------------------- | ----------------------------------------------------- | +| Start the cost tracker| tracker=Tracker().start()| +| Print costs| tracker.qpu_tasks_cost()
tracker.simulator_tasks_cost()| +| Cost summary| tracker.quantum_tasks_statistics()| \ No newline at end of file diff --git a/doc/cheat_sheet/_includes/fr/QiskitProvider.md b/doc/cheat_sheet/_includes/fr/QiskitProvider.md new file mode 100644 index 000000000..7b4be4c86 --- /dev/null +++ b/doc/cheat_sheet/_includes/fr/QiskitProvider.md @@ -0,0 +1,3 @@ +| | | +| -------------------- | ----------------------------------------------------- | + diff --git a/doc/cheat_sheet/_includes/fr/Resources.md b/doc/cheat_sheet/_includes/fr/Resources.md new file mode 100644 index 000000000..7916db49e --- /dev/null +++ b/doc/cheat_sheet/_includes/fr/Resources.md @@ -0,0 +1,10 @@ +- [AWS Braket]() +- [Official documentation](). +- [Braket Python SDK]() +- [Local simulators]() +- [Notebook examples]() +- [Algorithm library]() +- [Pennylane plugin]() +- [Braket Julia SDK]() +- [AWS Quantum blog]() + diff --git a/doc/cheat_sheet/_includes/fr/Results.md b/doc/cheat_sheet/_includes/fr/Results.md new file mode 100644 index 000000000..41486553c --- /dev/null +++ b/doc/cheat_sheet/_includes/fr/Results.md @@ -0,0 +1,6 @@ +| | | +| ----------------------------------- | -------------------------------------- | +| Retrieve results | `result = task.results()` | +| Get measurement counts | `result.measurement_counts` | +| Get measured qubits | `result.measured_qubits` | +| Compiled programs | `res.additional_metadata.rigettiMetada.compiledProgram` | \ No newline at end of file diff --git a/doc/cheat_sheet/_includes/fr/Simulators.md b/doc/cheat_sheet/_includes/fr/Simulators.md new file mode 100644 index 000000000..1f1626510 --- /dev/null +++ b/doc/cheat_sheet/_includes/fr/Simulators.md @@ -0,0 +1,3 @@ +| | | +| -------------------- | ----------------------------------------------------- | +| Instantiate the local simulator | local_sim = LocalSimulator() | \ No newline at end of file diff --git a/doc/cheat_sheet/_includes/fr/Tasks.md b/doc/cheat_sheet/_includes/fr/Tasks.md new file mode 100644 index 000000000..20d5b4938 --- /dev/null +++ b/doc/cheat_sheet/_includes/fr/Tasks.md @@ -0,0 +1,7 @@ +| | | +| -------------------- | ----------------------------------------------------- | +| 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:....”[, awssession=session])` | +| Queue position| `task.queue_position()` | diff --git a/doc/cheat_sheet/_includes/fr/What-is.md b/doc/cheat_sheet/_includes/fr/What-is.md new file mode 100644 index 000000000..9b587015f --- /dev/null +++ b/doc/cheat_sheet/_includes/fr/What-is.md @@ -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. Quantum computing My tooltip 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. diff --git a/doc/cheat_sheet/_includes/header.html b/doc/cheat_sheet/_includes/header.html new file mode 100644 index 000000000..e00fb8630 --- /dev/null +++ b/doc/cheat_sheet/_includes/header.html @@ -0,0 +1,28 @@ +
+ {{site.t[page.lang].name}} +
+ + + + {% for lang in site.t %} + {% if lang[0] != "en" %} + + + + {% endif %} + {% endfor %} +
+
+ +
+
+

{{ site.t[page.lang]["fast-track"] }}

+
+ +
+ + \ No newline at end of file diff --git a/doc/cheat_sheet/_layouts/default.html b/doc/cheat_sheet/_layouts/default.html new file mode 100644 index 000000000..3c013c2f9 --- /dev/null +++ b/doc/cheat_sheet/_layouts/default.html @@ -0,0 +1,33 @@ + + + + + + Amazon Braket in a nutshell + + + + +
+ {% include header.html %} +
+ {{ content }} + + + + + + \ No newline at end of file diff --git a/doc/cheat_sheet/braket.svg b/doc/cheat_sheet/braket.svg new file mode 100644 index 000000000..633c81140 --- /dev/null +++ b/doc/cheat_sheet/braket.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/doc/cheat_sheet/cheatsheet.css b/doc/cheat_sheet/cheatsheet.css new file mode 100644 index 000000000..03b9d8d46 --- /dev/null +++ b/doc/cheat_sheet/cheatsheet.css @@ -0,0 +1,497 @@ +@import url('https://fonts.cdnfonts.com/css/amazon-ember'); + +/******************************************************************* + * CSS reset adapted from http://meyerweb.com/eric/tools/css/reset * + *******************************************************************/ + +html, +body, +div, +span, +applet, +object, +iframe, +h1, +h2, +h3, +h4, +h5, +h6, +p, +blockquote, +pre, +a, +abbr, +acronym, +address, +big, +cite, +code, +del, +dfn, +em, +img, +ins, +kbd, +q, +s, +samp, +small, +strike, +sub, +sup, +tt, +var, +b, +u, +i, +center, +dl, +dt, +dd, +ol, +ul, +li, +fieldset, +form, +label, +legend, +table, +caption, +tbody, +tfoot, +thead, +tr, +th, +td, +article, +aside, +canvas, +details, +embed, +figure, +figcaption, +footer, +header, +hgroup, +menu, +nav, +output, +ruby, +section, +summary, +time, +mark, +audio, +video { + margin: 0; + padding: 0; + border: 0; + font-size: 100%; + font: inherit; + vertical-align: baseline; + text-decoration: none; +} + +article, +aside, +details, +figcaption, +figure, +footer, +header, +hgroup, +menu, +nav, +section { + display: block; +} + +body { + line-height: 1; +} + +blockquote, +q { + quotes: none; +} + +blockquote:before, +blockquote:after, +q:before, +q:after { + content: ''; + content: none; +} + +table { + border-collapse: collapse; + border-spacing: 0; + width: 100%; +} + +/****************** + * Variables * + ******************/ +:root { + --box-width: 800px; +} + + + +/****************** + * Custom styling * + ******************/ + +body { + font-family: 'Amazon Ember', sans-serif; + text-align: center; + color: #16191f; + background-color: #f2f3f3; + margin: 0; + font-size: 14px; + line-height: 22px; +} + +h1 { + display: table-cell; + font-size: 200%; + font-weight: bold; + vertical-align: middle; + text-align: right; +} + +h2 { + font-size: 1.2em; + margin: 8px 0px 8px 20px; + color: #545b64; + font-weight: bold; +} + +#top h1 { + display: block; + text-align: right; +} + +#top h2 { + font-family: 'Amazon Ember Cd RC', sans-serif; + font-size: 120%; + text-align: right; + font-weight: normal; +} + +header { + width: 100%; + height: 50px; + line-height: 50px; + position: fixed; + top: 0; + left: 0; + z-index: 99; + background-color: #232f3e; + color: #ffffff; +} + +footer { + width: 100%; + height: 30px; + line-height: 15px; + font-size: 80%; + position: fixed; + bottom: 0; + left: 0; + background-color: #232f3e; + color: #ffffff; +} + +#thanks:before { + content: "Thanks (alphabetically): "; + font-size: larger; +} + +#top { + display: inline-flex; +} + +#title { + margin: auto; +} + +#version { + font-size: larger; + vertical-align: bottom; + margin-left: 0em; + margin-top: auto; + margin-bottom: 1.5em; +} + +#contents { + -webkit-columns: 6 34em; + -moz-columns: 6 34em; + columns: 6 calc(var(--box-width) + 4px); + -webkit-column-gap: 0.25em; + -moz-column-gap: 0.25em; + column-gap: 0.25em; + padding-top: 54px; + padding-bottom: 30px; +} + + +/* + * Note: a coloured box title for a rounded box would require a hidden overflow to + * avoid colour spilling over the border. This, however, clashes with tooltips in + * all but the very first column due to the absolute positioning. + */ + +.box { + display: inline-block; + position: relative; + border-top: 1px solid #eaeded; + box-shadow: 0 1px 1px 0 rgba(0, 28, 36, 0.3), 1px 1px 1px 0 rgba(0, 28, 36, 0.15), -1px 1px 1px 0 rgba(0, 28, 36, 0.15); + text-align: left; + background-color: #ffffff; + margin: 0.5em; + /* padding-bottom: 0.5em; */ + width: var(--box-width); + word-wrap: break-word; +} + +#contents>ol, +ul { + list-style: none; +} + +.box .title { + background: #fafafa; + border-bottom: 1px solid #eaeded; + padding: .5em; +} + +.box h1 { + font-family: 'Amazon Ember V2', sans-serif; + font-size: 120%; + font-weight: bold; + padding: 5px; + color: 16191f; +} + +.box p { + padding: 0.25em 0.5em 0.25em 0.5em; + text-align: justify; +} + +.box em { + font-style: italic; +} + +le .box table { + border-spacing: 0.1em; + border-collapse: collapse; + margin-left: 0.5em; + margin-right: 0.5em; +} + +.box table { + width: var(--box-width); + table-layout: fixed; +} + +.box table td { + padding: 0.1em 0.5em 0.1em 0.5em; + vertical-align: middle; + border: #eaeded; +} + +.box table td:first-child { + width: calc(var(--box-width)/3); +} + +/* .box table tr:nth-child(odd) { + background-color: #ffffff; +} */ + +.box table tr { + border-top: 1px solid #eaeded; +} + +.box table tr:first-child { + border-top: none; +} + +.box ul li { + list-style-type: square; + margin-left: 2em; +} + +.centred { + display: table; + margin-left: auto; + margin-right: auto; +} + +.indented { + display: block; + margin-left: auto; + margin-right: auto; + width: 32em; +} + +pre { + font-family: 'Amazon Ember Mono', sans-serif; + color: #80ab5d; +} + +code { + /* display: inline-block; */ + white-space: pre-wrap; + font-family: 'Amazon Ember Mono', sans-serif; + color: darkgreen; +} + +pre code { + margin-left: 20px; +} + +a { + color: #0073bb; + text-decoration: #2a2a2e; +} + +a:hover { + color: #0a4a74; + text-decoration: underline; +} + +footer a { + color: #fff; +} + +footer a:hover { + color: #ec7211; + text-decoration: none; +} + + +/******************************************************************** + * Tooltip adapted from http://www.menucool.com/tooltip/css-tooltip * + ********************************************************************/ + +a.tooltip { + outline: none; + color: #9e7abe; +} + +a.tooltip:hover { + color: #6b458d; + text-decoration: none; + cursor: help; +} + +a.tooltip span { + display: none; + max-width: 33.5em; + padding: 0.25em; + text-align: center; + color: #2a2a2a; +} + +a.tooltip:hover span { + display: block; + position: absolute; + border: 1px solid #5d5d5d; + background: rgba(195, 195, 195, 0.9); +} + +a.tooltip span { + border-radius: 0.25em; + box-shadow: 0.1em 0.1em 0.1em #909090; +} + +.footer-text { + padding-top: 2em; + padding-bottom: 1em; +} + +.individual-styling>.bold { + color: blue; +} + +.github-info { + font-style: italic; + font-size: smaller; +} + +small { + font-size: smaller; + font-style: italic; +} + +.languages { + display: inline-block; + float: left; + left: 20px; + text-align: left; + position: absolute; + transition: 0.1s; +} + +.language { + width: 32px; + padding: 3px; + vertical-align: middle; +} + +.language-link { + font-size: 1.25em; + background: #e6f2ff; + padding: 5px; +} + +.language-link:hover { + background: #fafcff; +} + +.others { + border: 2px #4d64ae solid; + visibility: hidden; + position: absolute; + z-index: 1; + opacity: 0; + min-width: 260px; + transform: translateY(-2em); + transition: all 0.2s ease-in-out 0s, visibility 0s linear 0.2s; +} + +.languages:hover .others { + visibility: visible; + transform: translateY(0em); + opacity: 1; + transition-delay: 0s, 0s; +} + +.languages a { + text-decoration: none; + color: black; +} + +/* @media(min-width:576px) {} + +@media(min-width:768px) {} + +@media(min-width:992px) { + .box { + width: 35em; + } +} + +@media(min-width:1500px) { + .box { + width: 43em; + } +} + +@media(min-width:1600px) { + .box { + width: 30em; + } +} */ \ No newline at end of file diff --git a/doc/cheat_sheet/favicon.svg b/doc/cheat_sheet/favicon.svg new file mode 100644 index 000000000..f9d583d5f --- /dev/null +++ b/doc/cheat_sheet/favicon.svg @@ -0,0 +1,18 @@ + + + + Icon-Architecture/16/Arch_AWS-Braket_16 + Created with Sketch. + + + + + + + + + + + + + \ No newline at end of file diff --git a/doc/cheat_sheet/index.fr.html b/doc/cheat_sheet/index.fr.html new file mode 100644 index 000000000..5696ab063 --- /dev/null +++ b/doc/cheat_sheet/index.fr.html @@ -0,0 +1,7 @@ +--- +lang: fr +layout: default +permalink: /fr/ +--- + +{% include blocks.html %} diff --git a/doc/cheat_sheet/index.html b/doc/cheat_sheet/index.html new file mode 100644 index 000000000..a9ff1acdc --- /dev/null +++ b/doc/cheat_sheet/index.html @@ -0,0 +1,6 @@ +--- +lang: en +layout: default +--- + +{% include blocks.html %} diff --git a/doc/genai_cheat_sheet.md b/doc/genai_cheat_sheet.md new file mode 100644 index 000000000..ae0092dab --- /dev/null +++ b/doc/genai_cheat_sheet.md @@ -0,0 +1,490 @@ +# Braket CheatSheet + + + +**Circuits** + +***Import Braket modules:*** +``` +from braket.circuits import Circuit, Gate, Instruction +from braket.circuits.observables import X, Y, Z +from braket.circuits.gates import Rx, Ry, Rz, CNot, Unitary, CCNot +from braket.circuits.instruction import Instruction +``` + +***Create an empty circuit (default constructor):*** + +`circuit = Circuit()` + +***Create an circuit with arbitrary number of qubits. Note that number of qubits is not passed as an argument to the circuit constructor:*** + +`circuit = Circuit()` + +***Add X gate to circuit at qubit 0:*** + +`circuit.x(0)` + +***Add Rx gate to qubit 1 with a float angle 1.234 angle = 1.234:*** + +`circuit.rx(1, angle)` + +***Add cnot gate to pair of qubits:*** + +`circuit.cnot(0, 1)` + +***Add gates sequentially: X gate, Rx gate, cnot gate:*** + +`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()]` + +***Create a single qubit gate from unitary matrix:*** + +``` +matrix = np.eye(2) +G = Unitary(matrix) +``` + +***Get the circuit unitary:*** +`circuit.to_unitary()` + +***Add a probability result type to qubit 0 (will return exact probabilities, corresponds to shots=0 case when running on a simulator):*** + +`circuit.probability(0)` + +***Add probability result type to all qubits. Add probability result type only when measuring exact probabilities:*** + +``` +for i in range(len(circuit.qubits)): + circuit.probability(i) +``` + +***Show all result types attached to the circuit:*** + +`print(circuit._result_types)` + +Get circuit depth: + +`circuit.depth` + +Attach Expectation result type to measure both qubits [0, 1] in X basis. +The expectation method allows to pass an arbitrary tensor product of Pauli operators applied to each qubit, e.g. X() @ Y() @ Z(): + +``` +circuit.expectation(X() @ X(), target=[0, 1]); +circuit.expectation(X() @ Y() @ Z(), target=[0, 1, 2]); +``` + +List of the available result types +adjoint_gradient, amplitude, density_matrix, expectation, probability, sample, state_vector, variance: + +`print(circuit._result_types)` + +Append a circuit (new_circuit) to a given circuit: + +`circuit.add_circuit(new_circuit)` + +Wrap a new_circuit to a verbatim box and append to a circuit: + +`circuit.add_verbatim_box(new_circuit)` + +Wrap a circuit to a verbatim box (will be executed without as is without modifications): + +`Circuit().add_verbatim_box(circuit)` + +Gate modifiers (conditional gates with control and target qubits). +Gate modifiers allow to specify a fractional power applied to a gate: + +`circuit.x(0, control=[1, 2], control_state=[0, 1], power=-0.5)` + +Print a circuit: + +`print(circuit)` + +Create circuit from OpenQASM3 string: + +`Circuit.from_ir(source=qasm_str)` + +Export to OpenQASM3: + +`Circuit.to_ir("OPENQASM")` + +Create an instruction from a gate: + +`inst = Instruction(Gate.CPhaseShift(1.23), target=[0, 1])` + +Add an instruction to the circuit: + +`circuit.add(inst)` + +Sample random pairs of indexes (i, j) to generate random circuit: +``` +(control, target) = random.sample(range(num_qubits), 2) +instruction = Instruction(CNot(), target=[target], control=[control]) +circuit.add(instruction) +``` + +**FreeParameters (parametric gates)** + +Imports + +`from braket.circuits import FreeParameter` + +Create a FreeParameter (symbolic parameter): + +`alpha = FreeParameter(“alpha”)` + +Use FreeParameters: + +`circuit.rx(0, alpha+1)` + +Bind a FreeParameter to a specific value: + +`circuit.make_bound_circuit({“alpha”: 0.1})` + +Get the list of unbound FreeParameters: + +`circuit.parameters` + +Run circuit on a device with parametric compilation enabled. + +`device.run(circuit, inputs={“alpha”: 0.1})` + +**Tasks** + +Imports: + +`from braket.aws import AwsSession, AwsQuantumTask` + +Create a quantum task by executing a circuit on a device: + +`task = device.run(circuit)` + +Disable qubit rewiring (forces trivial mapping between logical and physical qubits on QPU): + +`device.run(circuit, disable_qubit_rewiring=True)` + +Instantiate an AwsSession: +`session = AwsSession(...)` + +Re-create a previously created quantum task from ARN: +`task = AwsQuantumTask(arn[, aws_session])` + +Task Queue position: +`task.queue_position()` + +Quantum Task batching: + +``` +n_batch = 5 # define circuit batch size +circuits = [circuit for _ in range(n_batch)] # Create a list of circuits in the batch +batch = device.run_batch(circuits, s3_folder, shots=100) # Submit batch of circuits +print(batch.results()[0].measurement_counts) # The result of the first quantum task in the batch +``` + +Attach tag to a Quantum Task: + +``` +task = device.run( + circuit, + shots=100, + tags={"MyTag": "MyValue"} +) +``` + +**Quantum Task attributes:** + +Cancel task: `task.cancel()` +Task metadata: `task.metadata()` +Task state (CREATED, COMPLETED, CANCELED, FAILED): `task.state()` +Task position in the queue: `task.queue_position()` +Get Task result dicitonary: `task.result()` + +**Results** + +Retrieve task results: + +`result = task.result()` + +Get measurement counts: + +`result.measurement_counts` + +Get measurement probabilities (for Probability Result Type): + +`result.measurement_probabilities` + +Get measured qubits: + +`result.measured_qubits` + +Get compiled circuit: + +`result.get_compiled_circuit()` + +**Device** + +Imports + +``` +from braket.aws import AwsDevice +from braket.devices import Devices +``` + +Instantiate a device: + +`AwsDevice("")` + +Device alias (use in place of string ARN): + +`Devices.Rigetti.AspenM3` + +QuantumTask Queue depth: + +`device.queue_depth()` + +Gate pulse implementation: + +`device.gate_calibrations` + +SV1 Simulator ARN: + +“arn:aws:braket:::device/quantum-simulator/amazon/sv1” + +TN1 Simulator ARN (Tensor Network simulator): + +“arn:aws:braket:::device/quantum-simulator/amazon/tn1” + +DM1 Simulator ARN (density matrix simulator): + +“arn:aws:braket:::device/quantum-simulator/amazon/dm1” + +Rydberg atom devices Aquila (AHS device from QuEra): + +“arn:aws:braket:us-east-1::device/qpu/quera/Aquila” + +Rigetti Aspen M3 device "arn:aws:braket:us-west-1::device/qpu/rigetti/Aspen-M-3" + +IQM Garnet device (20 qubits): + +"arn:aws:braket:eu-north-1::device/qpu/iqm/Garnet" + +**Device Properties** + +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` + +Get 2Q gate fidelitis for a qubit pair (i, j): + +`device.properties.dict()["provider"]["specs"]["2Q"][f"{i}-{j}"]` + + +**Pricing** + +Imports: +`from braket.tracking import Tracker` + +Start the cost tracker: +`tracker=Tracker().start()` + +Print costs: +``` +tracker.qpu_tasks_cost() +tracker.simulator_tasks_cost() +``` + +Cost summary: + +`tracker.quantum_tasks_statistics()` + + + +**Hybrid Jobs** + +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) +``` + +AwsQuantumJob Queue position: + +`job.queue_position()` + +Job decorator (local mode): + +`@hybrid_job(device=None, local=True)` + +Records Braket Hybrid Job metrics (will be displayed on Hybrid Jobbs concole metrics log): + +`log_metric(metric_name=metric_name, value=value, iteration_number=iteration_number)` + + +**Simulator** + +Imports +from braket.devices import LocalSimulator + +Instantiate the local simulator +local_sim = LocalSimulator() + +**Noise Simulation** + +Imports: + +`from braket.circuits import Noise` + +Apply 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 to an individual X gate + +`circuit.apply_gate_noise(noise, Gate.X)` + + + +**Low-Level Device Control** + +Imports +``` +from braket.pulse import PulseSequence, Frame +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) +GaussianWaveform(length, width, amplitude, zero_at_edges) +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()` + + +**Analog Hamiltonian Simulation** + +Imports: +`from braket.ahs import AtomArrangement, DrivingField, AnalogHamiltonianSimulation` + +Atom arrangement: + +`register = AtomArrangement()` + +Add an atom with (x, y) coordinates (in meters): + +`register.add((5.7e-6, 5.7e-6))` + +Add atoms in square lattice with lattice spacing a + +``` +a = 5e-6 +for i in range(nx): + for j in range(ny): + register.add((i*a, j*a)) +``` + +Get atom coordinates along x-axis: + +`register.coordinate_list(0)` + +Get atom coordinates along y-axis: + +`register.coordinate_list(1)` + +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)` + +**Error Mitigation** + +Debias: + +`device.run(circuit, shots=2500, device_parameters={"errorMitigation": Debias()})` + +Sharpening (if debiasing used): + +`result.additional_metadata.ionqMetadata.sharpenedProbabilities` \ No newline at end of file diff --git a/src/braket/ahs/analog_hamiltonian_simulation.py b/src/braket/ahs/analog_hamiltonian_simulation.py index af02471e2..f11675d41 100644 --- a/src/braket/ahs/analog_hamiltonian_simulation.py +++ b/src/braket/ahs/analog_hamiltonian_simulation.py @@ -23,6 +23,7 @@ from braket.ahs.hamiltonian import Hamiltonian from braket.ahs.local_detuning import LocalDetuning from braket.device_schema import DeviceActionType +from braket.timings.time_series import TimeSeries class AnalogHamiltonianSimulation: @@ -49,6 +50,52 @@ def hamiltonian(self) -> Hamiltonian: """Hamiltonian: The hamiltonian to simulate.""" return self._hamiltonian + @staticmethod + def from_ir(source: ir.Program) -> AnalogHamiltonianSimulation: + """Converts the canonical intermediate representation into + the Analog Hamiltonian Simulation. + + Args: + source (ir.Program): The IR representation of the circuit. + + Returns: + AnalogHamiltonianSimulation: The Analog Hamiltonian Simulation. + """ + atom_arrangement = AtomArrangement() + for site, fill in zip(source.setup.ahs_register.sites, source.setup.ahs_register.filling): + atom_arrangement.add( + coordinate=site, site_type=SiteType.FILLED if fill == 1 else SiteType.VACANT + ) + hamiltonian = Hamiltonian() + for term in source.hamiltonian.drivingFields: + amplitude = TimeSeries.from_lists( + times=term.amplitude.time_series.times, + values=term.amplitude.time_series.values, + ) + phase = TimeSeries.from_lists( + times=term.phase.time_series.times, + values=term.phase.time_series.values, + ) + detuning = TimeSeries.from_lists( + times=term.detuning.time_series.times, + values=term.detuning.time_series.values, + ) + hamiltonian += DrivingField( + amplitude=amplitude, + phase=phase, + detuning=detuning, + ) + for term in source.hamiltonian.localDetuning: + hamiltonian += LocalDetuning.from_lists( + times=term.magnitude.time_series.times, + values=term.magnitude.time_series.values, + pattern=term.magnitude.pattern, + ) + return AnalogHamiltonianSimulation( + register=atom_arrangement, + hamiltonian=hamiltonian, + ) + def to_ir(self) -> ir.Program: """Converts the Analog Hamiltonian Simulation into the canonical intermediate representation. diff --git a/src/braket/ahs/field.py b/src/braket/ahs/field.py index 1522b9d65..28319cc99 100644 --- a/src/braket/ahs/field.py +++ b/src/braket/ahs/field.py @@ -66,3 +66,30 @@ def discretize( discretized_pattern = self.pattern.discretize(pattern_resolution) discretized_field = Field(time_series=discretized_time_series, pattern=discretized_pattern) return discretized_field + + @staticmethod + def from_lists(times: list[Decimal], values: list[Decimal], pattern: list[Decimal]) -> Field: + """Builds Field from lists of time points, values and pattern. + + Args: + times (list[Decimal]): The time points of the field + values (list[Decimal]): The values of the field + pattern (list[Decimal]): The pattern of the field + + Raises: + ValueError: If the length of times and values differs. + + Returns: + Field: Field. + """ + if not (len(times) == len(values)): + raise ValueError( + f"The lengths of the lists for times({len(times)}) and values({len(values)})\ + are not equal" + ) + + time_series = TimeSeries.from_lists(times=times, values=values) + + field = Field(time_series=time_series, pattern=Pattern(pattern)) + + return field diff --git a/test/unit_tests/braket/ahs/test_analog_hamiltonian_simulation.py b/test/unit_tests/braket/ahs/test_analog_hamiltonian_simulation.py index 83178c120..3af8554a1 100644 --- a/test/unit_tests/braket/ahs/test_analog_hamiltonian_simulation.py +++ b/test/unit_tests/braket/ahs/test_analog_hamiltonian_simulation.py @@ -70,6 +70,140 @@ def local_detuning(): ) +@pytest.fixture +def ir(): + return Program.parse_raw_schema( + """ +{ + "braketSchemaHeader": { + "name": "braket.ir.ahs.program", + "version": "1" + }, + "setup": { + "ahs_register": { + "sites": [ + [ + "0.0", + "0.0" + ], + [ + "0.0", + "0.000003" + ], + [ + "0.0", + "0.000006" + ], + [ + "0.000003", + "0.0" + ], + [ + "0.000003", + "0.000003" + ], + [ + "0.000003", + "0.000003" + ], + [ + "0.000003", + "0.000006" + ] + ], + "filling": [ + 1, + 1, + 1, + 1, + 1, + 0, + 0 + ] + } + }, + "hamiltonian": { + "drivingFields": [ + { + "amplitude": { + "time_series": { + "values": [ + "0.0", + "25132700.0", + "25132700.0", + "0.0" + ], + "times": [ + "0.0", + "3E-7", + "0.0000027", + "0.000003" + ] + }, + "pattern": "uniform" + }, + "phase": { + "time_series": { + "values": [ + "0", + "0" + ], + "times": [ + "0.0", + "0.000003" + ] + }, + "pattern": "uniform" + }, + "detuning": { + "time_series": { + "values": [ + "-125664000.0", + "-125664000.0", + "125664000.0", + "125664000.0" + ], + "times": [ + "0.0", + "3E-7", + "0.0000027", + "0.000003" + ] + }, + "pattern": "uniform" + } + } + ], + "localDetuning": [ + { + "magnitude": { + "time_series": { + "values": [ + "-125664000.0", + "125664000.0" + ], + "times": [ + "0.0", + "0.000003" + ] + }, + "pattern": [ + "0.5", + "1.0", + "0.5", + "0.5", + "0.5", + "0.5" + ] + } + } + ] + } +} +""" + ) + + def test_create(): mock0 = Mock() mock1 = Mock() @@ -95,6 +229,38 @@ def test_to_ir_empty(): assert problem == Program.parse_raw_schema(problem.json()) +def test_from_ir(ir): + problem = AnalogHamiltonianSimulation.from_ir(ir).to_ir() + assert problem == ir + assert problem == Program.parse_raw_schema(problem.json()) + + +def test_from_ir_empty(): + empty_ir = Program.parse_raw_schema( + """ +{ + "braketSchemaHeader": { + "name": "braket.ir.ahs.program", + "version": "1" + }, + "setup": { + "ahs_register": { + "sites": [], + "filling": [] + } + }, + "hamiltonian": { + "drivingFields": [], + "localDetuning": [] + } +} +""" + ) + problem = AnalogHamiltonianSimulation.from_ir(empty_ir).to_ir() + assert problem == empty_ir + assert problem == Program.parse_raw_schema(problem.json()) + + @pytest.mark.xfail(raises=TypeError) def test_to_ir_invalid_hamiltonian(register): hamiltonian = Mock() diff --git a/test/unit_tests/braket/ahs/test_field.py b/test/unit_tests/braket/ahs/test_field.py index 2ff6714ce..21006fa6d 100644 --- a/test/unit_tests/braket/ahs/test_field.py +++ b/test/unit_tests/braket/ahs/test_field.py @@ -98,3 +98,23 @@ def test_uniform_field( ) or expected.pattern.series == actual.pattern.series assert expected.time_series.times() == actual.time_series.times() assert expected.time_series.values() == actual.time_series.values() + + +def test_from_lists(): + times = [0, 0.1, 0.2, 0.3] + values = [0.5, 0.8, 0.9, 1.0] + pattern = [0.3, 0.7, 0.6, -0.5, 0, 1.6] + + sh_field = Field.from_lists(times, values, pattern) + assert sh_field.time_series.times() == times + assert sh_field.time_series.values() == values + assert sh_field.pattern.series == pattern + + +@pytest.mark.xfail(raises=ValueError) +def test_from_lists_not_eq_length(): + times = [0, 0.1, 0.2] + values = [0.5, 0.8, 0.9, 1.0] + pattern = [0.3, 0.7, 0.6, -0.5, 0, 1.6] + + Field.from_lists(times, values, pattern)