Skip to content

Commit

Permalink
fix: have [row] and [col] span all implied wells
Browse files Browse the repository at this point in the history
BREAKING CHANGE:

This commit guarantees that any parameters mentioned in a [row]/[col]
block will be applied to any column/row implied in the layout.  Before,
such parameters would only be applied to columns/rows explicitly
mentioned in the layout.  The new behavior makes rows and columns more
natural to reason about: they always grow to the size of the layout.

Consider the following layout.  Previously, only wells A1 and A12
would've been included in the layout.  Now, all twelve wells in row A
are included:

    row.A.x = 1
    col.1.y = 2
    col.12.y = 3

This commit also fixes a bug where [row]/[col] didn't consider
columns/rows defined in blocks when deciding which wells to include in
the layout.   The following layout demonstrates this issue.  Previously,
this would've been an error because the row wouldn't have found any
columns to use.  Now, the row finds the columns defined by the block and
includes wells A1-A3 in the layout:

    row.A.x = 1
    block.2x2.B2.y = 2
  • Loading branch information
kalekundert committed Nov 25, 2020
1 parent 42c1d03 commit 2bd2cdc
Show file tree
Hide file tree
Showing 4 changed files with 285 additions and 23 deletions.
14 changes: 14 additions & 0 deletions tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,20 @@ def test_check_range_err(x0, x1, xn, single_step_ok, err):
def test_inclusive_range(x0, x1, xn, expected):
assert list(inclusive_range(x0, x1, xn)) == expected

@pytest.mark.parametrize(
'xs, expected', [
([], []),
([1], [1]),
([1,2], [1,2]),
([2,1], [1,2]),
([1,3], [1,2,3]),
([3,1], [1,2,3]),
]
)
def test_range_from_indices(xs, expected):
actual = util.range_from_indices(*xs)
assert list(actual) == expected

@pytest.mark.parametrize(
'key, indices', [
# A B C D E F G H
Expand Down
241 changes: 234 additions & 7 deletions tests/test_wells_from_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,21 @@ def test_multiple_rows():
(1,0): {'x': 2, 'y': 1},
}

config = {
'row': {
'A': {'x': 1},
'C': {'x': 2},
},
'col': {
'1': {'y': 1},
},
}
assert wells_from_config(config) == {
(0,0): {'x': 1, 'y': 1},
(1,0): { 'y': 1},
(2,0): {'x': 2, 'y': 1},
}

def test_multiple_cols():
config = {
'row': {
Expand All @@ -300,6 +315,21 @@ def test_multiple_cols():
(0,1): {'x': 1, 'y': 2},
}

config = {
'row': {
'A': {'x': 1},
},
'col': {
'1': {'y': 1},
'3': {'y': 2},
},
}
assert wells_from_config(config) == {
(0,0): {'x': 1, 'y': 1},
(0,1): {'x': 1 },
(0,2): {'x': 1, 'y': 2},
}

def test_row_range():
config = {
'row': {
Expand All @@ -311,6 +341,7 @@ def test_row_range():
}
assert wells_from_config(config) == {
(0,0): {'x': 1, 'y': 1},
(1,0): { 'y': 1},
(2,0): {'x': 1, 'y': 1},
}

Expand Down Expand Up @@ -339,6 +370,7 @@ def test_col_range():
}
assert wells_from_config(config) == {
(0,0): {'x': 1, 'y': 1},
(0,1): {'x': 1 },
(0,2): {'x': 1, 'y': 1},
}

Expand Down Expand Up @@ -377,6 +409,22 @@ def test_row_without_col():
(0,0): {'x': 1, 'y': 1},
}

config = {
'block': {
'2x2': {
'A1': {'y': 1},
},
},
'row': {
'A': {'x': 1},
},
}
assert wells_from_config(config) == {
(0,0): {'x': 1, 'y': 1},
(0,1): {'x': 1, 'y': 1},
(1,0): { 'y': 1},
(1,1): { 'y': 1},
}

def test_col_without_row():
config = {
Expand All @@ -399,7 +447,24 @@ def test_col_without_row():
(0,0): {'x': 1, 'y': 1},
}

def test_interleaved_row():
config = {
'block': {
'2x2': {
'A1': {'x': 1},
},
},
'col': {
'1': {'y': 1},
},
}
assert wells_from_config(config) == {
(0,0): {'x': 1, 'y': 1},
(0,1): {'x': 1, },
(1,0): {'x': 1, 'y': 1},
(1,1): {'x': 1, },
}

def test_one_irow():
config = {
'irow': {
'A': {'x': 1},
Expand All @@ -413,8 +478,12 @@ def test_interleaved_row():
}
assert wells_from_config(config) == {
(0,0): {'x': 1, 'y': 1},
(1,1): {'x': 1, 'y': 2},
(0,1): { 'y': 2},
(0,2): {'x': 1, 'y': 3},
(0,3): { 'y': 4},
(1,0): { 'y': 1},
(1,1): {'x': 1, 'y': 2},
(1,2): { 'y': 3},
(1,3): {'x': 1, 'y': 4},
}

Expand All @@ -430,13 +499,17 @@ def test_interleaved_row():
},
}
assert wells_from_config(config) == {
(1,0): {'x': 2, 'y': 1},
(0,0): { 'y': 1},
(0,1): {'x': 2, 'y': 2},
(1,2): {'x': 2, 'y': 3},
(0,2): { 'y': 3},
(0,3): {'x': 2, 'y': 4},
(1,0): {'x': 2, 'y': 1},
(1,1): { 'y': 2},
(1,2): {'x': 2, 'y': 3},
(1,3): { 'y': 4},
}

def test_interleaved_col():
def test_one_icol():
config = {
'row': {
'A': {'x': 1},
Expand All @@ -450,8 +523,12 @@ def test_interleaved_col():
}
assert wells_from_config(config) == {
(0,0): {'x': 1, 'y': 1},
(0,1): {'x': 1 },
(1,0): {'x': 2 },
(1,1): {'x': 2, 'y': 1},
(2,0): {'x': 3, 'y': 1},
(2,1): {'x': 3 },
(3,0): {'x': 4 },
(3,1): {'x': 4, 'y': 1},
}

Expand All @@ -467,10 +544,14 @@ def test_interleaved_col():
},
}
assert wells_from_config(config) == {
(0,0): {'x': 1 },
(0,1): {'x': 1, 'y': 2},
(1,0): {'x': 2, 'y': 2},
(1,1): {'x': 2 },
(2,0): {'x': 3 },
(2,1): {'x': 3, 'y': 2},
(3,0): {'x': 4, 'y': 2},
(3,1): {'x': 4 },
}

def test_irow_without_col():
Expand All @@ -482,6 +563,80 @@ def test_irow_without_col():
with raises(ConfigError, match="irow"):
wells_from_config(config)

config = {
'well': {
'A1': {'y': 1},
},
'irow': {
'A': {'x': 1},
},
}
assert wells_from_config(config) == {
(0,0): {'x': 1, 'y': 1},
}

config = {
'block': {
'2x1': {
'A1': {'y': 1},
},
},
'irow': {
'A': {'x': 1},
},
}
assert wells_from_config(config) == {
(0,0): {'x': 1, 'y': 1},
(0,1): { 'y': 1},
(1,1): {'x': 1 },
}

config = {
'block': {
'2x1': {
'A1': {'y': 1},
},
},
'irow': {
'B': {'x': 2},
},
}
assert wells_from_config(config) == {
(0,0): { 'y': 1},
(0,1): {'x': 2, 'y': 1},
(1,0): {'x': 2 },
}

config = {
'block': {
'1x2': {
'A1': {'y': 1},
},
},
'irow': {
'A': {'x': 1},
},
}
assert wells_from_config(config) == {
(0,0): {'x': 1, 'y': 1},
(1,0): { 'y': 1},
}

config = {
'block': {
'1x2': {
'A1': {'y': 1},
},
},
'irow': {
'B': {'x': 2},
},
}
assert wells_from_config(config) == {
(0,0): { 'y': 1},
(1,0): {'x': 2, 'y': 1},
}

def test_icol_without_row():
config = {
'icol': {
Expand All @@ -491,6 +646,80 @@ def test_icol_without_row():
with raises(ConfigError, match="icol"):
wells_from_config(config)

config = {
'well': {
'A1': {'x': 1},
},
'icol': {
'1': {'y': 1},
},
}
assert wells_from_config(config) == {
(0,0): {'x': 1, 'y': 1},
}

config = {
'block': {
'1x2': {
'A1': {'x': 1},
},
},
'icol': {
'1': {'y': 1},
},
}
assert wells_from_config(config) == {
(0,0): {'x': 1, 'y': 1},
(1,0): {'x': 1, },
(1,1): { 'y': 1},
}

config = {
'block': {
'1x2': {
'A1': {'x': 1},
},
},
'icol': {
'2': {'y': 2},
},
}
assert wells_from_config(config) == {
(0,0): {'x': 1 },
(0,1): { 'y': 2},
(1,0): {'x': 1, 'y': 2},
}

config = {
'block': {
'2x1': {
'A1': {'x': 1},
},
},
'icol': {
'1': {'y': 1},
},
}
assert wells_from_config(config) == {
(0,0): {'x': 1, 'y': 1},
(0,1): {'x': 1, },
}

config = {
'block': {
'2x1': {
'A1': {'x': 1},
},
},
'icol': {
'2': {'y': 2},
},
}
assert wells_from_config(config) == {
(0,0): {'x': 1 },
(0,1): {'x': 1, 'y': 2},
}

def test_top_level_params():
config = {
'expt': {'x': 1},
Expand Down Expand Up @@ -571,8 +800,6 @@ def test_block_precedence():
(1, 0): {'p': '1x2'},
}



def test_multi_letter_well():
config = {
'well': {
Expand Down

0 comments on commit 2bd2cdc

Please sign in to comment.