Library for simulating quantum computations
Create a cirquit:
from cirquits import *
n = 2 # number of qubits in register
cirq = Cirquit(2)
Add some gates to it:
import gates
cirq.add_gate(gates.Not) # apply Not operation to the first qubit
cirq.add_gate(gates.H, 1) # apply Hadamard operation to the second qubit
Create register:
from registers import *
reg = Register(n)
Apply your cirquit to the register:
reg.apply_cirquit(cirq)
Read the results:
reg.print()
Probabilities of states, 2-qubit register:
|10> : 0.5
|11> : 0.5
Add controlled gate:
cirq.add_controlled_gate(gates.Y) # apply Y operation to 1-st qubit
# controlled by 0-th qubit
cirq.add_controlled_gate(gates.Z, qubit_number=1, control_qubit=0)
# you can personalize this operation
and controlled-controlled gate:
cirq.add_controlled_gate(gates.Z, qubit_number=2, control_qubits=[0, 1])
# by default, parameters are given these values
reg.measure()
reg.print()
Previously we had two states, |10> and |11>, with 50% chance to measure each. Measurement collapses it to only one state. Example output:
Probabilities of states, 2-qubit register:
|11> : 1
Register(2).add_gate(gates.X).add_gate(gates.H).measure().print()
reg = Register(3).fix_state(5)
# or equivalently
reg = Register(3).fix_state(0b101)
reg.print()
Probabilities of states, 2-qubit register:
|101> : 1
c1 = Cirquit(2).add_gate(gates.Swap)
c2 = Cirquit(2).add_gate(gates.sqrtSwap)
c2.add_cirquit(c1)
cirq.reversed() # this operation returns reversed cirq
# but doesn't cange cirq itself
Sometimes we need to compose cirquits with different sizes. We can increase number of qubits in the cirquit:
Cirquit(2).extend(3) # this will make cirquit to operate on
# 5-qubits registers
Cirquit(2).extend(1, "top") # you could add new qubits
# on the top (more significant bits)
# or bottom (less significant)
Register(3).shuffle([2, 0, 1]) # converts a register |abc> into |cab>