Skip to content

Commit

Permalink
Merge branch 'dev' into unittesting
Browse files Browse the repository at this point in the history
  • Loading branch information
Marvmann authored Dec 6, 2024
2 parents eb900f8 + 34f803c commit dbc36d2
Show file tree
Hide file tree
Showing 13 changed files with 656 additions and 75 deletions.
45 changes: 43 additions & 2 deletions .settings/module_db.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"build_number": 16,
"build_date": "03-12-2024 10:07:24",
"git_revision_number": "d8a1d4277c0138703a1458fa1045fb9afd6a5470",
"build_date": "03-12-2024 10:33:07",
"git_revision_number": "5dd793e3a63cae9acd48fc083569f9ba20615e4c",
"modules": [
{
"name": "PVC",
Expand Down Expand Up @@ -2082,6 +2082,47 @@
"class": "MIS",
"module": "modules.applications.optimization.MIS.MIS",
"submodules": [
{
"name": "QIRO",
"class": "QIRO",
"args": {},
"module": "modules.applications.optimization.MIS.mappings.QIRO",
"requirements": [
{
"name": "qrisp",
"version": "0.5.2"
}
],
"submodules": [
{
"name": "QrispQIRO",
"class": "QIROSolver",
"args": {},
"module": "modules.solvers.QrispQIRO",
"requirements": [
{
"name": "qrisp",
"version": "0.5.2"
}
],
"submodules": [
{
"name": "qrisp_simulator",
"class": "QrispSimulator",
"args": {},
"module": "modules.devices.qrisp_simulator.QrispSimulator",
"requirements": [
{
"name": "qrisp",
"version": "0.5.2"
}
],
"submodules": []
}
]
}
]
},
{
"name": "NeutralAtom",
"class": "NeutralAtom",
Expand Down
4 changes: 2 additions & 2 deletions .settings/requirements_full.txt
Git LFS file not shown
65 changes: 52 additions & 13 deletions src/ConfigManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,33 @@ def generate_benchmark_configs(self, app_modules: list[dict]) -> None:
self.application = _get_instance_with_sub_options(app_modules, app_name)

application_config = self.application.get_parameter_options()
application_config = ConfigManager._query_for_config(
application_config, f"(Option for {application_answer['application']})")

submodule_options = self.application.get_available_submodule_options()
submodule_answer = checkbox(key='submodules', message="What submodule do you want?",
choices=submodule_options)
more_app_config = {}

full_application_config = ConfigManager._query_for_config(
application_config, f"(Option for {application_answer['application']})")
depending_submodules = False

available_submodules = []
for parameter in application_config:
if ("depending_submodule" in application_config[parameter] and
application_config[parameter]["depending_submodule"]):
available_submodules = self.application.get_available_submodules(full_application_config[parameter])
depending_submodules = True
if not depending_submodules:
available_submodules = self.application.get_available_submodule_options()
submodule_answer = checkbox(key='submodules',
message="What submodule do you want?",
choices=available_submodules)
for option in submodule_answer["submodules"]:
if self.application.depending_parameters:
more_app_config = self.application.get_depending_parameters(option, full_application_config)
more_app_config = (ConfigManager._query_for_config
(more_app_config, f"(Option for {self.application.__class__.__name__})"))
full_application_config = full_application_config | more_app_config
self.config = {
"application": {
"name": app_name,
"config": application_config,
"config": full_application_config,
"submodules": [self.query_module(self.application.get_submodule(sm), sm) for sm in
submodule_answer["submodules"]],
},
Expand All @@ -109,15 +125,38 @@ def query_module(self, module: Core, module_friendly_name: str) -> ConfigModule:
:return: Config module with the choices of the user
"""
module_config = module.get_parameter_options()
module_config = ConfigManager._query_for_config(module_config,
f"(Option for {module.__class__.__name__})")
available_submodules = module.get_available_submodule_options()
submodule_answer = checkbox(key='submodules', message="What submodule do you want?",
choices=available_submodules)
full_module_config = ConfigManager._query_for_config(module_config, f"(Option for {module.__class__.__name__})")
depending_submodules = False
available_submodules = []
for parameter in module_config:
if ("depending_submodule" in module_config[parameter] and
module_config[parameter]["depending_submodule"]):
available_submodules = module.get_available_submodules(full_module_config[parameter])
depending_submodules = True
if not depending_submodules:
available_submodules = module.get_available_submodule_options()
more_module_config = {}
if available_submodules:
if len(available_submodules) == 1:
logging.info(
f"Skipping asking for submodule, since only 1 option ({available_submodules[0]}) is available.")
submodule_answer = {"submodules": [available_submodules[0]]}
else:
submodule_answer = checkbox(key='submodules',
message="What submodule do you want?",
choices=available_submodules)
for option in submodule_answer:
if module.depending_parameters:
more_module_config = module.get_depending_parameters(option, full_module_config)
more_module_config = (ConfigManager._query_for_config
(more_module_config, f"(Option for {module.__class__.__name__})"))
full_module_config = full_module_config | more_module_config
else:
submodule_answer = {"submodules": []}

return {
"name": module_friendly_name,
"config": module_config,
"config": full_module_config,
"submodules": [self.query_module(module.get_submodule(sm), sm) for sm in
submodule_answer["submodules"]]
}
Expand Down
3 changes: 2 additions & 1 deletion src/Plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
from collections import defaultdict
import logging

import matplotlib.pyplot as plt
import matplotlib
from matplotlib import pyplot as plt
import seaborn as sns
import pandas as pd

matplotlib.use('Agg')
matplotlib.rcParams['savefig.dpi'] = 300
sns.set(style="darkgrid")

Expand Down
25 changes: 24 additions & 1 deletion src/modules/Core.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import logging
from abc import ABC, abstractmethod
from typing import final

from utils import _get_instance_with_sub_options
from Metrics import Metrics

Expand All @@ -32,10 +33,11 @@ def __init__(self, name: str = None):
"""
Constructor method.
:param name: name used to identify this QUARK module. If not specified class name will be used as default.
:param name: Name used to identify this QUARK module. If not specified class name will be used as default.
"""
self.submodule_options = []
self.sub_options = []
self.depending_parameters = False
self.preprocessed_input = None
self.postprocessed_input = None
if name is None:
Expand Down Expand Up @@ -68,6 +70,27 @@ def get_parameter_options(self) -> dict:
raise NotImplementedError("Please don't use the base version of get_parameter_options. "
"Implement your own override instead.")

def get_available_submodules(self, option: list) -> list:
"""
If the module has submodules depending on certain options, this method should adjust the submodule_options
accordingly.
:param option: List of chosen options
:return: List of available submodules
"""
return []

def get_depending_parameters(self, option: str, config: dict) -> dict:
"""
If the module has parameters depending on certain options, this method should return the parameters for the
given option.
:param option: The chosen option
:param config: Current config dictionary
:return: The parameters for the given option
"""
return {}

@final
def get_submodule(self, option: str) -> Core:
"""
Expand Down
Loading

0 comments on commit dbc36d2

Please sign in to comment.