ingenii_quantum.visualizer
- class ingenii_quantum.visualizer.QuantumVisualizer(qc)[source]
Bases:
object- static area_segment(r, h)[source]
Calculate the area of a circular segment.
- Parameters:
r (float) – The radius of the circle.
h (float) – The height of the segment (distance from the chord to the arc).
- Returns:
The area of the circular segment.
- Return type:
float
- static bit_string_index(s)[source]
Return the index of a string of 0s and 1s.
- Parameters:
s (string) – bit string
- Returns:
index of the string.
- Return type:
int
- static color_range(c1, c2, n)[source]
Generate a color gradient between two colors.
- Parameters:
c1 (str) – The starting color in hexadecimal.
c2 (str) – The ending color in hexadecimal.
n (int) – The number of gradient steps.
- Returns:
A list of colors in hexadecimal format.
- Return type:
list
- static count_control_num(gate_name)[source]
Count the number of consecutive ‘c’ characters in a gate name.
- Parameters:
gate_name (str) – The name of the gate.
- Returns:
The number of consecutive ‘c’ characters.
- Return type:
int
- draw_arrow(vector, old_vector, position, tol=0.001)[source]
Draw arrows connecting states between layers.
- Parameters:
vector (np.ndarray) – Current statevector (after the gate is applied).
old_vector (np.ndarray) – Previous statevector (before the gate is applied).
position (int) – The layer index (x-axis position in the visualization).
tol (float) – Tolerance for non-zero probabilities.
- draw_bloch_sphere(theta=None, phi=None, ax=None, filename=None)[source]
Visualize a single-qubit quantum state on the Bloch sphere.
- Parameters:
theta (float) – Polar angle for the Bloch vector (default 0).
phi (float) – Azimuthal angle for the Bloch vector (default 0).
ax (matplotlib.axes) – A Matplotlib axes to draw on (optional).
filename (str) – Path to save the plot (optional).
- Returns:
The Matplotlib figure object (if fig is not provided).
- Return type:
matplotlib.figure.Figure
- static draw_color_legend(figsize=None, ax=None, n=64, use_degrees=False, filename=None)[source]
Plot the color legend for the qsphere and state space.
- Parameters:
figsize (tuple) – Figure size in inches.
ax (matplotlib.axes.Axes) – An optional Axes object to be used for the visualization output. If none is specified a new matplotlib Figure will be created and used. Additionally, if specified there will be no returned Figure since it is redundant.
n (int) – Number of divisions of the color legend.
use_degrees (bool) – An optional boolean indicating whether to use
numbers. (degrees or complex)
filename (str) – File to save the plot if desired
- Returns:
A matplotlib figure instance if the
axkwarg is not set- Return type:
Figure
- draw_geometric_plots(filename=None, display_math=False)[source]
Create and visualize geometric representations of a quantum state, including phase disks, the Q-sphere or Bloch sphere, and a color legend.
- Parameters:
filename (str, optional) – If provided, saves the generated plot to the specified file. Defaults to None.
display_math (bool) – If True, show the fullness of the disks
- Returns:
The created figure containing the plots.
- Return type:
matplotlib.figure.Figure
- draw_phase_disks(ax=None, filename=None, display_math=False)[source]
Plot the color legend for the qsphere and state space.
- Parameters:
ax (matplotlib.axes.Axes) – An optional Axes object to be used for the visualization output. If none is specified a new matplotlib Figure will be created and used. Additionally, if specified there will be no returned Figure since it is redundant.
filename (str) – File to save the plot if desired
display_math (bool) – If True, show the fullness of the disk
- Returns:
A matplotlib figure instance if the
axkwarg is not set- Return type:
Figure
- draw_probabilities(statevector, position, tol=0.001)[source]
Draw probability circles for a given statevector.
- Parameters:
statevector (np.ndarray) – The statevector.
position (int) – The x-axis position of the circles.
ax (matplotlib.axes) – axes to draw the probabilities
tol (float) – Tolerance for non-zero probabilities.
- draw_qsphere(figsize=None, ax=None, show_state_labels=True, show_state_phases=False, use_degrees=False, tol=0.001, filename=None)[source]
Plot the qsphere representation of a quantum state. Here, the size of the points is proportional to the probability of the corresponding term in the state and the color represents the phase.
- Parameters:
figsize (tuple) – Figure size in inches.
ax (matplotlib.axes.Axes) – An optional Axes object to be used for the visualization output. If none is specified a new matplotlib Figure will be created and used. Additionally, if specified there will be no returned Figure since it is redundant.
show_state_labels (bool) – An optional boolean indicating whether to show labels for each basis state.
show_state_phases (bool) – An optional boolean indicating whether to show the phase for each basis state.
use_degrees (bool) – An optional boolean indicating whether to use radians or degrees for the phase values in the plot.
tol (float) – tolerance to show basis state on the sphere
filename (str) – File to save the plot if desired
- Returns:
A matplotlib figure instance if the
axkwarg is not set- Return type:
Figure
- draw_state_space(plot_circuit=False, plot_phase_disks=False, display_math=False, filename=None)[source]
Visualize the quantum circuit’s evolution. Optionally include the circuit diagram.
- Parameters:
plot_circuit (bool) – If True, include the quantum circuit diagram in the figure.
plt_phase_disks (bool) – If True, include the diagram of phase disks in the figure.
display_math (bool) – If True, include the value of the statevectors in the figure.
filename (str) – File name to save the figure.
- Returns:
figure of the state space
- Return type:
matplotlib.pyplot.figure
- static flip_bit(bitstring, i)[source]
Flip the bit at position i in a binary string.
- Parameters:
bitstring (str) – The binary string.
i (int) – The position of the bit to flip (0-indexed).
- Returns:
The binary string with the bit at position i flipped.
- Return type:
str
- static get_colors(n)[source]
Generate a full cyclic color map with gradients.
- Parameters:
n (int) – Total number of colors.
- Returns:
A list of colors in hexadecimal format.
- Return type:
list
- get_statevectors()[source]
Extract statevectors and gate information from the quantum circuit.
- Returns:
(list of statevectors, gate set)
- Return type:
tuple
- get_transformed_bitstrings(unitary, tol=1e-08)[source]
Compute the transformation of all basis states under a unitary matrix and output the transformed bitstrings.
- Parameters:
unitary (np.ndarray) – The unitary matrix of size (2^n, 2^n).
tol (float) – Tolerance for considering a value as non-zero.
- Returns:
A dictionary mapping input bitstrings to their transformed bitstrings.
- Return type:
dict
- static height_for_probability(radius, prob, total_area)[source]
Calculate the height (h) of a circular segment corresponding to a given probability.
- Parameters:
radius (float) – Radius of the circle.
prob (float) – Desired probability (fraction of the circle’s area to fill).
total_area (float) – Total area of the circle.
- Returns:
Height (h) of the segment.
- Return type:
float
- static hex_to_rgb(hex_str)[source]
Convert a hexadecimal color string to an RGB tuple.
- Parameters:
hex_str (str) – The hexadecimal color string.
- Returns:
The RGB color as a numpy array.
- Return type:
np.ndarray
- static lex_index(n, k, lst)[source]
Return the lex index of a combination..
- Parameters:
n (int) – the total number of options .
k (int) – The number of elements.
lst (list) – list
- Returns:
returns int index for lex order
- Return type:
int
- Raises:
VisualizationError – if length of list is not equal to k
- static n_choose_k(n, k)[source]
Return the number of combinations for n choose k.
- Parameters:
n (int) – the total number of options .
k (int) – The number of elements.
- Returns:
binomial coefficient
- Return type:
int
- static phase_to_rgb(complex_number, n=64, tol=0.001, return_black=True)[source]
Map a phase of a complex number to a color.
- Parameters:
complex_number (complex) – The input complex number.
n (int) – Number of colors in the gradient.
- Returns:
RGB color in hexadecimal format.
- Return type:
str
- static statevector_to_angles(phi)[source]
Convert a quantum statevector into spherical coordinates (theta, phi) for Bloch sphere representation.
- Parameters:
phi (ndarray) – A 2-element array-like object representing a single-qubit statevector.
- Returns:
Polar angle (0 to pi). phi (float): Azimuthal angle (0 to 2*pi).
- Return type:
theta (float)
ingenii_quantum.hybrid_networks
- ingenii_quantum.hybrid_networks.edge_detection
- ingenii_quantum.hybrid_networks.filters
QuantumFilters2DQuantumFilters3DQuantumFiltersBaseQuantumFiltersBase.n_dimensionsQuantumFiltersBase.shapeQuantumFiltersBase.strideQuantumFiltersBase.encodingQuantumFiltersBase.shotsQuantumFiltersBase.backendQuantumFiltersBase.nqbitsQuantumFiltersBase.deviceQuantumFiltersBase.unitaries_listQuantumFiltersBase.num_filtersQuantumFiltersBase.num_featuresQuantumFiltersBase.gates_nameQuantumFiltersBase.infoQuantumFiltersBase.gate_namesQuantumFiltersBase.generate_qc()QuantumFiltersBase.generate_reservoirs()QuantumFiltersBase.generate_unitaries()QuantumFiltersBase.get_quantum_filters()QuantumFiltersBase.load_gates()QuantumFiltersBase.load_reservoirs()QuantumFiltersBase.load_unitaries()
- ingenii_quantum.hybrid_networks.layers
QuantumFCLayerQuantumFCLayer.input_sizeQuantumFCLayer.n_layersQuantumFCLayer.encodingQuantumFCLayer.ansatzQuantumFCLayer.observablesQuantumFCLayer.backendQuantumFCLayer.nqbitsQuantumFCLayer.devQuantumFCLayer.apply_ansatz()QuantumFCLayer.create_layer()QuantumFCLayer.get_shapes()QuantumFCLayer.qnn_layer()QuantumFCLayer.qnn_layer_QAOA()
- ingenii_quantum.hybrid_networks.qinsp_filter
- ingenii_quantum.hybrid_networks.statistics
- ingenii_quantum.hybrid_networks.utils