Skip to content

Commit

Permalink
lint changes
Browse files Browse the repository at this point in the history
  • Loading branch information
SaashaJoshi committed Sep 2, 2023
1 parent 540da9e commit 0d40b80
Show file tree
Hide file tree
Showing 17 changed files with 232 additions and 78 deletions.
92 changes: 92 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/quantum-image-processing.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 14 additions & 1 deletion .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions make_init.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
from os.path import isdir, join

root = "."
finit = '__init__.py'
finit = "__init__.py"


def visitor(arg, dirname, fnames):
fnames = [fname for fname in fnames if isdir(fname)]
# here you could do some additional checks ...
print "adding %s to : %s" %(finit, dirname)
with open(join(dirname, finit), 'w') as file_: file_.write('')
print("adding %s to : %s" % (finit, dirname))
with open(join(dirname, finit), "w") as file_:
file_.write("")


walk(root, visitor, None)
walk(root, visitor, None)
18 changes: 8 additions & 10 deletions quantum_image_processing/data_loader/mnist_data_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,26 @@
def load_mnist_data():
"""
Loads MNIST dataset from PyTorch using DataLoader.
:return: Train and Test DataLoader objects.
Return:
Train and Test DataLoader objects.
"""

mnist_train = datasets.MNIST(
root="../data_loader/mnist_data",
train=True,
download=False,
transform=torchvision.transforms.Compose([
torchvision.transforms.ToTensor(),
torchvision.transforms.Resize(2)
])
transform=torchvision.transforms.Compose(
[torchvision.transforms.ToTensor(), torchvision.transforms.Resize(2)]
),
)

mnist_test = datasets.MNIST(
root="../data_loader/mnist_data",
train=False,
download=False,
transform=torchvision.transforms.Compose([
torchvision.transforms.ToTensor(),
torchvision.transforms.Resize(2)
])
transform=torchvision.transforms.Compose(
[torchvision.transforms.ToTensor(), torchvision.transforms.Resize(2)]
),
)

train_dataloader = torch.utils.data.DataLoader(
Expand All @@ -53,4 +52,3 @@ def collate_fn(batch):
if label == 1 or label == 7:
new_batch.append(item)
return torch.utils.data.default_collate(new_batch)

10 changes: 6 additions & 4 deletions quantum_image_processing/models/tensor_network_circuits/mera.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def _apply_real_general_block(self, qubits, param_vector_copy):

def mera_simple(self, complex_struct=True):
param_vector = ParameterVector(
'theta',
"theta",
int(self.img_dim / 2 * (self.img_dim / 2 + 1)) + 3,
)
param_vector_copy = param_vector
Expand All @@ -97,11 +97,13 @@ def mera_simple(self, complex_struct=True):
# Check number of params here.
def mera_general(self, complex_struct=True):
if complex_struct:
param_vector = ParameterVector('theta', 20 * self.img_dim - 1)
param_vector = ParameterVector("theta", 20 * self.img_dim - 1)
param_vector_copy = param_vector
return self.mera_backbone(self._apply_complex_general_block, param_vector_copy)
return self.mera_backbone(
self._apply_complex_general_block, param_vector_copy
)
else:
param_vector = ParameterVector('theta', 10 * self.img_dim - 1)
param_vector = ParameterVector("theta", 10 * self.img_dim - 1)
param_vector_copy = param_vector
return self.mera_backbone(self._apply_real_general_block, param_vector_copy)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def data_embedding(img_dim):
:return:
"""

params = ParameterVector('img_data', img_dim)
params = ParameterVector("img_data", img_dim)
embedding = QuantumCircuit(img_dim)
for i in range(img_dim):
embedding.ry(params[i], i)
Expand Down Expand Up @@ -70,7 +70,6 @@ def callback_graph(weights, obj_func_eval):
plt.savefig("graph.pdf")
plt.show()


estimator_qnn = EstimatorQNN(
circuit=circ,
observables=observable,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def ttn_simple(self, complex_struct=True):
:return:
"""
param_vector = ParameterVector('theta', 2 * self.img_dim - 1)
param_vector = ParameterVector("theta", 2 * self.img_dim - 1)
param_vector_copy = param_vector

if complex_struct:
Expand Down Expand Up @@ -127,11 +127,13 @@ def ttn_general(self, complex_struct=True):
"""
# Check number of params here.
if complex_struct:
param_vector = ParameterVector('theta', 15 * self.img_dim - 1)
param_vector = ParameterVector("theta", 15 * self.img_dim - 1)
param_vector_copy = param_vector
return self.ttn_backbone(self._apply_complex_general_block, param_vector_copy)
return self.ttn_backbone(
self._apply_complex_general_block, param_vector_copy
)
else:
param_vector = ParameterVector('theta', 6 * self.img_dim - 1)
param_vector = ParameterVector("theta", 6 * self.img_dim - 1)
param_vector_copy = param_vector
return self.ttn_backbone(self._apply_real_general_block, param_vector_copy)

Expand Down
19 changes: 10 additions & 9 deletions quantum_image_processing/representations/first-step.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '1'

os.environ["TF_CPP_MIN_LOG_LEVEL"] = "1"
import numpy as np
from keras.datasets import mnist
import tensorflow as tf
from qiskit import QuantumCircuit
import matplotlib.pyplot as plt

(x_train, y_train), (x_test, y_test) = mnist.load_data()
print(f'X train: {x_train.shape}')
print(f'Y train: {y_train.shape}')
print(f'X test {x_test.shape}')
print(f"X train: {x_train.shape}")
print(f"Y train: {y_train.shape}")
print(f"X test {x_test.shape}")

# Plot image data
# for i in range(9):
Expand All @@ -27,10 +28,10 @@
# Plot original and resized images
row = 3
cols = 3
fig, axs = plt.subplots(row, 2*cols)
fig, axs = plt.subplots(row, 2 * cols)
for i in range(row):
for j in range(0, 2*cols, 2):
axs[i, j].imshow(x_train[i+j])
axs[i, j+1].imshow(resize_x_train[i+j])
for j in range(0, 2 * cols, 2):
axs[i, j].imshow(x_train[i + j])
axs[i, j + 1].imshow(resize_x_train[i + j])
# plt.imshow(resize_x_train[i], cmap=plt.get_cmap('binary_r'))
plt.show()
plt.show()
Loading

0 comments on commit 0d40b80

Please sign in to comment.