QuantumCircuit module¶
This modules creates a Circuit for with the specified gates by the User. The User can also create their own gate in this module.
-
class
QuantumCircuit.
QuantumCircuit
(name, size)¶ Bases:
Interface.Interface
-
addBigGate
(gate_info)¶ Adds the representation of a gate into self.gates. The gate will be iplemented later on when the circuit is simulated.
- Parameters
gate_info – (tuple) The gate info for the large gate in the form of string(type of gate), and ints for control bits, then the controlled bit for the last int if needed.
-
addCustom
(qbit1, qbit2, gate, name)¶ Adds a custom, user defined gate to the circuit. Does not check for unitary matrices, so have to be careful when using it. The dimension of the gate must match the dimension allowed by the affected qubits.
- Parameters
qbit1 – (int) Position of the qubit with the smaller index.
qbit2 – (int) Position of the qubit with the higher index.
gate – (SparseMatrix) SparseMAtrix representation of the gate to be added to the circuit.
name – (str) The name of the custom gate.
-
addGate
(gate, bits)¶ Adds an arbitrary gate to the set of gates stored in the circuit
- Parameters
gate – (char) The type of gate to be added. Current options are:’x’, ‘y’, ‘z’, ‘h’, ‘p’, ‘t’
bits – (list) The position of bits the gate is needed to be added
-
addmeasure
()¶ Adds a space where a measurement should be made. Mesurements are only made when simulating the circuit.
-
ccnot
(control1, control2, qubit)¶ Adds the representation of a ccnot gate into self.gates. The gate will be iplemented later on when the circuit is simulated.
- Parameters
qbit1 – (int) Control Qubit
qbit2 – (int) Controlled Qubit
-
cnot
(qbit1, qbit2)¶ Adds the representation of a cnot gate into self.gates. The gate will be iplemented later on when the circuit is simulated.
- Parameters
qbit1 – (int) Control Qubit
qbit2 – (int) Controlled Qubit
-
cp
(qbit1, qbit2, phi)¶ Adds the representation of a controlled phase gate to the circuit.
- Parameters
qbit1 – (int) Control bit 1
qbit2 – (int) Control bit 2
phi – (float) Rotation angle
-
lazysim
()¶ Uses Lazy Matrix Implementation for the Simulator.
-
ncp
(bits, phi)¶ Adds a phase gate controlled by n other qubits
- Parameters
bits – (list) The control qubits
phi – (float) Rotation parameter
-
ncz
(bits)¶ Adds the representation of an n controlled z gate to the circuit
- Parameters
bits – (list) The control bits for the gate
-
r
(bits, theta)¶ Adds a rotation matrix to the circuit
- Parameters
bits – (list) The qubits that the matrices will be applied to
theta – (float) Rotation angle
-
return_measurements
()¶ Returns final measurements after simulation.
-
run_circuit
(return_full=False)¶ Applies the circuit to the initialized state vector
- Returns
The final state of the state vector. If return_full: returns all operations along with the statevector and measurements
-
setStateVector
(newVector)¶ Allows the user to define the state vector for the quantum circuit
- Parameters
newVector – (list) The vector that the user wants as the new state vector
-
show_results
()¶ Prints out the initial definition of the statevector, along with the gates of the circuit. It then simulates the circuit and prints out the new statevector.
-
simulate2
()¶ Applies the circuit to the initialized state vector using less memory than simulate()
- Returns
The final state of the state vector
-
swap
(qbit1, qbit2)¶ Adds the representation of a swap gate to the circuit.
- Parameters
qbit1 – (int) qubit to be swapped
qbit2 – (int) qubit to be swapped
-