Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ZarrTrace and fix non-determinism with Generators in sample #7540

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Prev Previous commit
Next Next commit
Handle missing attributes with default field values in DataClassState
  • Loading branch information
lucianopaz committed Dec 23, 2024
commit 2913e4a84438a00775403de421b3fb689c89e8c0
2 changes: 1 addition & 1 deletion pymc/step_methods/hmc/quadpotential.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ def current_mean(self, out=None):
class QuadPotentialDiagAdaptExpState(QuadPotentialDiagAdaptState):
_alpha: float
_stop_adaptation: float
_variance_estimator: ExpWeightedVarianceState
_variance_estimator: ExpWeightedVarianceState | None = None

_variance_estimator_grad: ExpWeightedVarianceState | None = None

Expand Down
8 changes: 6 additions & 2 deletions pymc/step_methods/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from copy import deepcopy
from dataclasses import Field, dataclass, fields
from dataclasses import MISSING, Field, dataclass, fields
from typing import Any, ClassVar

import numpy as np
Expand Down Expand Up @@ -67,7 +67,11 @@ def sampling_state(self) -> DataClassState:
state_class = self._state_class
kwargs = {}
for field in fields(state_class):
val = getattr(self, field.name)
val = getattr(self, field.name, field.default)
if val is MISSING:
raise AttributeError(
f"{type(self).__name__!r} object has no attribute {field.name!r}"
)
_val: Any
if isinstance(val, WithSamplingState):
_val = val.sampling_state
Expand Down