Skip to content
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
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2011 to 2021 inclusive, QuTiP developers and contributors.
Copyright (c) 2011 to 2025 inclusive, QuTiP developers and contributors.
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
3 changes: 1 addition & 2 deletions doc/pulse-paper/main_example.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import numpy as np
from qutip import basis
from qutip_qip.circuit import QubitCircuit
from qutip_qip.device import LinearSpinChain, SpinChainModel, Processor, ModelProcessor
from qutip_qip.compiler import SpinChainCompiler
from qutip_qip.device import LinearSpinChain, SpinChainModel, Processor
from qutip_qip.noise import RelaxationNoise
qc = QubitCircuit(3)
qc.add_gate("X", targets=2)
Expand Down
3 changes: 1 addition & 2 deletions doc/pulse-paper/qft.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
TEXTWIDTH = 5.93
LINEWIDTH = 3.22
import matplotlib as mpl
import matplotlib.pyplot as plt
try:
from quantum_plots import global_setup
Expand All @@ -11,7 +10,7 @@


import numpy as np
from qutip import basis, fidelity, Options
from qutip import basis, fidelity
from qutip_qip.device import LinearSpinChain
from qutip_qip.algorithms import qft_gate_sequence

Expand Down
6 changes: 3 additions & 3 deletions src/qutip_qip/algorithms/qft.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"""

import numpy as np
from ..operations import Gate, snot, cphase, swap, expand_operator
from ..circuit import QubitCircuit
from qutip_qip.operations import Gate, snot, cphase, swap, expand_operator
from qutip_qip.circuit import QubitCircuit
from qutip import Qobj
from ..decompose import decompose_one_qubit_gate
from qutip_qip.decompose import decompose_one_qubit_gate


__all__ = ["qft", "qft_steps", "qft_gate_sequence"]
Expand Down
1 change: 0 additions & 1 deletion src/qutip_qip/algorithms/qpe.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import numpy as np
from qutip import Qobj
from qutip_qip.operations import Gate, ControlledGate
from qutip_qip.circuit import QubitCircuit
from qutip_qip.algorithms import qft_gate_sequence
Expand Down
13 changes: 10 additions & 3 deletions src/qutip_qip/circuit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import warnings

from .circuit import *
from .circuitsimulator import *
from ..operations import Gate, Measurement
from .circuitsimulator import CircuitResult, CircuitSimulator
from .circuit import QubitCircuit
from qutip_qip.operations import Gate, Measurement


Comment on lines -5 to 9
Copy link
Member

@BoxiLi BoxiLi Dec 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think for the __init__.py files, it is fine to use the star importation. We already defined __all__.py in all the .py files. This simplifies the development. Otherwise one have to always rember to update __init__.py when a new function is added.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And is there a reason that relative import is kept here but removed elsewhere? I don't have strong preference but it should be consistent.

Copy link
Contributor Author

@Mayank447 Mayank447 Dec 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Python by defining __all__ in __init__.py, one is explicitly stating: "These are the tools intended for public use. Anything else you find in the submodules is internal logic and might change without warning." There were many cases of internal functions (starting with _) being exported through __all__ in .py file which generally is not a good practice

__all__ in .py file is better, if we want to define the import at a file level instead of module level.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally relative imports are only kept at module level ( in __init__.py). Relative imports from parent are strongly discouraged for large packages because refactor breaks a lot of things. One keeps the relative imports in __init__ only because some people map a package directory to a different name in pyproject.toml

Copy link
Contributor Author

@Mayank447 Mayank447 Dec 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reference you can check: https://github.com/Qiskit/qiskit/blob/main/qiskit/quantum_info/__init__.py

Not defining __all__ in __init__.py inherently means everything imported In __init__.py will be exported when does from package import *

def _add_deprecation(fun, msg):
Expand All @@ -29,3 +29,10 @@ def newfun(*args, **kwargs):
"The class Measurement has been moved to qutip_qip.operations."
"Please use update the import statement.\n",
)


__all__ = [
"CircuitSimulator",
"CircuitResult",
"QubitCircuit",
]
Comment on lines +32 to +38
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

2 changes: 1 addition & 1 deletion src/qutip_qip/circuit/_decompose.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"""

import numpy as np
from ..operations import Gate
from qutip_qip.operations import Gate


__all__ = ["_resolve_to_universal", "_resolve_2q_basis"]
Expand Down
11 changes: 2 additions & 9 deletions src/qutip_qip/circuit/circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,19 @@

import inspect
from collections.abc import Iterable
from math import pi

import numpy as np
from copy import deepcopy

from .texrenderer import TeXRenderer
from ._decompose import _resolve_to_universal, _resolve_2q_basis
from ..operations import (
from qutip_qip.operations import (
Gate,
Measurement,
expand_operator,
GATE_CLASS_MAP,
)
from .circuitsimulator import (
from qutip_qip.circuit import (
CircuitSimulator,
CircuitResult,
)
Expand All @@ -36,12 +35,6 @@ def DisplaySVG(data, *args, **kwargs):
return data


__all__ = [
"QubitCircuit",
"CircuitResult",
]


class QubitCircuit:
"""
Representation of a quantum program/algorithm, maintaining a sequence
Expand Down
7 changes: 2 additions & 5 deletions src/qutip_qip/circuit/circuitsimulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,15 @@
from functools import reduce
import numpy as np

from ..operations import (
from qutip_qip.operations import (
Gate,
Measurement,
expand_operator,
)
from qutip import basis, ket2dm, Qobj, tensor
from qutip import ket2dm, Qobj, tensor
import warnings


__all__ = ["CircuitSimulator", "CircuitResult"]


def _flatten(lst):
"""
Helper to flatten lists.
Expand Down
7 changes: 3 additions & 4 deletions src/qutip_qip/circuit/mat_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
Module for rendering a quantum circuit using matplotlib library.
"""

from typing import Union, Optional, List, Dict
from dataclasses import dataclass
from typing import Union

import numpy as np
import matplotlib.pyplot as plt
Expand All @@ -16,8 +15,8 @@
)

from .base_renderer import BaseRenderer, StyleConfig
from ..operations import Gate, Measurement
from ..circuit import QubitCircuit
from qutip_qip.operations import Gate, Measurement
from qutip_qip.circuit import QubitCircuit

__all__ = [
"MatRenderer",
Expand Down
3 changes: 1 addition & 2 deletions src/qutip_qip/circuit/texrenderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
import shutil
import tempfile
import warnings
import functools
import subprocess
import collections

from ..operations import Gate
from qutip_qip.operations import Gate

__all__ = ["TeXRenderer", "CONVERTERS"]

Expand Down
4 changes: 2 additions & 2 deletions src/qutip_qip/circuit/text_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from typing import List

from .base_renderer import BaseRenderer, StyleConfig
from ..operations import Gate, Measurement
from . import QubitCircuit
from qutip_qip.operations import Gate, Measurement
from qutip_qip.circuit import QubitCircuit

__all__ = [
"TextRenderer",
Expand Down
12 changes: 11 additions & 1 deletion src/qutip_qip/compiler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@
from .instruction import Instruction
from .scheduler import Scheduler
from .gatecompiler import GateCompiler
from .cavityqedcompiler import CavityQEDCompiler
from .spinchaincompiler import SpinChainCompiler
from .cavityqedcompiler import CavityQEDCompiler
from .circuitqedcompiler import SCQubitsCompiler


__all__ = [
"Instruction",
"Scheduler",
"GateCompiler",
"SpinChainCompiler",
"CavityQEDCompiler",
"SCQubitsCompiler",
]
10 changes: 2 additions & 8 deletions src/qutip_qip/compiler/cavityqedcompiler.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
from functools import partial
import numpy as np
import scipy

from ..circuit import QubitCircuit
from ..operations import Gate
from ..compiler import GateCompiler, Instruction


__all__ = ["CavityQEDCompiler"]
from qutip_qip.operations import Gate
from qutip_qip.compiler import GateCompiler, Instruction


class CavityQEDCompiler(GateCompiler):
Expand Down
7 changes: 2 additions & 5 deletions src/qutip_qip/compiler/circuitqedcompiler.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import numpy as np

from ..operations import Gate
from ..compiler import GateCompiler, Instruction


__all__ = ["SCQubitsCompiler"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is __all__ removed here?

I think typically we do in qutip family package is to keep this in all .py files. Not __init__.py. Unless there is some advantages?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This applies to many other files.

from qutip_qip.operations import Gate
from qutip_qip.compiler import GateCompiler, Instruction


class SCQubitsCompiler(GateCompiler):
Expand Down
10 changes: 3 additions & 7 deletions src/qutip_qip/compiler/gatecompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@
import numpy as np
from scipy import signal

from .instruction import Instruction
from .scheduler import Scheduler
from ..circuit import QubitCircuit
from ..operations import Gate


__all__ = ["GateCompiler"]
from qutip_qip.compiler import Instruction
from qutip_qip.compiler import Scheduler
from qutip_qip.circuit import QubitCircuit


class GateCompiler(object):
Expand Down
3 changes: 0 additions & 3 deletions src/qutip_qip/compiler/instruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
import numpy as np


__all__ = ["Instruction"]


class Instruction:
"""
Representation of pulses that implement a quantum gate.
Expand Down
7 changes: 3 additions & 4 deletions src/qutip_qip/compiler/scheduler.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from collections import deque
from copy import deepcopy
from functools import cmp_to_key
from random import shuffle

from ..circuit import QubitCircuit
from ..operations import Gate
from .instruction import Instruction
from qutip_qip.circuit import QubitCircuit
from qutip_qip.operations import Gate
from qutip_qip.compiler import Instruction


class InstructionsGraph:
Expand Down
8 changes: 1 addition & 7 deletions src/qutip_qip/compiler/spinchaincompiler.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
from functools import partial
import numpy as np

from ..circuit import QubitCircuit
from ..operations import Gate
from ..compiler import GateCompiler, Instruction


__all__ = ["SpinChainCompiler"]
from qutip_qip.compiler import GateCompiler, Instruction


class SpinChainCompiler(GateCompiler):
Expand Down
6 changes: 5 additions & 1 deletion src/qutip_qip/decompose/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""Unitary decomposition. (experimental)"""

from .decompose_single_qubit_gate import *
from .decompose_single_qubit_gate import decompose_one_qubit_gate

__all__ = [
"decompose_one_qubit_gate",
]
3 changes: 0 additions & 3 deletions src/qutip_qip/decompose/decompose_single_qubit_gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
from qutip_qip.operations import Gate


__all__ = ["decompose_one_qubit_gate"]


def _angles_for_ZYZ(input_gate):
"""Finds and returns the angles for ZYZ rotation matrix. These are
used to change ZYZ to other combinations.
Expand Down
19 changes: 17 additions & 2 deletions src/qutip_qip/device/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,28 @@
Simulation of quantum hardware.
"""

from .processor import Processor, Model
from .model import Model
from .processor import Processor
from .modelprocessor import ModelProcessor
from .spinchain import (
LinearSpinChain,
CircularSpinChain,
SpinChainModel,
)
from .cavityqed import DispersiveCavityQED, CavityQEDModel
from .optpulseprocessor import OptPulseProcessor
from .circuitqed import SCQubits, SCQubitsModel
from .optpulseprocessor import OptPulseProcessor

__all__ = [
"DispersiveCavityQED",
"CavityQEDModel",
"SCQubits",
"SCQubitsModel",
"Model",
"ModelProcessor",
"Processor",
"LinearSpinChain",
"CircularSpinChain",
"SpinChainModel",
"OptPulseProcessor",
]
17 changes: 5 additions & 12 deletions src/qutip_qip/device/cavityqed.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import warnings
from copy import deepcopy

import warnings
import numpy as np

from qutip import (
Expand All @@ -11,17 +10,11 @@
sigmaz,
basis,
Qobj,
QobjEvo,
)
from ..circuit import QubitCircuit
from ..operations import Gate
from .processor import Processor, Model
from .modelprocessor import ModelProcessor, _to_array
from ..pulse import Pulse
from ..compiler import GateCompiler, CavityQEDCompiler


__all__ = ["DispersiveCavityQED"]
from qutip_qip.device import Model
from qutip_qip.device import ModelProcessor
from qutip_qip.compiler import CavityQEDCompiler
from qutip_qip.device.utils import _to_array


class DispersiveCavityQED(ModelProcessor):
Expand Down
15 changes: 5 additions & 10 deletions src/qutip_qip/device/circuitqed.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
from copy import deepcopy

import numpy as np

from qutip import qeye, tensor, destroy, basis
from .processor import Model
from .modelprocessor import ModelProcessor, _to_array
from ..transpiler import to_chain_structure
from ..compiler import SCQubitsCompiler
from ..noise import ZZCrossTalk
from ..operations import expand_operator


__all__ = ["SCQubits"]
from qutip_qip.device import Model, ModelProcessor
from qutip_qip.transpiler import to_chain_structure
from qutip_qip.compiler import SCQubitsCompiler
from qutip_qip.noise import ZZCrossTalk
from qutip_qip.device.utils import _to_array


class SCQubits(ModelProcessor):
Expand Down
Loading