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
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]
# ============================================================================= # 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 # reduced Planck constant
import svect as sv import numpy as np from math import pi import qneural as qn from matplotlib import pyplot as plt # ============================================================================= # Entropy Dynamics for a Unitary Quantum Neural Map # ============================================================================= # ============================================================================= # Part 1 - Preparation # ============================================================================= # Setup the initial operator to get the initial density U0 = sv.tensorProd([sv.WHGate(), sv.WHGate()]) # Initialize the network Net, mult_2 = qn.initialize_network(num_neurons=2, initial_operator=U0, type_initial='Unitary', return_multipliers=True) print("\nInitial Density") print(Net.rho) print("\nLocal Operators") print("\nNeuron 0") print(Net.local_operators[0])
# ============================================================================= # 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]) # Prepare the Quantum Circuit r=0.6
P1 = sv.proj2x2(True) one = sv.unit() 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] # ============================================================================= # Part 2 - Preparation of neural network # ============================================================================= # 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])
# ============================================================================= # Mean Firing Energy vs Mutual Information Plots for a Stochastic Map # ============================================================================= # ============================================================================= # 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 # reduced Planck constant
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)
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 Design: U0 = sv.tensorProd([H, I]) # First transition in circuit CNOT = sv.tensorProd([P0, I]) + sv.tensorProd([P1, X]) # CNOT gate # 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("\nStep 1:") ket = sv.transformKet(U0, ket)
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] # ============================================================================= # Part 2 - Preparation of the neural network # ============================================================================= # Initialize the network to one of the eigenvectors Net, mult_2 = qn.initialize_network(num_neurons=2, initial_operator=sv.tensorProd([P0, P0]), type_initial='Density', return_multipliers=True) # ============================================================================= # Part 3 - Eigenvalue and entropy analysis # ============================================================================= step = 0.001 r = 0 neural_map = Net.build_quantum_neural_map(get_unitaries(r * pi)) eigenvalues, eigenvectors = Net.get_eigenvectors(neural_map, printout=False) r_values = [] phases_values = []