Skip to content

Segmentation fault in MtEnv._apply_action when using scipy.special.expit #54

@darkrams98

Description

@darkrams98

Description
When running MtEnv.step(...) with the default import of expit from scipy.special, even a zero-action array (all logits = 0) causes a hard Python crash (segfault) inside _apply_action. Replacing scipy.special.expit with a pure-NumPy implementation fixes the crash.

Create a fresh conda environment with:

conda create -n test_py39 python=3.9 numpy scipy gymnasium
pip install gym-mtsim

Prepare a minimal script debug_segfault.py:

`# debug_segfault.py
import faulthandler
faulthandler.enable(all_threads=True)

import numpy as np
from gym_mtsim import MtEnv, MtSimulator

Configure your simulator (use any valid symbols_filename)

sim = MtSimulator(
unit='USD',
balance=10000.,
leverage=1000.,
stop_out_level=0.2,
hedge=True,
symbols_filename='symbols_forex.pkl'
)

env = MtEnv(
original_simulator=sim,
trading_symbols=['EURUSD'], # or your symbol
window_size=10,
multiprocessing_processes=0
)

env.reset()

This line always segfaults if using scipy.special.expit:

env.step(np.zeros(env.action_space.shape))
`

Fatal Python error: Segmentation fault Current thread ... File ".../mt_env.py", line 146, in _apply_action Segmentation fault (core dumped)

Replacing the import in mt_env.py:

  • from scipy.special import expit
  • import numpy as np
  • def expit(x):
  • return 1.0 / (1.0 + np.exp(-x))
    

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions