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

Aberta Para iniciantes
#1,171 1 comentário 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 3 dias

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
2/5
Tempo estimado
1-3 horas
Facilidade para iniciantes
74/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Pouca atividade
Stack de tecnologia
python
Domínio
backend

Direção de pesquisa

Comece por StochasticModel._declare_stochastic_input e por _reconfigure_stochastic_input, adicionado em #1169; inspecione como dict_generator usa as declarações estocásticas. Adicione testes para um y omitido e para limpar com None um x configurado anteriormente. O trabalho estará concluído quando as entradas omitidas permanecerem não declaradas e as entradas limpas não voltarem após a redefinição da semente.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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.

Linguagem predominante
Python
Estrelas
1.1k
Forks
280
Merge médio
3d 2h
PRs com merge (30d)
24

Preparar o ambiente

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de RocketPy-Team/RocketPy

Todas as issues de RocketPy-Team/RocketPy

Issues semelhantes

Mais issues de Python

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.