Skip to content
Draft
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
15 changes: 13 additions & 2 deletions src/queens/parameters/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import numpy as np

from queens.distributions._distribution import Continuous, Discrete
from queens.distributions.free_variable import FreeVariable
from queens.parameters.random_fields._random_field import RandomField
from queens.utils.logger_settings import log_init_args

Expand Down Expand Up @@ -60,16 +61,26 @@ class Parameters:
"""

@log_init_args
def __init__(self, **parameters):
def __init__(self, *parameters_without_distribution, **parameters):
"""Initialize Parameters object.

Args:
**parameters (Distribution, RandomField): parameters as keyword arguments
*parameters_without_distribution (str): Names of one-dimensional parameters without
assumption about underlying distribution.
Comment on lines +68 to +69
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
*parameters_without_distribution (str): Names of one-dimensional parameters without
assumption about underlying distribution.
*parameters_without_distribution (str): Names of one-dimensional parameters without
assumption about the underlying distribution.

**parameters (Distribution, RandomField): parameters as keyword arguments. The keyword
corresponds to the parameter name and the
value corresponds to the underlying
distribution.
"""
joint_parameters_keys = []
joint_parameters_dim = 0
random_field_flag = False

for parameter_name in parameters_without_distribution:
if parameter_name in parameters:
raise ValueError(f"Parameter name {parameter_name} can only be used once.")
Comment on lines +79 to +81
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch. I think the error message should be more precise, specifying that it was specified once by pure name and once using a distribution.

Additionally, we need to check if the user provides the same name twice, e.g., Parameters("x1","x1") as this might happen now.

parameters[parameter_name] = FreeVariable(1)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add some logging information that we are assuming the parameter to be 1d?


for parameter_name, parameter_obj in parameters.items():
if isinstance(parameter_obj, (Continuous, Discrete)):
joint_parameters_keys = _add_parameters_keys(
Expand Down
4 changes: 1 addition & 3 deletions tests/integration_tests/iterators/test_optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@
def test_optimization_rosenbrock(algorithm, global_settings):
"""Test different solution algorithms in optimization iterator."""
# Parameters
x1 = FreeVariable(dimension=1)
x2 = FreeVariable(dimension=1)
parameters = Parameters(x1=x1, x2=x2)
parameters = Parameters("x1", "x2")

# Setup iterator
driver = Function(parameters=parameters, function="rosenbrock60")
Expand Down
Loading