lefnire / tforce_btc_trader

TensorForce Bitcoin Trading Bot
http://ocdevel.com/podcasts/machine-learning/26
GNU Affero General Public License v3.0
820 stars 235 forks source link

AttributeError: 'NoneType' object has no attribute 'run' #18

Closed blueboy09 closed 6 years ago

blueboy09 commented 6 years ago

I just run the "python hypersearch.py" directly and get the following error. Actually, I find that "self.monitored_session.run" have repeated many times and finally it got a None. I am not familiar with tensorforce and do not know what happened. Any help is appreciated.


Traceback (most recent call last):
  File "hypersearch.py", line 772, in <module>
    main()
  File "hypersearch.py", line 768, in main
    y_list=Y
  File "/home/RL/tforce_btc_trader/gp.py", line 193, in bayesian_optimisation2
    y_list.append(loss_fn(params))
  File "hypersearch.py", line 719, in loss_fn
    reward = hsearch.execute(vec2hypers(params))
  File "hypersearch.py", line 547, in execute
    env.train_and_test(agent, self.cli_args.n_steps, self.cli_args.n_tests, -1)
  File "/home/RL/tforce_btc_trader/btc_env.py", line 487, in train_and_test
    self.run_deterministic(runner, print_results=True)
  File "/home/RL/tforce_btc_trader/btc_env.py", line 471, in run_deterministic
    runner.agent.act(next_state, deterministic=False)
  File "/home/anaconda3/lib/python3.6/site-packages/tensorforce/agents/agent.py", line 145, in act
    deterministic=deterministic
  File "/home/anaconda3/lib/python3.6/site-packages/tensorforce/models/model.py", line 1268, in act

    actions, internals, timestep = self.monitored_session.run(fetches=fetches, feed_dict=feed_dict)
  File "/home/anaconda3/lib/python3.6/site-packages/tensorflow/python/training/monitored_session.py", line 536, in run
    return self._sess.run(fetches,
AttributeError: 'NoneType' object has no attribute 'run'
TalhaAsmal commented 6 years ago

Hi,

Lets do some debugging:

  1. What version of python are you running?
  2. Did you import the data as stated in the readme?
  3. What version of tensorflow are you using?
  4. Approximately how long does it take for the error to occur, and what hardware are you using?
blueboy09 commented 6 years ago

@TalhaAsmal Thanks a lot!

  1. Python 3.6.3 :: Anaconda custom (64-bit)
  2. Yes. I have done the first two steps (Setup and Populate Data). There is no error.
  3. Tensorflow: 1.5.0 (gpu), CUDA 9.0

4.1 Basic system information: Ubuntu 16.04.3 LTS, Intel(R) Xeon(R) CPU E5-2660 v3 @ 2.60GHz, GPU: TITAN Xp 4.2 It happens about 7 minutes after I start the program when it calls the function "train_and_test" (in hypersearch.py) and calls function "self.run_deterministic(runner, print_results=True)" (in btc_env) at the first time.

It seems that a possible reason is "next_start" in "runner.agent.act(next_state, deterministic=True)" is not right. It outputs as follows. But I do not know what the correct form is.

{'series': array([[[ 0.00000000e+00,  0.00000000e+00,  0.00000000e+00, ...,
          0.00000000e+00,  0.00000000e+00,  0.00000000e+00]],

       [[ 0.00000000e+00,  0.00000000e+00,  0.00000000e+00, ...,
          0.00000000e+00,  0.00000000e+00,  0.00000000e+00]],

       [[ 0.00000000e+00,  0.00000000e+00,  0.00000000e+00, ...,
          0.00000000e+00,  0.00000000e+00,  0.00000000e+00]],
       ...,

       [[ 0.00000000e+00,  0.00000000e+00,  0.00000000e+00, ...,
          0.00000000e+00,  0.00000000e+00, -3.19445158e-08]],

       [[ 0.00000000e+00,  0.00000000e+00,  0.00000000e+00, ...,
          0.00000000e+00,  0.00000000e+00, -2.96627647e-08]],

       [[ 0.00000000e+00,  0.00000000e+00,  0.00000000e+00, ...,
          0.00000000e+00,  0.00000000e+00, -2.75439958e-08]]]), 'stationary': [0.3, 0.3, 0.0]}
blueboy09 commented 6 years ago

@TalhaAsmal I forgot to mention one thing. I made a small modification. Actually, if I directly run "python hypersearch.py", it has "connection is closed" error. It seems that the self.conn closed in the process because of some unknown reason. I modify line 269 in btc_env as follows.

271            conn = data.engine.connect()
272            try:
273                self.row_ct = data.count_rows(conn, arbitrage=self.hypers.arbitrage)
274            except:
275                import traceback
276                print(traceback.extract_stack())
277            finally:
278                conn.close()
hkfreenet commented 6 years ago

@blueboy09 I am facing the same issue as the connection is closed. i am doing the same things to make the engine connect again, then the "AttributeError: 'NoneType' object has no attribute 'run'" is coming out.

How to fix this problem?

TalhaAsmal commented 6 years ago

@hkfreenet @blueboy09 Please have a look at issue #10 . I experienced the 'connection is closed' issue as well, and it was resolved with an update to tensorforce. There was no need to change the code in any way.

blueboy09 commented 6 years ago

@TalhaAsmal Thanks a lot! It works. Actually, the current master of tensorforce also changed a lot and does not work. It would be better to specify the committed version (e.g., f1c49de3) of tensorforce in requirement.txt.