Skip to content
This repository has been archived by the owner on Dec 10, 2020. It is now read-only.

Unwanted imports #34

Closed
donjan opened this issue Sep 17, 2018 · 4 comments
Closed

Unwanted imports #34

donjan opened this issue Sep 17, 2018 · 4 comments
Assignees

Comments

@donjan
Copy link
Collaborator

donjan commented Sep 17, 2018

  • QMT is currently importing QMS, which should not occur. (qmt/tasks/ms/mesh.py, qmt/data/scalar_data.py, qmt/geometry/freecad/run.py)
    These should be QMT dummies.

  • fenics is getting imported in the global namespace of some files, which makes it a dependency for QMT. (qmt/data/scalar_data.py, qmt/data/geo_data.py)
    We probably want to push it down to function level imports, and remove where possible.

  • the unit tests are failing due to fenics not being installed in Travis. Either remove fenics imports or add it as a dependency.

@johnkgamble
Copy link
Contributor

OK, this should be fixed as of the latest commit - can you check?

@donjan
Copy link
Collaborator Author

donjan commented Sep 18, 2018

Can't test the specific issue due to things not working generally.
Using the first section of an example sent by Spencer last week:

from qmt.tasks import Task, SweepManager

class HelloWorldTask(Task):
    def __init__(self):
        super().__init__()
    def _solve_instance(self, inputs, options):
        print("Hello World")

hi = HelloWorldTask()
em = SweepManager.create_empty_sweep()
print(hi.run_daskless())

If I try to run it as-is:

$ python3 foo.py
Traceback (most recent call last):
  File "foo.py", line 15, in <module>
    print(hi.run_daskless())
  File "/home/donjan/ETH/PhD/code/qmt/qmt/tasks/task.py", line 298, in run_daskless
    self.daskless_result = self.__class__._solve_instance(input_result_list, self.options)
TypeError: _solve_instance() missing 1 required positional argument: 'options'

Removing the self, part from _solve_instance yields:

$ python3 foo.py
Hello World
None

Now using dask:

from qmt.tasks import Task, SweepManager

class HelloWorldTask(Task):
    def __init__(self):
        super().__init__()
    def _solve_instance(inputs, options):
        print("Hello World")

hi = HelloWorldTask()
em = SweepManager.create_empty_sweep()
print(em.run(hi))

Gives:

$ python3 foo.py
Traceback (most recent call last):
  File "foo.py", line 14, in <module>
    print(em.run(hi))
  File "/home/donjan/ETH/PhD/code/qmt/qmt/tasks/sweep.py", line 92, in run
    return task._run()
  File "/home/donjan/ETH/PhD/code/qmt/qmt/tasks/task.py", line 258, in _run
    self.computed_result = self.delayed_result.calculate_futures(resources=self.resources)
  File "/home/donjan/ETH/PhD/code/qmt/qmt/tasks/sweep.py", line 237, in calculate_futures
    futures.append(self.dask_client.compute(delayed_result, resources=resources))
AttributeError: 'NoneType' object has no attribute 'compute'

Can you confirm that these snippets work for you?

@johnkgamble
Copy link
Contributor

Ah, I managed to break some stuff yesterday :) . It's fixed now. Yes, you should no longer use "self" in the _solve_instance methods, as they are static now to make it easier for Dask to work with them. Give it a try now; your snippet above now works for me.

@donjan
Copy link
Collaborator Author

donjan commented Sep 19, 2018

Looks good now, everything works in Python3.
One QMS import left in qmt/geometry/freecad/run.py, but I assume this is a conscious decision to keep the region mapping code in QMS.

I've added @staticmethod to the _solve_instance of Task derivatives currently in QMT, in accordance to the base class. (Python3 miraculously doesn't complain)

@donjan donjan closed this as completed Sep 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants