Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7893363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:06:51+00:00 2026-06-03T07:06:51+00:00

I want to parallelize a function using IPython.parallel, and when I define it in

  • 0

I want to parallelize a function using IPython.parallel, and when I define it
in the IPython shell it works flawlessly:

Type:       function
Base Class: <type 'function'>
String Form:<function gradient at 0x3ae0398>
Namespace:  Interactive
File:       /root/<ipython-input-30-cf7eabdfef84>
Definition: gradient(w) 
Source:
def gradient(w):
    s = (1.0 + exp(y * (X * w)))**-1
    return C*X.T*((1 - s) * y)

rc = Client() 
rc[:].apply_sync(gradient, w)
...

However, when I define it in a module and use import:

Type:       function
Base Class: <type 'function'>
String Form:<function gradient at 0x3933d70>
Namespace:  Interactive
File:       /root/mv.py
Definition: mv.gradient(w)
Source:
def gradient(w):
    s = (1.0 + exp(y * (X * w)))**-1
    return C*X.T*((1 - s) * y)

import mv 
rc = Client()
rc[:].apply_sync(mv.gradient, w)

CompositeError: one or more exceptions from call to method: gradient
[0:apply]: NameError: global name 'y' is not defined
[1:apply]: NameError: global name 'y' is not define

Furthermore, it works fine one my local system running Python 2.7.2/IPython 0.12, while
it crashes on Python 2.7.2+/IPython 0.12 using the newest Starcluster Ubuntu AMI.

What is going on here?

UPDATE: I installed the IPython 0.13.dev version from github and now it works.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T07:06:52+00:00Added an answer on June 3, 2026 at 7:06 am

    The difference is module globals. When a function is defined in a module, the global namespace is that of the module (i.e. mv.y). When that module is __main__, e.g. an interactively defined function, then the global namespace is your user_ns on the Engine, and is affected by execute("y=5").

    IPython provides a decorator, if you want to define functions in modules that should behave as if they are interactively defined (have access to the user namespace as globals):

    # mymod
    
    from IPython.parallel.util import interactive
    
    @interactive
    def by_a(b):
        """multiply a by b"
        return a*b
    

    And interactively, you can do:

    from mymod import by_a
    
    e0 = rc[0]
    e0.execute("a=5")
    print e0.apply_sync(by_a, 10) # 50
    e0.execute("a=10")
    print e0.apply_sync(by_a, 10) # 100
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

want to know why String behaves like value type while using ==. String s1
I want to parallelize a loop in a class member function. However there are
Following to this post , I want parallelize this method : public IEnumerable<string> GetAllLogs(IEnumerable<IComputer>
I want to use MPI to parallelize a function that is being called multiple
I've got a for loop I want to parallelize with something like PLINQ's Parallel.ForEach().
I have a function that I eventually want to parallelize. Currently, I call things
I have the following nested for loops. I want to parallelize the first loop
I create a QFuture that I want to use to parallelize calls to a
Want the function to sort the table by HP but if duplicate HPs then
I want to parallelize some file-parsing actions with network activity in powershell. Quick google

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.