From 8072f3bf8309f9f3cf56c8219f0a7396ae5613fb Mon Sep 17 00:00:00 2001 From: Ryan Shaffer <3620100+rmshaffer@users.noreply.github.com> Date: Fri, 20 Sep 2024 13:08:11 -0400 Subject: [PATCH] Highlight Python syntax in md files --- doc/decorators.md | 12 ++++++------ doc/hybrid_jobs.md | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/doc/decorators.md b/doc/decorators.md index 879b65e..7072f29 100644 --- a/doc/decorators.md +++ b/doc/decorators.md @@ -10,7 +10,7 @@ This decorator marks the entry point to a quantum program. You can include gates, pulse control, classical control and subroutine calls. The function wrapped by `@aq.main` is converted into a `Program` object. The `Program` object can be executed on [devices available through Amazon Braket](https://docs.aws.amazon.com/braket/latest/developerguide/braket-devices.html), including local simulators. The code snippet below creates a quantum program with `@aq.main` and runs it on the `Device` instantiated as `device`. -``` +```python size = 5 @aq.main(num_qubits=size) @@ -26,7 +26,7 @@ device.run(ghz_state) When you run your quantum program, the Amazon Braket SDK automatically serializes the program to OpenQASM before sending it to the local simulator or the Amazon Braket service. In AutoQASM, you can optionally view the OpenQASM script of your quantum program before submitting to a device by calling `build()` on the MainProgram object, and calling `display()` on the resulting `Program` object. -``` +```python ghz_state.build().display() ``` @@ -39,7 +39,7 @@ Like any subroutine, `@aq.subroutine` is often used to simplify repeated code an Because AutoQASM supports strongly-typed serialization formats such as OpenQASM, you must provide type hints for the inputs of your subroutine definitions. Our example below uses a subroutine to make Bell states on two pairs of qubits. -``` +```python @aq.subroutine def bell(q0: int, q1: int) -> None: h(q0) @@ -72,7 +72,7 @@ Gate definitions define higher-level gates in terms of other gates, and are ofte The body of a gate definition can only contain gates. Qubits used in the body of a gate definition must be passed as input arguments, with the type hint `aq.Qubit`. Like subroutines, a gate definition must be called from within the context of a main quantum program or subroutine in order to be included in the program. -``` +```python @aq.gate def ch(q0: aq.Qubit, q1: aq.Qubit): """Define a controlled-Hadamard gate.""" @@ -100,7 +100,7 @@ Every qubit and angle parameter of the gate being implemented must appear either For example, the gate `rx` takes two arguments, target and angle. Each arguments must be either set in the decorator or declared as an input parameter to the decorated function. -``` +```python # This calibration only applies to physical qubit zero, so we # mark that in the decorator call @aq.gate_calibration(implements=rx, target="$0") @@ -116,7 +116,7 @@ def cal_1(angle: float): To add the gate calibration to your program, use the `with_calibrations` method of the main program. -``` +```python @aq.main def my_program(): rx("$0", 0.123) diff --git a/doc/hybrid_jobs.md b/doc/hybrid_jobs.md index 1372473..1399785 100644 --- a/doc/hybrid_jobs.md +++ b/doc/hybrid_jobs.md @@ -5,7 +5,7 @@ Amazon Braket Hybrid Jobs provides a solution for executing hybrid quantum-class ## Using `AwsQuantumJob.create` This [documentation page](https://docs.aws.amazon.com/braket/latest/developerguide/braket-jobs-first.html#braket-jobs-first-create) shows you how to create a hybrid job with `AwsQuantumJob.create`. To use a hybrid job with AutoQASM, simply use AutoQASM in your algorithm script. Because AutoQASM is currently not installed in the default job container, be sure to include AutoQASM in the requirements.txt of your source module, or add AutoQASM as a dependency when you build your own container. Below is an example algorithm script to get you started. -``` +```python import os from braket.devices import LocalSimulator @@ -34,7 +34,7 @@ def start_here(): ``` Save this algorithm script as "algorithm_script.py" in a folder called "source_module" and run this code snippet below to create your first hybrid job with AutoQASM! -``` +```python from braket.aws import AwsQuantumJob job = AwsQuantumJob.create( @@ -52,7 +52,7 @@ Alternatively, you can use the `@aq.hybrid_job` decorator to create a hybrid job One of the core mechanisms of AutoQASM is source code analysis. When calling an AutoQASM decorated function, the source code of the function is analyzed and converted into a transformed Python function by AutoGraph. With the the `@aq.hybrid_job` decorator, the source code of a function defined inside the `@aq.hybrid_job` decorated function is separately saved as input data to the job. When [AutoQASM decorators](decorators.md) wrap these functions, the source code is retrieved from the input data. Because of this, if you use an AutoQASM decorator to convert a function that is defined outside of the `@aq.hybrid_job` decorated function, it may not work properly. If your application requires AutoQASM decorated functions to be defined outside of the `@aq.hybrid_job` decorated function, we recommend that you use the option described in the "Using `AwsQuantumJob.create`" section above to create the hybrid job. Below is a working example to create an AutoQASM job with the `@aq.hybrid_job` decorator. -``` +```python from braket.devices import LocalSimulator import autoqasm as aq