Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
edyounis committed Sep 12, 2024
1 parent cc6af7c commit 1bafb03
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions docs/guides/customgate.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,17 +128,17 @@ class MyGateTensor(Gate):

## Utilizing Helper Classes

BQSKit provides some helper classes to simplify the process of defining gates. In the first example of this guide, we used the [`ConstantGate`](https://bqskit.readthedocs.io/en/latest/source/autogen/bqskit.ir.ConstantGate.html#bqskit.ir.ConstantGate) and [`QubitGate`](https://bqskit.readthedocs.io/en/latest/source/autogen/bqskit.ir.QubitGate.html#bqskit.ir.QubitGate) helper classes. To use these helper subclasses, we will subclass them instead of [`Gate`](https://bqskit.readthedocs.io/en/latest/source/autogen/bqskit.ir.Gate.html#bqskit.ir.Gate). The following are the available helper classes:
BQSKit provides some helper classes to simplify the process of defining gates. In the first example of this guide, we used the [`ConstantGate`](https://bqskit.readthedocs.io/en/latest/source/autogen/bqskit.ir.gates.ConstantGate.html#bqskit.ir.gates.ConstantGate) and [`QubitGate`](https://bqskit.readthedocs.io/en/latest/source/autogen/bqskit.ir.gates.QubitGate.html#bqskit.ir.gates.QubitGate) helper classes. To use these helper subclasses, we will subclass them instead of [`Gate`](https://bqskit.readthedocs.io/en/latest/source/autogen/bqskit.ir.Gate.html#bqskit.ir.Gate). The following are the available helper classes:

- [`ConstantGate`](https://bqskit.readthedocs.io/en/latest/source/autogen/bqskit.ir.gates.ConstantGate.html#bqskit.ir.gates.ConstantGate): A gate that has a fixed unitary matrix with no parameters. This will automatically set `_num_params` to 0, and swap the `get_unitary` method for a `_utry` attribute. Additionally, these gates have the trivial differentiable implementations provided.
- [`QubitGate`](https://bqskit.readthedocs.io/en/latest/source/autogen/bqskit.ir.gates.QubitGate.html#bqskit.ir.gates.QubitGate): A gate that acts only on qubits. This defines `_radixes` to be all `2`s.
- [`QutritGate`](https://bqskit.readthedocs.io/en/latest/source/autogen/bqskit.ir.gates.QutritGate.html#bqskit.ir.gates.QutritGate): A gate that acts on qutrits. This defines `_radixes` to be all `3`s.
- [`QutritGate`](https://bqskit.readthedocs.io/en/latest/source/autogen/bqskit.ir.gates.QutritGate.html#bqskit.ir.gates.QutritGate): A gate that acts only on qutrits. This defines `_radixes` to be all `3`s.
- [`QuditGate`](https://bqskit.readthedocs.io/en/latest/source/autogen/bqskit.ir.gates.QuditGate.html#bqskit.ir.gates.QuditGate): A gate that acts on qudits of the same radix. This swaps the `_radixes` requirement for a required `_radix` attribute. This is useful for gates that act on qudits of the same radix, but not necessarily only qubits or qutrits.
- [`ComposedGate`](https://bqskit.readthedocs.io/en/latest/source/autogen/bqskit.ir.gates.ComposedGate.html#bqskit.ir.gates.ComposedGate): A gate that is composed of other gates. This provides methods to dynamically determine if the gate is differentiable or optimizable via other means.

## Differentiable Gates

If you are implementing a parameterized gate, you may want to make it differentiable. By making a gate differentiable, you allow it to be used by out instantiation engine. In turn, this allows synthesis and other algorithms to work more easily with these gates. To do this, you will need to additionally subclass [`DifferentiableUnitary`](https://bqskit.readthedocs.io/en/latest/source/autogen/bqskit.qis.DifferentiableUnitary.html) and implement the [`get_grad`](https://bqskit.readthedocs.io/en/latest/source/autogen/bqskit.qis.DifferentiableUnitary.get_grad.html#bqskit.qis.DifferentiableUnitary.get_grad) method. `ConstantGate`s are trivially differentiable, as they have no parameters.
If you are implementing a parameterized gate, you may want to make it differentiable. By making a gate differentiable, you allow it to be used by BQSKit's instantiation engine. In turn, this allows synthesis and other algorithms to work more easily with these gates. To do this, you will need to additionally subclass [`DifferentiableUnitary`](https://bqskit.readthedocs.io/en/latest/source/autogen/bqskit.qis.DifferentiableUnitary.html) and implement the [`get_grad`](https://bqskit.readthedocs.io/en/latest/source/autogen/bqskit.qis.DifferentiableUnitary.get_grad.html#bqskit.qis.DifferentiableUnitary.get_grad) method. `ConstantGate`s are trivially differentiable, as they have no parameters.

Most of the time, the [`get_unitary_and_grad`](https://bqskit.readthedocs.io/en/latest/source/autogen/bqskit.qis.DifferentiableUnitary.get_unitary_and_grad.html#bqskit.qis.DifferentiableUnitary.get_unitary_and_grad) method is called by other parts of BQSKit, since both the unitary and gradient are typically needed at the same time. For most gates, computing them at the same time can allow for greater efficiency, since the unitary and gradient can share some computations.

Expand Down

0 comments on commit 1bafb03

Please sign in to comment.