nke001 / causal_learning_unknown_interventions

Code for "Neural causal learning from unknown interventions"
98 stars 18 forks source link

AttributeError: module 'causal' has no attribute '_causal' #1

Closed ronikobrosly closed 2 years ago

ronikobrosly commented 2 years ago

Hello @nke001 , I'm thrilled you put together this package and I just finished reading the corresponding paper. I seem to have a problem running this in my python 3.9.6 virtual environment. I'm able to install all of the requirements, but when I run the command python run.py train --seed 1 --train_functional 10000 --mopt adam:5e-2,0.9 --gopt adam:5e-3,0.1 -v 500 --lsparse 0.1 --bs 256 --ldag 0.5 --predict 100 --temperature 1 --limit-samples 500 -N 2 -p confounder3 as listed in your README, I get the following error:

[2021-09-19 11:55:03.091 EDT ~~ INFO    ] *****************************************
[2021-09-19 11:55:03.091 EDT ~~ INFO    ] Command:             run.py train --seed 1 --train_functional 10000 --mopt adam:5e-2,0.9 --gopt adam:5e-3,0.1 -v 500 --lsparse 0.1 --bs 256 --ldag 0.5 --predict 100 --temperature 1 --limit-samples 500 -N 2 -p confounder3
[2021-09-19 11:55:03.092 EDT ~~ INFO    ] CWD:                 /Users/roni_kobrosly/Desktop/causal_learning_unknown_interventions
[2021-09-19 11:55:03.092 EDT ~~ INFO    ] Experiment Name:     1-cat-200-256-10-10000-100-None-None-3-2-2-20-10-100-10-1.0-1.0-1.0-['{0-2}->{0-2}']-[]-Namespace(lr=0.05, beta1=0.9, beta2=0.999, eps=1e-08, name='adam')-Namespace(lr=0.005, beta1=0.1, beta2=0.999, eps=1e-08, name='adam')-0.0-[Namespace(lr=0.1, name='const')]-0.5-0-500-0
[2021-09-19 11:55:03.092 EDT ~~ INFO    ] Experiment UUID:     M3_N2_T1.0_predict100_BS256_seed1_lsparse[Namespace(lr=0.1, name='const')]__UUID-8fa3a767-0f7c-5922-eb09-ffcd53838ac4
[2021-09-19 11:55:03.092 EDT ~~ INFO    ] Experiment Work Dir: /Users/roni_kobrosly/Desktop/causal_learning_unknown_interventions/work/CausalOptimization-40037046-a359-470b-b327-af9bbef3e532/by-uuid/M3_N2_T1.0_predict100_BS256_seed1_lsparse[Namespace(lr=0.1, name='const')]__UUID-8fa3a767-0f7c-5922-eb09-ffcd53838ac4
[2021-09-19 11:55:03.092 EDT ~~ INFO    ] 
[2021-09-19 11:55:03.092 EDT ~~ INFO    ] 
Traceback (most recent call last):
  File "/Users/roni_kobrosly/Desktop/causal_learning_unknown_interventions/run.py", line 206, in <module>
    sys.exit(main(sys.argv))
  File "/Users/roni_kobrosly/Desktop/causal_learning_unknown_interventions/run.py", line 202, in main
    return a.__cls__.run(a)
  File "/Users/roni_kobrosly/Desktop/causal_learning_unknown_interventions/run.py", line 174, in run
    return Experiment(a).rollback().run().exitcode
  File "/Users/roni_kobrosly/Desktop/Nauka/src/nauka/exp/experiment.py", line 155, in rollback
    else:                  return self.fromScratch()
  File "/Users/roni_kobrosly/Desktop/causal_learning_unknown_interventions/causal/experiment.py", line 206, in fromScratch
    self.reseed(password="Seed: {} Init".format(self.a.seed))
  File "/Users/roni_kobrosly/Desktop/causal_learning_unknown_interventions/causal/experiment.py", line 65, in reseed
    causal._causal.seed(nauka.utils.pbkdf2int(64, password))
AttributeError: module 'causal' has no attribute '_causal'

So it seems I'm not able to read the _causal.c file in the package. I imagine this is because it's written in C. Could you help me understand what I'm doing wrong here?

obilaniu commented 2 years ago

@ronikobrosly I am the author of the C chunk.

1) It must be compiled, a step carried out by setup.py. I suspect you may not have done pip install -e .. 2) It very heavily uses AVX2 and FMA vector extensions, available only on CPUs Intel Haswell/AMD Excavator and newer. A runtime CPU detection code rejects loading the module on CPUs that are too old. I don't see the warning it prints in your error message, so I really suspect you're still at problem 1), but I may be mistaken.

ronikobrosly commented 2 years ago

Thank you for the heads up @obilaniu ! I will try this later today and report back here.

ronikobrosly commented 2 years ago

Hi @obilaniu , unfortunately that did not seem to work. I ran both pip install -e . and python setup.py develop. When I run python run.py train --seed 1 --train_functional 10000 --mopt adam:5e-2,0.9 --gopt adam:5e-3,0.1 -v 500 --lsparse 0.1 --bs 256 --ldag 0.5 --predict 100 --temperature 1 --limit-samples 500 -N 2 -p confounder3 I still get AttributeError: module 'causal' has no attribute '_causal'.

Do you have any more ideas?

obilaniu commented 2 years ago

@ronikobrosly Well, I'll guess based on your paths that you're on macOS.

I never developed for that platform specifically, and because Apple does things differently I had to disable my CPU check for too-old compilers. My vector code will also 100% not work on very new M1 chips because they're not x86_64 architecture but Aarch64.

Assuming you're still on one of the Intel-based Macs, I propose you remove the try-except from around the import here and say what error message it gives, and furthermore check whether there is a newly-compiled library causal/_causal*.{so|dylib} (or something like that). If there is not, I'd suggest you try pip install -v -e . to see more verbosely what's going on.

I would not be surprised to learn that it failed to compile (x86_64 code will not compile on Aarch64), or fails to import with a failing CPU check (x86_64 CPU is too old).

ronikobrosly commented 2 years ago

Ahhh, welp you basically guessed it, Im using a new Macbook Pro with the M1 chip. Oh well, thanks for your help though!