qcp package¶
Subpackages¶
- qcp.algorithms package
- qcp.cli package
- qcp.gui package
- Subpackages
- qcp.gui.components package
- Subpackages
- Submodules
- qcp.gui.components.abstract_component module
- qcp.gui.components.combo_box_component module
- qcp.gui.components.constants module
- qcp.gui.components.graph_component module
- qcp.gui.components.progress_bar_component module
- qcp.gui.components.simulator_component module
- qcp.gui.components.threaded_compute module
- Module contents
- qcp.gui.components package
- Submodules
- qcp.gui.constants module
- qcp.gui.main module
- qcp.gui.main_window module
- Module contents
- Subpackages
- qcp.matrices package
Submodules¶
qcp.constants module¶
- qcp.constants.IDENTITY = <qcp.matrices.sparse_matrix.SparseMatrix object>¶
The 2x2 Identity Matrix
- qcp.constants.MINUS_VECTOR = <qcp.matrices.sparse_matrix.SparseMatrix object>¶
A Column Vector representing the |-> state
- qcp.constants.ONE_VECTOR = <qcp.matrices.sparse_matrix.SparseMatrix object>¶
A Column Vector representing the |1> state
- qcp.constants.PAULI_X = <qcp.matrices.sparse_matrix.SparseMatrix object>¶
The 2x2 Pauli-X Gate
- qcp.constants.PAULI_Z = <qcp.matrices.sparse_matrix.SparseMatrix object>¶
The 2x2 Pauli-Z Gate
- qcp.constants.PLUS_VECTOR = <qcp.matrices.sparse_matrix.SparseMatrix object>¶
A Column Vector representing the |+> state
- qcp.constants.TWO_HADAMARD = <qcp.matrices.sparse_matrix.SparseMatrix object>¶
The 2x2 Hadamard Gate
- qcp.constants.ZERO_VECTOR = <qcp.matrices.sparse_matrix.SparseMatrix object>¶
A Column Vector representing the |0> state
- qcp.constants.factor = 0.7071067811865475¶
Normalisation factor used in the hadamard gate, and in the plus/minus state vectors
qcp.gates module¶
Contains the code required calculate the required gates used to construct Grover’s Algorithm
- class qcp.gates.Gate(value)[source]¶
Bases:
enum.Enum
Enums of the options of gate types to use in qcp.gates.multi_gates()
- H = 'h'¶
- I = 'i'¶
- P = 'p'¶
- X = 'x'¶
- Z = 'z'¶
- qcp.gates._generic_control(size: int, controls: List[int], target: int, cval: Union[complex, float, int]) qcp.matrices.matrix.Matrix [source]¶
Constructs a (2**size by 2**size) control gate with given controls, target and the control value. This is a generic implementation of the logic used for
qcp.gates.control_z()
andqcp.gates.control_phase()
- Parameters
size (int) – total number of qubits in circuit
controls (List[int]) – List of control qubits
target (int) – target qubit the gate will be applied to
cval (SCALARS) – The control value in the gate
- Returns
Matrix representing the gate
- Return type
- qcp.gates.control_phase(size: int, controls: List[int], target: int, phi: complex) qcp.matrices.matrix.Matrix [source]¶
Constructs a (2**size by 2**size) control-phase gate with given controls and target
- Parameters
size (int) – total number of qubits in circuit
controls (List[int]) – List of control qubits
target (int) – target qubit the phase gate will be applied to
phi (complex) – angle the target qubit will be phase shifted by
- Returns
Matrix representing the gate
- Return type
- qcp.gates.control_u(size: int, control: int, unitary: qcp.matrices.matrix.Matrix)[source]¶
Implement the control U gate
- qcp.gates.control_x(size: int, controls: List[int], target: int) qcp.matrices.matrix.Matrix [source]¶
Constructs a (2**size by 2**size) control-x gate with given controls and target
- Parameters
size (int) – total number of qubits in circuit
controls (List[int]) – List of control qubits, if empty, 0th bit is used as the control.
target (int) – target qubit the x gate will be applied to
- Returns
Matrix representing the gate
- Return type
- qcp.gates.control_z(size: int, controls: List[int], target: int) qcp.matrices.matrix.Matrix [source]¶
- Constructs a (2**size by 2**size) control-z gate with
given controls and target
- Parameters
size (int) – total number of qubits in circuit
controls (List[int]) – List of control qubits
target (int) – target qubit the z gate will be applied to
- Returns
Matrix representing the gate
- Return type
- qcp.gates.multi_gate(size: int, targets: List[int], gate: qcp.gates.Gate, phi=0j) qcp.matrices.matrix.Matrix [source]¶
Constructs a (2**size by 2**size) gate matrix that applies a specific gate to one or more specified qubits
- Parameters
int (size) – total number of qubits in circuit
List[int] (targets) – list of qubits the specified gate will be applied to, indexing from 0.
Gate (gate) – Enum of which gate we want to apply
complex (phi) – Phase angle for the phase gate
- Returns
Matrix representing the composite gate
- Return type
- qcp.gates.phase_shift(phi: complex) qcp.matrices.matrix.Matrix [source]¶
Creates a 2 x 2 phase shift matrix
- Parameters
phi (complex) – angle the qubit is phase shifted by
- Returns
Matrix representing the phase shift gate.
- Return type
- qcp.gates.swap(size: int, target0: int, target1: int) qcp.matrices.matrix.Matrix [source]¶
Construct swap gate which swaps two states
- Parameters
size (int) – total number of qubits in circuit
target0 (int) – The first target bit to swap
target1 (int) – The second target bit to swap
- Returns
Matrix representing the gate
- Return type
qcp.main module¶
Entrypoint for the Simulator
- qcp.main.compute(constructor, alg_name: str, *args)[source]¶
Run the Quantum Algorithm simulation and print the observed state to stdout with the probability of observing that state.
- Parameters
constructor – The constructor the algorithm objects, varies per choice of algorithm
alg_name (str) – The name of the algorithm being run
args – All args that need to be passed in to the Algorithm constructor
- qcp.main.main()[source]¶
The entrypoint for the CLI, parses the cli options and passes the read options to the function to run the computation.
- qcp.main.print_solution(alg: qcp.algorithms.abstract_algorithm.GeneralAlgorithm, m: int, p: float)[source]¶
Output the result of the algorithm to the terminal, handling the special outputs required for PhaseEstimation and Sudoku
- Parameters
alg (GeneralAlgorithm) – The algorithm object used to run the simulation.
m (int) – The measured state
p (float) – The probability of measuring that state.
qcp.register module¶
Code that converts a given column vector to the probability distributions of observing the qbits in each state
- qcp.register._magnitude(v: Union[complex, float, int]) float [source]¶
Measure the probability magnitude of the given scalar in the usual Quantum Mechanical way.
- Parameters
v (SCALARS) – The value to determine the magnitude of.
- Returns
The magnitude of the scalar
- Return type
float
- qcp.register.measure(mat: qcp.matrices.matrix.Matrix) List[float] [source]¶
Convert the qbit states into probability amplitudes
- Parameters
mat (Matrix) – the column vector of qbit states to measure.
- Returns
list of probabilities of observing the qbits in each state, normalised to total probability of 1.
- Return type
List[float]
qcp.tensor_product module¶
Code to calculate the general tensor product between two arbitrarily sized matrices.
- qcp.tensor_product._tensor_product_sparse(A: qcp.matrices.sparse_matrix.SparseMatrix, B: qcp.matrices.sparse_matrix.SparseMatrix) qcp.matrices.sparse_matrix.SparseMatrix [source]¶
Compute the tensor product between two SparseMatrices, and return the resultant Matrix
- Parameters
A (SparseMatrix) – An m*n matrix
B (SparseMatrix) – Second p*q matrix to tensor product with
- Returns
An (m*p)*(n*q) matrix of the tensor product.
- Return type
- qcp.tensor_product.tensor_product(A: qcp.matrices.matrix.Matrix, B: qcp.matrices.matrix.Matrix) qcp.matrices.matrix.Matrix [source]¶
Compute the tensor product between two matrices, and return the resultant Matrix
Module contents¶
Base module for the Quantum Computer Simulator.