Circuit Test Functions
- circuit_test.normal_pdf(x: ndarray, mu: float = 0, sigma: float = 1) ndarray
Calculates the probability density of the normal (Gaussian) distribution.
- Parameters:
x (np.ndarray) – The input values where the PDF is evaluated.
mu (float, optional) – The mean of the Gaussian distribution (default is 0).
sigma (float, optional) – The standard deviation of the Gaussian distribution (default is 1).
- Returns:
The probability density function evaluated at each point in x.
- Return type:
np.ndarray
- circuit_test.qft_on_gaussian(number_of_qubits: int, mu: float = 0, sigma: float = 1) None
A Applies the Quantum Fourier Transform (QFT) to a quantum state with amplitudes based on a Gaussian function and compares the resulting amplitudes with the expected amplitudes using numpy’s FFT method. The function also plots the input states’s amplitudes and the measurement plot of the resulting state.
- Parameters:
number_of_qubits (int) – The number of qubits in the quantum state.
mu (float, optional) – The mean of the Gaussian distribution (default is 0).
sigma (float, optional) – The standard deviation of the Gaussian distribution (default is 1).
- Return type:
None
- circuit_test.qft_on_sine(number_of_qubits: int) None
Applies the Quantum Fourier Transform (QFT) to a quantum state with amplitudes based on a sine function and compares the resulting amplitudes with the expected amplitudes using numpy’s FFT method. The function also plots the input states’s amplitudes and the measurement plot of the resulting state.
- Parameters:
number_of_qubits (int) – The number of qubits in the quantum state.
- Return type:
None
- circuit_test.test_qft_matrix_output(qubits_to_test: int = 3) None
Tests the correctness of the QFT circuit by comparing its matrix representation to the expected QFT matrix.
- Parameters:
qubits_to_test (int, optional) – The maximum number of qubits to test (default is 3).
- Return type:
None
- circuit_test.test_tracing_out_qubit(qubits_to_test: int, print_amplitudes: bool = False) None
Tests the process of tracing out a qubit in a multi-qubit quantum state by comparing the amplitudes of each qubit before and after the operation. The function generates a random quantum state for multiple qubits, traces out each qubit one by one, and verifies if the original amplitudes are preserved.
- Parameters:
qubits_to_test (int) – The number of qubits in the quantum state to test. Each qubit will be initialized with random amplitudes, and the test will check that the amplitudes are correctly traced out for each qubit.
print_amplitudes (bool) – A boolean value to print or not to print the lists for the original and traced amplitudes
- Returns:
This function does not return any values. It performs an assertion to verify that the traced out qubits’ amplitudes match the original amplitudes and prints confirmation.
- Return type:
None
Notes
The function assumes that the MultiQubit class has methods like add_qubit, get_qubit, and print_tensor_form for handling the quantum state, and that each Qubit has methods like get_alpha and get_beta for retrieving the amplitudes of individual qubits.
The test checks that the amplitudes of each qubit remain unchanged after tracing out each qubit by comparing them to the original values stored before the tracing out operation.
Example
>>> test_tracing_out_qubit(3) Prints the original amplitudes and confirms that tracing out each qubit works correctly.