Remove most usages of put_{vector,vector_list}; deprecate get_set

This commit is contained in:
2021-08-10 11:52:02 -05:00
parent 60b9a6775f
commit ed58242b5c
9 changed files with 40 additions and 176 deletions

View File

@@ -13,6 +13,7 @@ from miplearn.components.objective import ObjectiveValueComponent
from miplearn.features.sample import Sample, MemorySample
from miplearn.solvers.learning import LearningSolver
from miplearn.solvers.pyomo.gurobi import GurobiPyomoSolver
from miplearn.solvers.tests import assert_equals
@pytest.fixture
@@ -21,7 +22,7 @@ def sample() -> Sample:
{
"mip_lower_bound": 1.0,
"mip_upper_bound": 2.0,
"lp_instance_features": [1.0, 2.0, 3.0],
"lp_instance_features": np.array([1.0, 2.0, 3.0]),
},
)
return sample
@@ -29,18 +30,18 @@ def sample() -> Sample:
def test_sample_xy(sample: Sample) -> None:
x_expected = {
"Lower bound": [[1.0, 2.0, 3.0]],
"Upper bound": [[1.0, 2.0, 3.0]],
"Lower bound": np.array([[1.0, 2.0, 3.0]]),
"Upper bound": np.array([[1.0, 2.0, 3.0]]),
}
y_expected = {
"Lower bound": [[1.0]],
"Upper bound": [[2.0]],
"Lower bound": np.array([[1.0]]),
"Upper bound": np.array([[2.0]]),
}
xy = ObjectiveValueComponent().sample_xy(None, sample)
assert xy is not None
x_actual, y_actual = xy
assert x_actual == x_expected
assert y_actual == y_expected
assert_equals(x_actual, x_expected)
assert_equals(y_actual, y_expected)
def test_fit_xy() -> None:

View File

@@ -36,13 +36,15 @@ def sample() -> Sample:
"static_constr_names": np.array(["c1", "c2", "c3", "c4", "c5"], dtype="S"),
"static_instance_features": [5.0],
"mip_constr_lazy_enforced": {b"c1", b"c2", b"c4"},
"lp_constr_features": [
[1.0, 1.0],
[1.0, 2.0],
[1.0, 3.0],
[1.0, 4.0, 0.0],
None,
],
"lp_constr_features": np.array(
[
[1.0, 1.0, 0.0],
[1.0, 2.0, 0.0],
[1.0, 3.0, 0.0],
[1.0, 4.0, 0.0],
[0.0, 0.0, 0.0],
]
),
"static_constr_lazy_count": 4,
},
)
@@ -216,7 +218,7 @@ def test_fit_xy() -> None:
def test_sample_xy(sample: Sample) -> None:
x_expected = {
b"type-a": [[5.0, 1.0, 1.0], [5.0, 1.0, 2.0], [5.0, 1.0, 3.0]],
b"type-a": [[5.0, 1.0, 1.0, 0.0], [5.0, 1.0, 2.0, 0.0], [5.0, 1.0, 3.0, 0.0]],
b"type-b": [[5.0, 1.0, 4.0, 0.0]],
}
y_expected = {

View File

@@ -61,7 +61,7 @@ def test_knapsack() -> None:
np.array(["default", "default", "default", "default", ""], dtype="S"),
)
assert_equals(
sample.get_vector_list("static_var_features"),
sample.get_array("static_var_features"),
np.array(
[
[23.0, 505.0, 1.0, 0.32899, 0.0, 505.0, 1.0],
@@ -155,7 +155,7 @@ def test_knapsack() -> None:
np.array([1.0, 0.923077, 1.0, 0.0, 67.0]),
)
assert_equals(
sample.get_vector_list("lp_var_features"),
sample.get_array("lp_var_features"),
np.array(
[
[

View File

@@ -18,7 +18,7 @@ def test_usage() -> None:
filename = tempfile.mktemp()
FileInstance.save(original, filename)
sample = Hdf5Sample(filename, check_data=True)
assert len(sample.get_bytes("pickled")) > 0
assert len(sample.get_array("pickled")) > 0
# Solve instance from disk
solver = LearningSolver(solver=GurobiSolver())