Skip to content

Commit

Permalink
Create neural_network_quantum.py
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Jul 13, 2024
1 parent 53f6d66 commit e787390
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions ai_engine/neural_network_quantum.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import tensorflow as tf
from qiskit import QuantumCircuit, execute

class QuantumNeuralNetwork:
def __init__(self, input_shape, num_classes):
self.model = tf.keras.Sequential([
tf.keras.layers.Dense(64, activation='relu', input_shape=input_shape),
tf.keras.layers.Dense(32, activation='relu'),
tf.keras.layers.Dense(num_classes, activation='softmax')
])
self.quantum_circuit = QuantumCircuit(5, 5)

def train(self, X_train, y_train, epochs=10, batch_size=32):
self.model.fit(X_train, y_train, epochs=epochs, batch_size=batch_size, validation_split=0.2)
self.quantum_circuit.barrier()
job = execute(self.quantum_circuit, backend='qasm_simulator', shots=1024)
result = job.result()
self.model.set_weights(result.get_statevector())

def predict(self, X_test):
return self.model.predict(X_test)

0 comments on commit e787390

Please sign in to comment.