Skip to content

Commit

Permalink
examples/anomaly_detection
Browse files Browse the repository at this point in the history
  • Loading branch information
renatomello committed Oct 31, 2024
1 parent dfe8a2c commit 5700014
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions examples/anomaly_detection/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
import matplotlib.pyplot as plt
import numpy as np

import qibo
from qibo import Circuit, gates
from qibo import Circuit, gates, get_backend, set_backend

LOCAL_FOLDER = Path(__file__).parent

Expand All @@ -21,8 +20,8 @@ def main(n_layers, train_size, filename, plot, save_loss):
save_loss (bool): save losses for standard and anomalous data (default False).
"""

qibo.set_backend(backend="qiboml", platform="tensorflow")
tf = qibo.get_backend().tf
set_backend(backend="qiboml", platform="tensorflow")
tf = get_backend().tf

# Circuit ansatz
def make_encoder(n_qubits, n_layers, params, q_compression):
Expand All @@ -35,7 +34,7 @@ def make_encoder(n_qubits, n_layers, params, q_compression):
q_compression (int): number of compressed qubits.
Returns:
encoder (qibo.models.Circuit): variational quantum circuit.
:class:`qibo.models.Circuit`: Variational quantum circuit.
"""

index = 0
Expand All @@ -62,11 +61,11 @@ def compute_loss_test(encoder, vector):
"""Evaluate loss function for one test sample.
Args:
encoder (qibo.models.Circuit): variational quantum circuit (trained).
vector (tf.Tensor): test sample, in the form of 1d vector.
encoder (:class:`qibo.models.Circuit`): variational quantum circuit (trained).
vector (:class:`tf.Tensor`): test sample, in the form of 1d vector.
Returns:
loss (tf.Variable): loss of the test sample.
:class:`tf.Variable`: Loss of the test sample.
"""
reconstructed = encoder(vector)
# 3 qubits compression
Expand Down

0 comments on commit 5700014

Please sign in to comment.