Skip to content

Fix dim lengths created from coords or ConstantData #5751

@michaelosthege

Description

@michaelosthege
Member

In this comment we proposed to make dimensions created from coords non-resizeable, because it would prevent users from running into issues like #5181.

What needs to be done

In

pymc/pymc/model.py

Lines 1070 to 1076 in dd23c90

def add_coord(
self,
name: str,
values: Optional[Sequence] = None,
*,
length: Optional[Variable] = None,
):
the set_coord method could take another kwarg resizable: bool=False or fixed: bool=True.

Then we can actively turn off re-sizing of dimensions that are created from ConstantData or coords.

Activity

added this to the v4.0.0 milestone on May 6, 2022
ricardoV94

ricardoV94 commented on May 6, 2022

@ricardoV94
Member

Let's remember to add #5181 as a test

LukeLB

LukeLB commented on May 13, 2022

@LukeLB
Contributor

Hi guys just been looking at how this can be implemented. Can I check my understanding first... So this line:

self._dim_lengths[name] = length or aesara.shared(len(values))

Is causing the problem due to the aesara.shared(len(values)) being resizeable. So the sugestion here is to create a new kwarg which we can use in an if statement, something like:

if fixed:
    self._dim_lengths[name] = length or aesara.tensor.constant(len(values))
else: 
    self._dim_lengths[name] = length or aesara.shared(len(values))
michaelosthege

michaelosthege commented on May 13, 2022

@michaelosthege
MemberAuthor

@LukeLB yes, that's the idea

canyon289

canyon289 commented on May 13, 2022

@canyon289
Member

@LukeLB Did you want to take a shot at fixing this, and if so when were you planning on doing so? I ask as this is holding up the Bambi migration to V4 so we want to get fixed soon here!

LukeLB

LukeLB commented on May 14, 2022

@LukeLB
Contributor

@canyon289 I've got time today so I'll have a crack at it.

canyon289

canyon289 commented on May 14, 2022

@canyon289
Member

Sounds great! Looking forward to the PR and thank you. Let us know if you need any help.

LukeLB

LukeLB commented on May 14, 2022

@LukeLB
Contributor

@canyon289 just put in a WIP-PR as I'm heading out and was having some problems with locally failing tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      Participants

      @michaelosthege@canyon289@ricardoV94@LukeLB

      Issue actions

        Fix dim lengths created from `coords` or `ConstantData` · Issue #5751 · pymc-devs/pymc