Blqs_cirq is a library that uses blqs to make it easier to write Cirq programs.
Here is the creation of a simple circuit in Cirq
import cirq
circuit = cirq.Circuit()
q0, q1 = cirq.LineQubit.range(2)
circuit.append(cirq.H(q0))
circuit.append(cirq.CX(q0, q1))
circuit.append(measure(q0, key='a'))
Blqs_cirq makes it so that you can write this more like a normal imperative program
import blqs_cirq as bc
from blqs_cirq import CX, H, measure
# Write the function imperatively.
@bc.build
def my_circuit():
H(0)
CX(0, 1)
measure(q0, key='a')
# To create the circuit we simply call the function.
circuit = my_circuit()
Blqs provides supports for all the gates in Cirq, along with all the various ways to use these gates to create operations.
But wait, there is more. Blqs_cirq supports
-
Simplification of qubit specification. Instead of creating
LineQubit
orNamedQubit
, etc., one can simply use integers (converted toLineQubit
s), 2-tuples or 2-lists (converted toGridQubit
s) or strings (converted toNamedQubits
). Custom conversions are also possible. -
Simplification of control flow primitives. For example Cirq currently supports a subcircuit which can be repeated. For example here we repeat a small circuit within our circuit:
@bc.build
def my_circuit():
H(1)
with Repeat(repetitions=10):
H(0)
CX(0, 1)
As more control operations are added to Cirq these will be added to blqs_cirq.
- Simple building of Moments. For example, the code below builds two moments:
@bc.build
def my_circuit():
with Moment():
bc.H(0)
with Moment():
bc.H(1)
- Support for Cirq's insertion strategies:
@bc.build
def my_circuit():
with bc.InsertStrategy(cirq.InsertStrategy.NEW):
H(0)
H(1)
To install blqs_cirq one can simply pip install the appropriate package
pip install blqs_cirq
Note that installing blqs_cirq will also install blqs and cirq.
A good place to start is with the introduction, followed by a look at the important features. For a quick intro via a jupyter notebook, see hello blqs_cirq.