qcrypto Library Documentation
- class qcrypto.agents.Agent(num_priv_qubits: 'Any' = None, qstates: 'dict[str, QState | Any]' = <factory>, keys: 'dict[str, npt.NDArray[np.int_] | None]' = <factory>, priv_qstates: 'QstateEnt | QstateUnEnt | None' = None, init_method: 'str' = 'random', priv_qbittype: 'str | None' = None)
Bases:
object
- apply_gate(gate: ndarray[Any, dtype[complex128]], qstate_type: str, qubit_idx: int | None = None) None
- get_key(qstate_type: str, order: Any | None = None) ndarray[Any, dtype[int64]]
- init_method: str = 'random'
- keys: dict[str, ndarray[Any, dtype[int64]] | None]
- measure(qstate_type: str, qubit_idx: int) int
Measure the qubit_idx’th qubit, calculating the probability of each outcome and returning said outcome.
- Parameters:
qstate_type (str) – Whether the given qstate is to be private or public
qubit_idx (int) – Index identifying the qubit to be measured
- Returns:
Outcome of the measurement, either 0 or 1
- measure_all(qstate_type: str, order: Any | None = None) ndarray[Any, dtype[int64]]
- num_priv_qubits: Any = None
- priv_qbittype: str | None = None
- priv_qstates: QstateEnt | QstateUnEnt | None = None
- qstates: dict[str, QState | Any]
- set_qstate(qstate: QstateEnt | QstateUnEnt, qstate_type: str) None
Sets a given qstate as either a private or public qubit of the Agent
- Parameters:
qstate (QstateEnt or QstateUnEnt) – Quantum state of a private or public system of qubits
qstate_type (str) – Whether the given qstate is to be private or public
- Returns:
None
- class qcrypto.qstates.QState
Bases:
ABC
- abstract apply_gate(gate: ndarray[Any, dtype[complex128]], qubit_idx: int | ndarray[Any, dtype[int64]] | list[int] | None = None) None
- abstract measure(qubit_idx: int) int
- abstract measure_all(*args: Any) ndarray[Any, dtype[int64]]
- class qcrypto.qstates.QstateEnt(_state: ~numpy.ndarray[~typing.Any, ~numpy.dtype[~numpy.complex128]] | None = None, num_qubits: int = 10, init_method: str = 'zeros', rng: ~numpy.random._generator.Generator = <factory>)
Bases:
QState
Represents the state of a set of N qubits which might be entangled.
- apply_gate(gate: ndarray[Any, dtype[complex128]], _: Any | None = None) None
Applies quantum gate to the system of qubits.
- Parameters:
gate (np.NDarray) – Gate to be applied to the to the system
- Returns:
n/a
- init_method: str = 'zeros'
- measure(qubit_idx: int) int
Measure the qubit_idx’th qubit, calculating the probability of each outcome and returning said outcome.
- Parameters:
qubit_idx (int) – Index identifying the qubit to be measured
- Returns:
Outcome of the measurement, either 0 or 1
- measure_all(order: str) ndarray[Any, dtype[int64]]
Measures all of the qubits
- Parameters:
order (str) – Specifies the order in which the qubits will be measured. “simult” = all qubits measured simultaneously “sequential” = qubits measured in sequential order (first 0, second 1, etc.)
- Returns:
Outcome of the measurements done. Array of 0’s and 1’s equal in length to the number of qubits in the system.
- num_qubits: int = 10
- rng: Generator
- class qcrypto.qstates.QstateUnEnt(_state: 'npt.NDArray[np.complex128] | None' = None, num_qubits: 'int' = 10, init_method: 'str' = 'zeros', rng: 'np.random.Generator' = <factory>)
Bases:
QState
- apply_gate(gate: ndarray[Any, dtype[complex128]], qubit_idx: int | ndarray[Any, dtype[int64]] | list[int] | None = None) None
Applies a given gate to a subset of qubits, modifying the quantum state.
- Parameters:
gate (np.array) – Gate to be applied. Represented as a numpy matrix
qubit_idx (int, list) – Index/Indices of qubit/qubits which will be transformed by gate
- Returns:
None
- init_method: str = 'zeros'
- measure(qubit_idx: int) int
Simulates the measurement of a single qubit. As a result, the state of said qubit is collapsed depending on the result.
- Parameters:
qubit_idx (int) – Index of the qubit to be measured
- Returns:
Outcome of the measurement. Also collapses the state of the qubit.
- measure_all(*args: Any) ndarray[Any, dtype[int64]]
Measures all of the qubits in sequential order.
- Parameters:
n/a
- Returns:
Numpy array containing the outcome of all of the measurements.
- num_qubits: int = 10
- rng: Generator
- qcrypto.gates.Phase_shift(phase: float) ndarray[Any, dtype[complex128]]
Generates a phase shift gate for a given phase.
- Parameters:
phase (float) – The phase angle in radians.
- Returns:
A 2x2 numpy array representing the phase shift gate.
- Return type:
NDArray
- qcrypto.gates.tensor_power(gate: ndarray[Any, dtype[complex128]], N: int) ndarray[Any, dtype[complex128]]
Computes the tensor power of a 2x2 gate matrix.
- Parameters:
gate (NDArray) – A 2x2 numpy array representing a quantum gate.
N (int) – The power to which the gate matrix is to be raised, tensor-wise.
- Returns:
A numpy array representing the N-th tensor power of the gate.
- Return type:
NDArray