RasmussenLab / MOVE

MOVE (Multi-Omics Variational autoEncoder) for integrating multi-omics data and identifying cross modal associations
https://move-dl.readthedocs.io/
MIT License
63 stars 25 forks source link

defining entrypoints #14

Closed enryH closed 1 year ago

enryH commented 2 years ago

I tried out of curiosity to define an entrypoint in setup.cfg, and I ran in an error regarding the uncommon module naming convention

[options.entry_points]
console_scripts =
    move-encode-data = move.01_encode_data.__main__:main
move-encode-data --help
Traceback (most recent call last):
  File "C:\Users\enryh\anaconda3\envs\move\lib\runpy.py", line 189, in _run_module_as_main
    mod_name, mod_spec, code = _get_main_module_details(_Error)
  File "C:\Users\enryh\anaconda3\envs\move\lib\runpy.py", line 223, in _get_main_module_details
    return _get_module_details(main_name)
  File "C:\Users\enryh\anaconda3\envs\move\lib\runpy.py", line 129, in _get_module_details
    spec = importlib.util.find_spec(mod_name)
  File "C:\Users\enryh\anaconda3\envs\move\lib\importlib\util.py", line 103, in find_spec
    return _find_spec(fullname, parent_path)
  File "<frozen importlib._bootstrap>", line 945, in _find_spec
  File "<frozen importlib._bootstrap_external>", line 1439, in find_spec
  File "<frozen importlib._bootstrap_external>", line 1411, in _get_spec
  File "<frozen zipimport>", line 170, in find_spec
  File "<frozen importlib._bootstrap>", line 431, in spec_from_loader
  File "<frozen importlib._bootstrap_external>", line 741, in spec_from_file_location
  File "<frozen zipimport>", line 229, in get_filename
  File "<frozen zipimport>", line 760, in _get_module_code
  File "<frozen zipimport>", line 689, in _compile_source
  File "C:\Users\enryh\anaconda3\envs\move\Scripts\move-encode-data.exe\__main__.py", line 4
    from move.01_encode_data import main
                ^
SyntaxError: invalid decimal literal

Changing the module name from 01_encode_data to encode_data (and changing setup.cfg accordingly, solves the problem

>>> move-encode-data --help
C:\Users\enrhy\Documents\repos\MOVE\src\move\encode_data\__main__.py:6: UserWarning: 
The version_base parameter is not specified.
Please specify a compatability version level, or None.
Will assume defaults for version 1.1
  @hydra.main(config_path="../conf", config_name="main")
__main__ is powered by Hydra.

== Configuration groups ==
Compose your configuration from those groups (group=option)

data: main
model: vae
training: main
training_association: main
training_latent: main
tuning_reconstruction: main
tuning_stability: main

== Config ==
Override anything in the config (foo.bar=value)

name: MOVE
seed: 123456
data:
  user_config: data.yaml
  na_value: NA
  raw_data_path: data/
  interim_data_path: interim_data/
  processed_data_path: processed_data/
  headers_path: headers/
  version: v1
  ids_file_name: baseline_ids.txt
  ids_has_header: true
  ids_colname: 0
  categorical_inputs:
  - name: diabetes_genotypes
    weight: 1
  - name: baseline_drugs
    weight: 1
  - name: baseline_categorical
    weight: 1
  continuous_inputs:
  - name: baseline_continuous
    weight: 2
  - name: baseline_transcriptomics
    weight: 1
  - name: baseline_diet_wearables
    weight: 1
  - name: baseline_proteomic_antibodies
    weight: 1
  - name: baseline_target_metabolomics
    weight: 1
  - name: baseline_untarget_metabolomics
    weight: 1
  - name: baseline_metagenomics
    weight: 1
  data_of_interest: baseline_drugs
  categorical_names: ${names:${data.categorical_inputs}}
  continuous_names: ${names:${data.continuous_inputs}}
  categorical_weights: ${weights:${data.categorical_inputs}}
  continuous_weights: ${weights:${data.continuous_inputs}}
  data_features_to_visualize_notebook4:
  - drug_1
  - clinical_continuous_2
  - clinical_continuous_3
  write_omics_results_notebook5:
  - baseline_target_metabolomics
  - baseline_untarget_metabolomics
model:
  _target_: move.models.vae.VAE
  user_config: model.yaml
  seed: 1
  cuda: false
  lrate: 0.0001
  num_epochs: 500
  patience: 100
  kld_steps:
  - 20
  - 30
  - 40
  - 90
  batch_steps:
  - 50
  - 100
  - 150
  - 200
  - 250
  - 300
  - 350
  - 400
  - 450
tuning_reconstruction:
  user_config: tuning_reconstruction.yaml
  num_hidden:
  - 500
  - 1000
  num_latent:
  - 20
  - 50
  num_layers:
  - 1
  - 2
  dropout:
  - 0.1
  - 0.2
  beta:
  - 1.0e-05
  - 0.0001
  batch_sizes:
  - 10
  repeats: 1
  max_param_combos_to_save: 12
tuning_stability:
  user_config: tuning_stability.yaml
  num_hidden:
  - 500
  - 1000
  num_latent:
  - 20
  - 50
  num_layers:
  - 1
  dropout:
  - 0.1
  - 0.2
  beta:
  - 1.0e-05
  batch_sizes:
  - 10
  repeats: 5
  tuned_num_epochs: 250
training_latent:
  user_config: training_latent.yaml
  num_hidden: 500
  num_latent: 20
  num_layers: 1
  dropout: 0.1
  beta: 1.0e-05
  batch_sizes: 10
  tuned_num_epochs: 250
training_association:
  user_config: training_association.yaml
  num_hidden: 500
  num_latent:
  - 150
  - 200
  - 250
  - 300
  num_layers: 1
  dropout: 0.1
  beta: 1.0e-05
  batch_sizes: 10
  repeats: 10
  tuned_num_epochs: 250

Powered by Hydra (https://hydra.cc)
Use --hydra-help to view Hydra specific help
enryH commented 2 years ago
[options.entry_points]
console_scripts =
    move-dl=move.__main__:main
    move-dl-encode-data=move.encode_data.__main__:main

if I name the target move I somehow get an error, I don't get: The system cannot find the file specified. (so if move=move.__main__:main it somehow has errors...)

enryH commented 2 years ago

I added the example on entrypoints: https://github.com/RasmussenLab/MOVE/commit/b9e7c2d1dbfbcfa18804bd46ae1523a2848af1af

ri-heme commented 2 years ago

What do you mean by sub-commands here?

enryH commented 2 years ago

What e.g. git or conda have:

move --help # help move
move encode --help # move command with subcommand encode
simonrasmu commented 2 years ago

Alternatively, what about adding a keyword that specifies what to do?

move mode=encode
move mode=optimize_reconstruction
move mode=optimize_stability
move mode=analyze_latent
move mode=get_associations
ri-heme commented 1 year ago

@enryH:

if I name the target move I somehow get an error, I don't get: The system cannot find the file specified. (so if move=move.__main__:main it somehow has errors...)

It's a Windows-specific problem. The issue is that move is an internal Windows command (similar to mv in Unix), and setuptools cannot override it.

A different name has to be used then, so I will stick with move-dl for now.

enryH commented 1 year ago

🤯 nice that this is solved!

simonrasmu commented 1 year ago

I think using move-dl is fine, it is then also consistent with the pip package