Skip to content

Commit

Permalink
Upgrade Braket SDK version; ensure tests use valid OpenQASM (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
rmshaffer authored Sep 24, 2024
1 parent 6943fe9 commit a5044b7
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 124 deletions.
6 changes: 3 additions & 3 deletions doc/decorators.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,18 @@ The body of a function decorated with `@aq.gate_calibration` must only contain p
The first argument to the `@aq.gate_calibration` decorator must be the gate function that the calibration will be registered to. Concrete values for the qubits and parameters are supplied as keyword arguments to the decorator.
Every qubit and angle parameter of the gate being implemented must appear either as an argument to the `@aq.gate_calibration` decorator, or as a parameter of the decorated function.

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.
For example, the gate `rx` takes two arguments, target and theta. Each arguments must be either set in the decorator or declared as an input parameter to the decorated function.

```
# This calibration only applies to physical qubit zero, so we
# mark that in the decorator call
@aq.gate_calibration(implements=rx, target="$0")
def cal_1(angle: float):
def cal_1(theta: float):
# The calibration is applicable for any rotation angle,
# so we accept it as an input argument
pulse.barrier("$0")
pulse.shift_frequency(q0_rf_frame, -321047.14178613486)
pulse.play(q0_rf_frame, waveform(angle))
pulse.play(q0_rf_frame, waveform(theta))
pulse.shift_frequency(q0_rf_frame, 321047.14178613486)
pulse.barrier("$0")
```
Expand Down
20 changes: 10 additions & 10 deletions examples/6_Customize_gate_calibrations.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
"2. Decide the qubits and angles you want to define the calibration.\n",
"3. Compose a pulse program that defines the calibration.\n",
"\n",
"As an example, let's define the gate calibration of `rx` on qubit `$1` and at angle `pi/2`. We first inspect the definition of the `rx` gate. You can find the definition of gate instructions in the [gate module](https://github.com/amazon-braket/autoqasm/blob/main/src/autoqasm/instructions/gates.py) of AutoQASM. You can also use the Python built-in `help` function to retrieve the definition. A gate calibration for the `rx` gate must fully specify the inputs of the gate, `target` and `angle`."
"As an example, let's define the gate calibration of `rx` on qubit `$1` and at angle `pi/2`. We first inspect the definition of the `rx` gate. You can find the definition of gate instructions in the [gate module](https://github.com/amazon-braket/autoqasm/blob/main/src/autoqasm/instructions/gates.py) of AutoQASM. You can also use the Python built-in `help` function to retrieve the definition. A gate calibration for the `rx` gate must fully specify the inputs of the gate, `target` and `theta`."
]
},
{
Expand All @@ -170,12 +170,12 @@
"text": [
"Help on function rx in module autoqasm.instructions.gates:\n",
"\n",
"rx(target: Union[int, str, braket.registers.qubit.Qubit, oqpy.classical_types._ClassicalVar, oqpy.base.OQPyExpression, oqpy.quantum_types.Qubit], angle: Union[float, braket.parametric.free_parameter_expression.FreeParameterExpression, oqpy.classical_types._ClassicalVar], **kwargs) -> None\n",
"rx(target: Union[int, str, braket.registers.qubit.Qubit, oqpy.classical_types._ClassicalVar, oqpy.base.OQPyExpression, oqpy.quantum_types.Qubit], theta: Union[float, braket.parametric.free_parameter_expression.FreeParameterExpression, oqpy.classical_types._ClassicalVar], **kwargs) -> None\n",
" X-axis rotation gate.\n",
" \n",
" Args:\n",
" target (QubitIdentifierType): Target qubit.\n",
" angle (GateParameterType): Rotation angle in radians.\n",
" theta (GateParameterType): Rotation angle in radians.\n",
"\n"
]
}
Expand All @@ -189,7 +189,7 @@
"id": "a1189626",
"metadata": {},
"source": [
"To specify fixed values for the parameters `target` and `angle`, we set the values through keyword arguments of the decorator. The pulse implementation for the gate calibration is in the body of the `my_rx_cal` function decorated by `@aq.gate_calibration`. In the example in the next cell, we want to experiment with offsetting the frequency of the pulse by 100 Hz away from the hardware provider's implementation. The gate calibration `my_rx_cal` recreates the hardware provider's implementation but with an offset in the frequency."
"To specify fixed values for the parameters `target` and `theta`, we set the values through keyword arguments of the decorator. The pulse implementation for the gate calibration is in the body of the `my_rx_cal` function decorated by `@aq.gate_calibration`. In the example in the next cell, we want to experiment with offsetting the frequency of the pulse by 100 Hz away from the hardware provider's implementation. The gate calibration `my_rx_cal` recreates the hardware provider's implementation but with an offset in the frequency."
]
},
{
Expand All @@ -205,7 +205,7 @@
"q0_rf_frame = device.frames[\"q0_rf_frame\"]\n",
"\n",
"\n",
"@aq.gate_calibration(implements=rx, target=\"$0\", angle=np.pi / 2)\n",
"@aq.gate_calibration(implements=rx, target=\"$0\", theta=np.pi / 2)\n",
"def my_rx_cal():\n",
" pulse.barrier(\"$0\")\n",
" pulse.shift_frequency(q0_rf_frame, -321047.14178613486 - 100)\n",
Expand Down Expand Up @@ -299,7 +299,7 @@
"id": "f038b8c8",
"metadata": {},
"source": [
"You can also define a gate calibration with variable parameters. Variable parameters are used in the body of the decorated function. The variable parameters must be arguments of the decorated Python function, instead of being arguments to the decorator `@aq.gate_calibration`. The variable parameters must have a type hint of either `aq.Qubit` for qubits or `float` for angles. Let's define another gate calibration with a variable parameter. This time, we define a calibration for the `rz` gate on qubit `$1` and a variable angle `angle`."
"You can also define a gate calibration with variable parameters. Variable parameters are used in the body of the decorated function. The variable parameters must be arguments of the decorated Python function, instead of being arguments to the decorator `@aq.gate_calibration`. The variable parameters must have a type hint of either `aq.Qubit` for qubits or `float` for angles. Let's define another gate calibration with a variable parameter. This time, we define a calibration for the `rz` gate on qubit `$1` and a variable angle `theta`."
]
},
{
Expand All @@ -313,9 +313,9 @@
"\n",
"\n",
"@aq.gate_calibration(implements=rz, target=\"$1\")\n",
"def my_rz_cal(angle: float):\n",
"def my_rz_cal(theta: float):\n",
" pulse.barrier(\"$1\")\n",
" pulse.shift_frequency(q1_rf_frame, -1.0 * angle)\n",
" pulse.shift_frequency(q1_rf_frame, -1.0 * theta)\n",
" pulse.barrier(\"$1\")"
]
},
Expand Down Expand Up @@ -348,9 +348,9 @@
" shift_frequency(q0_rf_frame, 321147.14178613486);\n",
" barrier $0;\n",
"}\n",
"defcal rz(angle[32] angle) $1 {\n",
"defcal rz(angle[32] theta) $1 {\n",
" barrier $1;\n",
" shift_frequency(q1_rf_frame, -1.0 * angle);\n",
" shift_frequency(q1_rf_frame, -1.0 * theta);\n",
" barrier $1;\n",
"}\n",
"rx(1.5707963267948966) $0;\n",
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
packages=find_namespace_packages(where="src", exclude=("test",)),
package_dir={"": "src"},
install_requires=[
"amazon-braket-sdk==1.81.0",
"amazon-braket-sdk>=1.87.1",
"amazon-braket-default-simulator>=1.23.2",
"oqpy~=0.3.5",
"diastatic-malt",
Expand Down
Loading

0 comments on commit a5044b7

Please sign in to comment.