[CQT-369] Add CircuitBuilder user documentation#699
Conversation
elenbaasc
left a comment
There was a problem hiding this comment.
Thanks for the clear description!
Make sure to write each sentence on a new line and break sentences that are too long.
| The `CircuitBuilder` is OpenSquirrel's programmatic API for constructing a circuit. It | ||
| offers an alternative to writing out a |
There was a problem hiding this comment.
Each sentence starts on a new line.
| The `CircuitBuilder` is OpenSquirrel's programmatic API for constructing a circuit. It | |
| offers an alternative to writing out a | |
| The `CircuitBuilder` is OpenSquirrel's programmatic API for constructing a circuit. | |
| It offers an alternative to writing out a |
| naturally and easily expressed with code than as a static string, for instance when a | ||
| circuit has patterns that a `for` loop captures nicely. |
There was a problem hiding this comment.
It is much much broader than for loops. It should say that you basically have all programmatic tools at your disposal that are available in Python.
| A builder is created by declaring the sizes of its qubit and (optionally) bit registers: | ||
|
|
||
| ```python | ||
| builder = CircuitBuilder(qubit_register_size=3, bit_register_size=2) | ||
| ``` | ||
|
|
||
| This reserves a qubit register `q` of size 3 and a bit register `b` of size 2. Qubits | ||
| and bits are always referred to by their integer index into these registers, | ||
| starting at `0`. |
There was a problem hiding this comment.
This is indeed the simplest way, but we should already mention (a reference and link to the section below) that a user can also define registers themselves and added these to the builder.
| Once the builder is instantiated, instructions are added by calling the method that | ||
| carries the name of the instruction, passing the qubit and bit indices (and any | ||
| parameters for e.g. _parameterized gates_ ) as arguments: |
There was a problem hiding this comment.
Don't refer to gates as methods, that is confusing, just show how the instructions can be added, and add a reference link to the available instructions.
| raises an `AttributeError`, and passing the wrong number or type of arguments raises a | ||
| `TypeError`. | ||
|
|
||
| Instructions can also be appended directly with `add_instruction`, which accepts either |
There was a problem hiding this comment.
| Instructions can also be appended directly with `add_instruction`, which accepts either | |
| Instructions can also be appended with `add_instruction`, which accepts either |
| builder = CircuitBuilder(2) | ||
| builder.add_instruction(H(0)) | ||
| builder.add_instruction([H(1), CNOT(0, 1)]) | ||
| circuit = builder.to_circuit() |
There was a problem hiding this comment.
| circuit = builder.to_circuit() |
| builder = CircuitBuilder(qubit_register_size=2) | ||
| builder.H(0) | ||
| builder.CNOT(0, 1) | ||
| circuit = builder.to_circuit() |
There was a problem hiding this comment.
| builder = CircuitBuilder(qubit_register_size=2) | |
| builder.H(0) | |
| builder.CNOT(0, 1) | |
| circuit = builder.to_circuit() | |
| builder = CircuitBuilder(qubit_register_size=2, bit_register_size=2) | |
| builder.add_instruction([H(0) CNOT(0, 1)]) | |
| builder.measure(1, 0).measure(0, 1) | |
| circuit = builder.to_circuit() |
| version 3.0 | ||
|
|
||
| qubit[2] q | ||
|
|
||
| H q[0] | ||
| CNOT q[0], q[1] |
There was a problem hiding this comment.
| version 3.0 | |
| qubit[2] q | |
| H q[0] | |
| CNOT q[0], q[1] | |
| version 3.0 | |
| qubit[2] q | |
| bit[2] b | |
| H q[0] | |
| CNOT q[0], q[1] | |
| b[0] = measure q[1] | |
| b[1] = measure q[0] |
| ## Adding instructions | ||
|
|
||
|
|
||
|
|
||
|
|
There was a problem hiding this comment.
| ## Adding instructions |
No description provided.