Skip to content

[CQT-369] Add CircuitBuilder user documentation#699

Open
rares1609 wants to merge 2 commits into
developfrom
CQT-369-Write-circuit-builder-section-User-documentation
Open

[CQT-369] Add CircuitBuilder user documentation#699
rares1609 wants to merge 2 commits into
developfrom
CQT-369-Write-circuit-builder-section-User-documentation

Conversation

@rares1609

Copy link
Copy Markdown
Contributor

No description provided.

@rares1609
rares1609 requested review from Copilot and elenbaasc and removed request for Copilot July 13, 2026 09:39
@elenbaasc elenbaasc changed the title (CQT-369): add CircuitBuilder user documentation [CQT-369] Add CircuitBuilder user documentation Jul 16, 2026

@elenbaasc elenbaasc left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the clear description!

Make sure to write each sentence on a new line and break sentences that are too long.

Comment on lines +3 to +4
The `CircuitBuilder` is OpenSquirrel's programmatic API for constructing a circuit. It
offers an alternative to writing out a

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Each sentence starts on a new line.

Suggested change
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

Comment on lines +10 to +11
naturally and easily expressed with code than as a static string, for instance when a
circuit has patterns that a `for` loop captures nicely.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +21 to +29
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`.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +33 to +35
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:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
circuit = builder.to_circuit()

Comment on lines +80 to +83
builder = CircuitBuilder(qubit_register_size=2)
builder.H(0)
builder.CNOT(0, 1)
circuit = builder.to_circuit()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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()

Comment on lines +89 to +94
version 3.0

qubit[2] q

H q[0]
CNOT q[0], q[1]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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]

Comment on lines +189 to 193
## Adding instructions




Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## Adding instructions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants