def generate_multipliers_neuron(self, multipliers_list, neuron_index): # Method to return extended multipliers list for a given neuron # used for the reduced density operations # 1. Define a fixed tuple of unit vectors ones = tuple([svect.unit()] * self.num_neurons) # 2. Define the extended multipliers list M = [] # 3. Get the extended multipliers per neuron for multiplier in multipliers_list: # Change at the neuron's position for the multiplier a = list(ones) a[neuron_index] = multiplier # Get the tensor product for the extension to the firing # pattern basis multiplier_extended = svect.tensorProd(a) # Append the multiplier to the multipliers list M.append(multiplier_extended) # 4. Return extended multipliers list on the N neurons Hilbert space return M
# ============================================================================= # Mean Firing Energy vs Mutual Information Plots for a Stochastic Map # with the initial density set equal to an eigendensity # ============================================================================= # ============================================================================= # Part 1 - Definition of function needed for the stochastic updade and of # the Hamiltonian for the mean firing energy calculation # ============================================================================= V = np.matrix([[0, -1], [1, 0]]) P0 = sv.proj2x2(False) P1 = sv.proj2x2(True) one = sv.unit() P01 = sv.tensorProd([P0, P1]) P10 = sv.tensorProd([P1, P0]) P11 = sv.tensorProd([P1, P1]) # Get the unitary operators list for the quantum neural map def get_unitaries(angle): U_angle = np.cos(angle / 2) * one + np.sin(angle / 2) * V U01 = sv.tensorProd([P0, one]) + sv.tensorProd([P1, U_angle]) U10 = sv.tensorProd([one, P0]) + sv.tensorProd([U_angle, P1]) return [U01, U10] # Get the Hamiltonian for the quantum mean firing energy, the # factor is equal to the angular frequency multiplied by the
print("\nLocal Operators") print("\nNeuron 0") print(Net.local_operators[0]) print("\nNeuron 1") print(Net.local_operators[1]) # Prepare Quantum Circuit r = 0.001 V = np.matrix([[0, -1], [1, 0]]) U_r = np.cos(r * pi / 2) * sv.unit() + np.sin(r * pi / 2) * V U01 = sv.tensorProd([sv.proj2x2(False), sv.unit()]) + sv.tensorProd( [sv.proj2x2(True), U_r]) U10 = sv.tensorProd([sv.unit(), sv.proj2x2(False)]) + sv.tensorProd( [U_r, sv.proj2x2(True)]) NeuralMap = Net.build_quantum_neural_map([U01, U10]) # ============================================================================= # Part 2 - Iterate the network # ============================================================================= # Get the density sequence densities = Net.iterate_density(map_operator=NeuralMap, T=30000,
from math import pi import qneural as qn from matplotlib import pyplot as plt # ============================================================================= # Simulating the iterations of a Quantum Neural Map # for a Quantum Recurrent Neural Network # ============================================================================= # ============================================================================= # Part 1 - Preparation # ============================================================================= P0 = sv.proj2x2(False) # operator |0><0| P1 = sv.proj2x2(True) # operator |1><1| I = sv.unit() # operator |0><0|+|1><1| # Setup the initial operator to get the initial density U0 = sv.tensorProd([sv.WHGate(),sv.WHGate()]) # Initialize the network Net = qn.initialize_network(num_neurons=2, initial_operator=U0, type_initial='Unitary', return_multipliers=False) print("\nInitial Density") print(Net.rho) print("\nLocal Operators") print("\nNeuron 0") print(Net.local_operators[0]) print("\nNeuron 1") print(Net.local_operators[1])
import svect as sv import numpy as np # Main Operators Used in the Circuit: H = sv.WHGate() # Walsh-Haddamard transform I = sv.unit() # Unit gate X = sv.PauliX() # Pauli X P0 = sv.proj2x2(False) # Projector P0 = |0><0| P1 = sv.proj2x2(True) # projector P1 = |1><1| # Circuit Operator UCircuit = np.dot( sv.tensorProd([P0, I]) + sv.tensorProd([P1, X]), sv.tensorProd([H, I])) # Basis: basis = sv.basisDef(2) # we are working with a two register basis # Initial amplitude: psi0 = np.zeros(len(basis)) psi0[0] = 1 # Initial ket: ket = sv.getKet(basis, psi0) # Implementing the quatum circuit: print("\nQUANTUM CIRCUIT SIMULATION") print("\nInitial ket vector:") sv.showKet(ket) print("\nFinal ket vector:") ket = sv.transformKet(UCircuit, ket)