Simulator module¶
This module simulates a circuit. It also defines the necessary gates.
-
class
Simulator.
Simulator
(gates, register, custom, measurements)¶ Bases:
object
-
__NCP
(gate_info)¶ Adds a phase gate controlled by an arbitrary number of bits
- Parameters
gate_info – (tuple(int, int, int…, float)) Control qubits as ints, phase as a float.
- Returns
(SparseMatrix) Matrix representation of gate.
-
__NCZ
(gate_info)¶ Adds a z gate controlled by an arbitrary number of bits
- Parameters
gate_info – (tuple(int, int, int…,)) Control qubits as ints, arbitrary number
- Returns
(SparseMatrix) Matrix representatin of the gate
-
__Rt
(theta)¶ Creates an r gate with the given phase
- Parameters
theta – (float) The angle in radians which the qubit should be rotated by.
- Returns
(SparseMatrix) Matrix representation of the r gate.
-
__Swap
(gate_info)¶ Creates the matrix representing the swap operation between two qubits.
- Parameters
gate_info – (tuple(int, int)) The two gates to be swapped.
- Returns
(SparseMatrix) Matrix representation of the swap gate.
-
__addLargeGate
(gate_info)¶ Helper function for makeMatrices(). Calls the creators for the larger gates based info provided.
- Parameters
gate_info – (tuple) information of multi-qubit gate
- Returns
(SparseMatrix) Matrix representation of the operation for the gates given.
-
__bitactive
(n, bit)¶ Checks whether a given integer has a particular bit active
- Parameters
n – (int) Integer to check
bit – (int) The position of the bit to check
- Returns
(Boolean) True of bit is active, false if not
-
__cNot
(gate_info)¶ Creates an arbitrary sized controlled not gate between two arbitrary qbits.
- Parameters
gate_info – (tuple(int, int)) Position in the circuit of the control qubit and the controlled qubit
- Returns
(SparseMatrix) The cnot gate entangling the two qubits given.
-
__cP
(gate_info)¶ Creates a controlled phase gate for the given qubits
- Parameters
gate_info – (tuple(int, int, float)) The information supplied to the gate. Control qubits as ints, float as the phase.
- Returns
(SparseMatrix) Representation of the cp gate
-
__cZ
(gate_info)¶ Creates a controlled z gate given 2 qubits
- Parameters
gate_info – (tuple(int, int)) The two gates to control the z
- Returns
(SparseMatrix) Representation of the cz gate
-
__ccNot
(gate_info)¶ Creates a Sparsematrix representing the controlled-controlled-not (ccnot or Tiffoli) gate for the given qubits. Can be applied to any exisiting qubits.
- Parameters
gate_info – (tuple(int, int, int)) first, second qubit controlling the gate and the qubit controlled by the other two
- Returns
(SparseMatrix) Matrix representation of the gate
-
__toggle
(n, bit)¶ Toggles a specific bit in an integer
- Parameters
n – (int) Integer to toggle
bit – (int) The position of the bit to toggle
- Returns
(int) The new integer created by toggling the bit
-
makeMatrices
()¶ Creates the matrices that will be applied to the wavevector
- Returns
(array) list of np matrices that will be applied to the statevector
-
simulate
(return_full=False)¶ Applies the circuit to the initialized statevector
- Parameters
return_full – (Boolean) True if operations and measurements need to be returned.
- Returns
The register, if return_full: the register, operations and any measurements.
-
simulate2
()¶ Applies the circuit to the initialized statevector without storing the operations
- Returns
The register and any measurements made
-