BUG: setting a declared eccentricity back to None leaves the old distribution in place

Đang mở Phù hợp với người mới
#1,171 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 3 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
74/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Ít trao đổi
Công nghệ
python
Lĩnh vực
backend

Hướng nghiên cứu

Bắt đầu với StochasticModel._declare_stochastic_input và _reconfigure_stochastic_input được thêm trong #1169; kiểm tra cách dict_generator sử dụng các khai báo ngẫu nhiên. Thêm kiểm thử cho trường hợp bỏ qua y và xóa một x đã được cấu hình trước đó bằng None. Hoàn tất khi các đầu vào bị bỏ qua vẫn không được khai báo và các đầu vào đã xóa không xuất hiện trở lại sau khi đặt lại seed.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

What happens

add_cp_eccentricity and add_thrust_eccentricity accept None to mean an input is not randomized, and their docstrings document x and y as optional. Passing None after a distribution was configured does not remove the earlier one, so the next reseed brings it back.

stochastic = StochasticRocket(rocket=calisto, radius=0.0127 / 2)

stochastic.add_cp_eccentricity(x=0.001)
stochastic.add_cp_eccentricity(x=None)

stochastic._set_stochastic(7)

On develop at 7822ab1d:

after the None call, still declared:      True
after the reseed, the attribute:          (0, 0.001, Generator.normal)
in the generated dict:                    True

The caller asked for the uncertainty to go away and it is still being drawn.

Why

StochasticModel._declare_stochastic_input returns early on None rather than removing the entry:

if input_value is None:
    return
self.__stochastic_dict[input_name] = input_value

dict_generator walks __stochastic_dict, so the stale declaration reaches the draw. The early return is right for the case it was written for, which is add_cp_eccentricity(x=0.001) with no y, where None means "was never given" rather than "take it away". The two meanings are not distinguished.

Fix

Removing the entry instead of returning early covers the second meaning, and leaves the first alone as long as removal only happens for a name that is being configured. #1169 adds _reconfigure_stochastic_input, which already owns the replacement half of this, so the removal fits there in about a line.

Worth a test for each meaning: add_cp_eccentricity(x=0.001) with no y must not declare y, and add_cp_eccentricity(x=None) after x=0.001 must remove x.

Where it came from

The behaviour arrived with #1167, which declared these inputs so a fixed seed could reproduce them. Reconfiguration was not part of that change. Raised separately rather than folded into #1169, which fixes the other half of the same lifecycle and is under review.

Ngôn ngữ chính
Python
Star
1.1k
Fork
280
Merge trung bình
3 ngày 2 giờ
Pull request đã merge (30 ngày)
24

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của RocketPy-Team/RocketPy

Tất cả issue của RocketPy-Team/RocketPy

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.