Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring #35

Merged
merged 13 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"configurations": [
{
"name": "Kedro: Default",
"type": "python",
"type": "debugpy",
"request": "launch",
"module": "kedro",
"args": [
Expand All @@ -19,7 +19,7 @@
},
{
"name": "Kedro: Slurm",
"type": "python",
"type": "debugpy",
"request": "launch",
"module": "kedro",
"args": [
Expand Down
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,19 @@ which will open Kedro`s dashboard in you browser.

The following parameters can be adjusted:
- Data Preprocessing Parameters: `conf/base/parameters/preprocessing.yml`
- Image sidelength
- Batch size:
- a number >0 indicating the batch size
- -1 to use all of the data as batch
- Mode: Type of dataset
- "cosine": Fourier series
- "image": Cameraman image
- Domain: Range for the input data that goes into the encoding gates
- Scale Domain by Pi: If the range shall be multiplied by Pi
- Specific for 'Image' Dataset
- Sidelength: Image sidelength
- Nonlinear Coordinates: If an arcsin shall be applied on the coordinates
- Specific for 'Cosine' Dataset
- Omega: Frequencies for the Fourier series. List of lists where the "outer" list determines the dimensionality and the "inner" list the frequencies for that dimension
- Training Parameters: `conf/base/parameters/data_science.yml`
- Number of qubits
- Number of layers
Expand Down
Empty file removed conf/base/parameters.yml
Empty file.
6 changes: 0 additions & 6 deletions conf/base/parameters_postprocessing.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,2 @@
# This is a boilerplate parameters config generated for pipeline 'postprocessing'
# using Kedro 0.18.12.
#
# Documentation for this file format can be found in "Parameters"
# Link: https://docs.kedro.org/en/0.18.12/kedro_project_setup/configuration.html#parameters

postprocessing:
upscale_factor: 2
6 changes: 0 additions & 6 deletions conf/base/parameters_preprocessing.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
# This is a boilerplate parameters config generated for pipeline 'preprocessing'
# using Kedro 0.18.12.
#
# Documentation for this file format can be found in "Parameters"
# Link: https://docs.kedro.org/en/0.18.12/kedro_project_setup/configuration.html#parameters

preprocessing:
batch_size: -1
mode: "cosine" # image, cosine
Expand Down
6 changes: 0 additions & 6 deletions conf/base/parameters_training.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
# This is a boilerplate parameters config generated for pipeline 'training'
# using Kedro 0.18.12.
#
# Documentation for this file format can be found in "Parameters"
# Link: https://docs.kedro.org/en/0.18.12/kedro_project_setup/configuration.html#parameters

training: #see globals.yml for adjustment of n_qubits, n_layers,...
n_qubits: 4
n_layers: 14
Expand Down
865 changes: 504 additions & 361 deletions poetry.lock

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,24 @@ gpu=["torchvision"]

[tool.poetry.dependencies]
python = ">=3.9,<3.12"
pennylane = "^0.33.1"
pennylane = "^0.36.0"
pillow = "^10.3.0"
scikit-image = "^0.21.0"
ipykernel = "^6.25.0"
matplotlib = "^3.7.2"
torch = [
# Uncomment the following line once this issue is resolved: https://github.com/python-poetry/poetry/issues/7748 # noqa
# {version = "2.1.0", source = "torch_gpu", markers = "extra == 'gpu'"},
{version = "2.1.0+cpu", source = "torch_cpu", markers = "extra != 'gpu'"}
]
torchvision = "^0.16.0"
kedro = "^0.19.5"
kedro = "^0.19.6"
torchsummary = "^1.5.1"
torchmetrics = "^1.0.2"
kedro-mlflow = "^0.12.2"
plotly = "^5.15.0"
plotly = "^5.22.0"
black = "^24.4.2"
kaleido = "0.2.1"
mlflow = "^2.13.2"



Expand Down
85 changes: 85 additions & 0 deletions src/quantum_siren/helpers/colors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import numpy as np


def hsv_to_rgb(hsv):
"""
Convert HSV values to RGB.

Parameters
----------
hsv : (..., 3) array-like
All values assumed to be in range [0, 1]

Returns
-------
(..., 3) `~numpy.ndarray`
Colors converted to RGB values in range [0, 1]
"""
hsv = np.asarray(hsv)

# check length of the last dimension, should be _some_ sort of rgb
if hsv.shape[-1] != 3:
raise ValueError(
"Last dimension of input array must be 3; " f"shape {hsv.shape} was found."
)

in_shape = hsv.shape
hsv = np.array(
hsv,
copy=False,
dtype=np.promote_types(hsv.dtype, np.float32), # Don't work on ints.
ndmin=2, # In case input was 1D.
)

h = hsv[..., 0]
s = hsv[..., 1]
v = hsv[..., 2]

r = np.empty_like(h)
g = np.empty_like(h)
b = np.empty_like(h)

i = (h * 6.0).astype(int)
f = (h * 6.0) - i
p = v * (1.0 - s)
q = v * (1.0 - s * f)
t = v * (1.0 - s * (1.0 - f))

idx = i % 6 == 0
r[idx] = v[idx]
g[idx] = t[idx]
b[idx] = p[idx]

idx = i == 1
r[idx] = q[idx]
g[idx] = v[idx]
b[idx] = p[idx]

idx = i == 2
r[idx] = p[idx]
g[idx] = v[idx]
b[idx] = t[idx]

idx = i == 3
r[idx] = p[idx]
g[idx] = q[idx]
b[idx] = v[idx]

idx = i == 4
r[idx] = t[idx]
g[idx] = p[idx]
b[idx] = v[idx]

idx = i == 5
r[idx] = v[idx]
g[idx] = p[idx]
b[idx] = q[idx]

idx = s == 0
r[idx] = v[idx]
g[idx] = v[idx]
b[idx] = v[idx]

rgb = np.stack([r, g, b], axis=-1)

return rgb.reshape(in_shape)
Loading