Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speedup import: disable ipython magic by default #3764

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/changes/newsfragments/3764.breaking
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
IPython measurement magic (Special command staring with % for use in IPython) using the legacy
loop is no longer enabled by default.
To enable it set the corresponding config value (`core.register_magic`) in your ``qcodesrc.json`` config file to true.
14 changes: 9 additions & 5 deletions qcodes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,17 @@
from qcodes.utils import validators

try:
# Check if we are in iPython
get_ipython() # type: ignore[name-defined]
from qcodes.utils.magic import register_magic_class
_register_magic = config.core.get('register_magic', False)
if _register_magic is not False:
register_magic_class(magic_commands=_register_magic)
except NameError:
from IPython import get_ipython

# Check if we are in IPython
ip = get_ipython()
if ip is not None:
from qcodes.utils.magic import register_magic_class

register_magic_class(magic_commands=_register_magic)
except ImportError:
pass
except RuntimeError as e:
print(e)
Expand Down
2 changes: 1 addition & 1 deletion qcodes/configuration/qcodesrc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"core":{
"default_fmt": "data/{date}/#{counter}_{name}_{time}",
"register_magic": true,
"register_magic": false,
"import_legacy_api": false,
"db_location": "~/experiments.db",
"db_debug": false,
Expand Down
2 changes: 1 addition & 1 deletion qcodes/configuration/qcodesrc_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
{"type": "boolean"},
{"type": "array"}
],
"default": true
"default": false
jenshnielsen marked this conversation as resolved.
Show resolved Hide resolved
},
"import_legacy_api" : {
"description": "Import the legacy api in main qcodes namespace",
Expand Down
6 changes: 4 additions & 2 deletions qcodes/utils/magic.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from IPython.core.magic import Magics, magics_class, line_cell_magic
from IPython import get_ipython
from IPython.core.magic import Magics, line_cell_magic, magics_class


@magics_class
class QCoDeSMagic(Magics):
Expand Down Expand Up @@ -153,7 +155,7 @@ def register_magic_class(cls=QCoDeSMagic, magic_commands=True):

ip = get_ipython()
if ip is None:
raise RuntimeError('No iPython shell found')
raise RuntimeError("No IPython shell found")
else:
if magic_commands is not True:
# filter out any magic commands that are not in magic_commands
Expand Down