Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
117 commits
Select commit Hold shift + click to select a range
a0922c6
Added Singleton design patter for non-parametric, non-controlled gates
Mayank447 Feb 15, 2026
48092e0
Make validate_control, validate_params as staticmethod, corrected some
Mayank447 Feb 15, 2026
be354e7
Moved certain abstract properties as class attribute in Gate class
Mayank447 Feb 15, 2026
cee446d
Deprecated gates.py
Mayank447 Feb 15, 2026
0d45d1d
Added __slots__ for optimization
Mayank447 Feb 15, 2026
da8da90
Added namespace to Gates
Mayank447 Feb 15, 2026
6ee5ca4
Resolved errors in qpe, vqa based on namespace
Mayank447 Feb 15, 2026
21f571a
Made Gate class not instantiable by default
Mayank447 Feb 20, 2026
4e52dd6
Add an additional test for qiskit backend
Mayank447 Feb 20, 2026
ab79f34
Added gate equivalence checking
Mayank447 Feb 21, 2026
1d64f8f
Renamed custom_gate, controlled_gate factory functions
Mayank447 Feb 21, 2026
e074634
separated controlled and parametric gate into their own files
Mayank447 Feb 21, 2026
bffbae9
run black
Mayank447 Feb 22, 2026
4f24efb
Removed get_qobj() static method from std controlled gates
Mayank447 Feb 22, 2026
a4594cf
Corrected a bug in controlled_gate for beyond two qubit controlled gates
Mayank447 Feb 22, 2026
1b0437b
Added some other standard gates
Mayank447 Feb 22, 2026
c645026
Added inverse for single qubit gates
Mayank447 Feb 22, 2026
7279957
Added tests for gate inverse of single qubit gate
Mayank447 Feb 23, 2026
46b7f12
Added gate inverse and tests for non-controlled two qubit gates
Mayank447 Feb 23, 2026
535cb8b
Added checks for unitary_gate method
Mayank447 Feb 23, 2026
06d8ca4
Use qutip_qip.operations.std import for std gates import
Mayank447 Feb 23, 2026
2fdde02
Added inverse method for controlled gates
Mayank447 Feb 23, 2026
8f20aeb
Minor change to argument ordering for ControlledGate
Mayank447 Feb 23, 2026
fd4214c
Added inverse gate test for TOFFOLI, FREDKIN
Mayank447 Feb 23, 2026
e9aa797
Corrected __setattr__ for Gate metaclass
Mayank447 Feb 23, 2026
f5aa421
Rename is_controlled_gate method to is_controlled
Mayank447 Feb 23, 2026
b31f5f4
Rename is_parametric_gate method to is_parametric
Mayank447 Feb 23, 2026
81c12d5
Fix dagger symbol in latex_str for gates
Mayank447 Feb 23, 2026
d28cd8d
Added further checks in add_gate
Mayank447 Feb 25, 2026
853a2c4
Renamed gates.py to old_gates.py
Mayank447 Feb 25, 2026
51978c5
Removed deprecated variables from expand_operator
Mayank447 Feb 25, 2026
470f58c
Removed deprecation for Gate, Measurement from circuit/ module
Mayank447 Feb 25, 2026
c7821d0
Remove precompute_unitary argument from CircuitSimulator
Mayank447 Feb 25, 2026
6d82f78
Rename inverse() method for Gate to inverse_gate()
Mayank447 Feb 25, 2026
e070a78
Add typehints to operations/utils.py
Mayank447 Feb 25, 2026
ff26e56
Minor changes
Mayank447 Feb 25, 2026
3bb9f7f
Corrected some latex_str for std gates
Mayank447 Feb 27, 2026
c5903a2
Added ctrl_value to ControlledGate class
Mayank447 Feb 28, 2026
cc54686
Remove mutable default values from function arguments
Mayank447 Feb 28, 2026
64bb346
Added slots=True to dataclasses
Mayank447 Feb 28, 2026
d1d15db
Add a ControlledParam Gate temporarily
Mayank447 Feb 28, 2026
348032e
Remove standard gates from operations
Mayank447 Feb 28, 2026
82a79ce
Made some of the std gates as ControllledParamGate
Mayank447 Feb 28, 2026
db68bc1
Made ControlledGate non-initialisable
Mayank447 Feb 28, 2026
b19272a
Added Dynamic Descriptors, Delegation to ControlledGate
Mayank447 Feb 28, 2026
5130d25
Deleted ControlledParamGate
Mayank447 Feb 28, 2026
77bc5eb
Resolved failing inverse gate tests
Mayank447 Feb 28, 2026
a0019dd
Corrected Metaclass for Gates
Mayank447 Feb 28, 2026
10a351c
Move hadamard_transform to utils
Mayank447 Mar 1, 2026
096573d
Replaced inverse_gate with inverse in Gate class
Mayank447 Mar 1, 2026
bebc64b
Add static method get_qobj, cache
Mayank447 Mar 1, 2026
9b6f022
Renamed std to gates
Mayank447 Mar 1, 2026
b54d6c2
Added __eq__, __hash__ to GateMetaclasses
Mayank447 Mar 1, 2026
c4fb138
Added caching single qubit parametrized gates
Mayank447 Mar 1, 2026
91e025b
Added caching for two qubit parametrized gates
Mayank447 Mar 1, 2026
6433f67
Added proper typehints for all standard gates
Mayank447 Mar 1, 2026
dc702df
Removed arg_value from ParametricGate
Mayank447 Mar 2, 2026
e84da96
Made the remaining tests pass based on removal of arg_value
Mayank447 Mar 2, 2026
ca8734c
Added a utils.py for helper functions
Mayank447 Mar 2, 2026
0d7af5d
Corrected several isInstance in the codebase
Mayank447 Mar 2, 2026
5026db4
Add setter method for arg_value
Mayank447 Mar 2, 2026
97540f3
Added expanded option in inverse method fort Parametric Gates
Mayank447 Mar 2, 2026
46b4f9b
Corrected typhinting for tuple[]
Mayank447 Mar 2, 2026
7b4cb9a
Add __hash__ method for Parametric Gates
Mayank447 Mar 2, 2026
a6f5d18
Added __eq__, __hash__ for Controlled Gates
Mayank447 Mar 2, 2026
11a889c
Remove __hash__ from Controlled, Parametric Gate as they are mutable
Mayank447 Mar 2, 2026
41e65d5
Made _compute_qobj() abstract in Parametric Gate
Mayank447 Mar 3, 2026
7f050a1
Renamed unitary_gate method to get_unitary_gate
Mayank447 Mar 3, 2026
ca44070
replace gate.name comparisions with actual gate comparision
Mayank447 Mar 3, 2026
4d63b1f
Added checks for input for add_gate method
Mayank447 Mar 3, 2026
242d5fb
Corrected inconsistency bt Gate and Type[Gate]
Mayank447 Mar 3, 2026
b14ed06
Added new standard gates to the colour theme
Mayank447 Mar 3, 2026
efa30db
Added new gates to qiskit converter
Mayank447 Mar 3, 2026
b7449ba
Added new standard gates to the docs
Mayank447 Mar 3, 2026
c40284d
Separated namespace from gates as a broader concept
Mayank447 Mar 4, 2026
e87100d
Added a NameSpaceRegistry functionality
Mayank447 Mar 4, 2026
7ee0f63
Use NameSpaceRegistry in Gate Meta class
Mayank447 Mar 4, 2026
b8889c0
Change the NameSpace dataclass
Mayank447 Mar 4, 2026
c37ac57
Replace .format with f-strings
Mayank447 Mar 4, 2026
5f2e5c8
Correct typing and added circuit.utils method to utils.py
Mayank447 Mar 4, 2026
03a483d
Corrected some minor typehinting as per Python 3.10 standards
Mayank447 Mar 4, 2026
67c2595
Added _namespace to all the standard gates and gate factory functions
Mayank447 Mar 4, 2026
d6814c1
NameSpace functionality working
Mayank447 Mar 4, 2026
b74497b
Move pytest.ini to root dir, make namespace a set
Mayank447 Mar 4, 2026
b1cbdaa
Minor fixes to tests, ControlledGate.inverse method
Mayank447 Mar 4, 2026
a3a1674
Fix the namespace mechanism
Mayank447 Mar 7, 2026
b90f53b
Corrected inverse method for controlled, parametrized gates
Mayank447 Mar 7, 2026
d7ab53a
Added a controlled gate registry mechanism
Mayank447 Mar 7, 2026
ad7782d
Add additional checks on Gate subclasses
Mayank447 Mar 7, 2026
880bc22
Corrected __hash__, __eq__ for Gate meta class
Mayank447 Mar 8, 2026
4dcd70e
Minor fix to inverse in ControlledGate
Mayank447 Mar 8, 2026
1a8f3d3
Minor remaining fixes
Mayank447 Mar 8, 2026
1cf0cf5
Fix bug in gate_product, move its logic to operations
Mayank447 Mar 8, 2026
d63d2db
Added test gates for which gates must raise an Error
Mayank447 Mar 8, 2026
f718e9c
Added more checks to __init_subclass__ in Gate class
Mayank447 Mar 8, 2026
fb80ef6
Added more tests for gates
Mayank447 Mar 8, 2026
15f8250
Add argument dtype to get_qobj() method
Mayank447 Mar 8, 2026
fd848b8
Added the functionality to remove elements from a namespace
Mayank447 Mar 8, 2026
100234d
Add checks on is_controlled, is_parametric method
Mayank447 Mar 9, 2026
403d656
Minor code ordering change in add_gate method
Mayank447 Mar 9, 2026
c5ca576
Add test for add_gate method in test_circuit.py
Mayank447 Mar 9, 2026
93dcaa0
Rename controlled to get_controlled_gate
Mayank447 Mar 10, 2026
45ebe81
Fix __hash__
Mayank447 Mar 10, 2026
6b10f95
Removed redundant CNOT in the codebase
Mayank447 Mar 10, 2026
43ec959
Correct several isinstances
Mayank447 Mar 10, 2026
3f4cd43
Minor fixes as per recommendation
Mayank447 Mar 10, 2026
25bd01a
Added more comments, docstring for gateclass
Mayank447 Mar 10, 2026
8b78eac
Minor Fixes to gate class design
Mayank447 Mar 10, 2026
c495ea2
Added gate.name in pulse compiler with gate_class
Mayank447 Mar 10, 2026
03c9f69
Added CSdag, CTdag gates
Mayank447 Mar 11, 2026
db49f47
Removed expanded from inverse() in Parametric Gates
Mayank447 Mar 11, 2026
6f0b7cf
Add inverse for standard controlled parametric gates
Mayank447 Mar 11, 2026
aae676a
Remove expanded from Parametric Gates
Mayank447 Mar 11, 2026
dd2b5ea
run black
Mayank447 Mar 11, 2026
4378e1f
Added a default inverse method for non-parametrized gates
Mayank447 Mar 11, 2026
0b1cd2f
Separated Identity and IDLE gate
Mayank447 Mar 11, 2026
5c7ac64
Add docstrings for namespace
Mayank447 Mar 11, 2026
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
6 changes: 3 additions & 3 deletions doc/pulse-paper/qft.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ def get_control_latex(model):
num_qubits = model.num_qubits
num_coupling = model._get_num_coupling()
return [
{f"sx{m}": r"$\sigma_x^{}$".format(m) for m in range(num_qubits)},
{f"sz{m}": r"$\sigma_z^{}$".format(m) for m in range(num_qubits)},
{f"g{m}": r"$g_{}$".format(m) for m in range(num_coupling)},
{f"sx{m}": rf"$\sigma_x^{m}$" for m in range(num_qubits)},
{f"sz{m}": rf"$\sigma_z^{m}$" for m in range(num_qubits)},
{f"g{m}": rf"$g_{m}$" for m in range(num_coupling)},
]


Expand Down
2 changes: 1 addition & 1 deletion doc/source/apidoc/qutip_qip.operations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ qutip\_qip.operations

.. autosummary::

controlled_gate
controlled_gate_unitary
expand_operator
gate_sequence_product
45 changes: 29 additions & 16 deletions doc/source/qip-basics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -139,38 +139,51 @@ The pre-defined gates for the class :class:`~.operations.Gate` are shown in the
==================== ========================================
Gate name Description
==================== ========================================
"RX" Rotation around x axis
"RY" Rotation around y axis
"RZ" Rotation around z axis
"R" Arbitrary single qubit rotation
"X" Pauli-X gate
"Y" Pauli-Y gate
"Z" Pauli-Z gate
"H" Hadamard gate
"S" Single-qubit rotation or Z90
"Sdag" Inverse of S gate
"T" Square root of S gate
"Tdag" Inverse of T gate
"SQRTX" Square root of X gate
"H" Hadamard gate
"PHASEGATE" Add a phase one the state 1
"CRX" Controlled rotation around x axis
"CRY" Controlled rotation around y axis
"CRZ" Controlled rotation around z axis
"CX" Controlled X gate (also called CNOT)
"SQRTXdag" Inverse of SQRTX gate
"RX" Rotation around x axis
"RY" Rotation around y axis
"RZ" Rotation around z axis
"PHASE" Adds a relative phase to ket 1
"R" Arbitrary single qubit rotation
"QASMU" U rotation gate used as a primitive in the QASM standard
"CX" (CNOT) Controlled X gate
"CY" Controlled Y gate
"CZ" Controlled Z gate
"CH" Controlled H gate
"CS" Controlled S gate
"CSdag" Controlled Sdag gate
"CT" Controlled T gate
"CPHASE" Controlled phase gate
"QASMU" U rotation gate used as a primitive in the QASM standard
"BERKELEY" Berkeley gate
"SWAPalpha" SWAPalpha gate
"CTdag" Controlled Tdag gate
"CRX" Controlled rotation around x axis
"CRY" Controlled rotation around y axis
"CRZ" Controlled rotation around z axis
"CPHASE" Controlled Phase gate
"CQASMU" Controlled QASMU gate
"SWAP" Swap the states of two qubits
"ISWAP" Swap gate with additional phase for 01 and 10 states
"ISWAPdag" Inverse of ISWAP gate
"SQRTSWAP" Square root of the SWAP gate
"SQRTSWAPdag" Inverse of SQRTSWAP gate
"SQRTISWAP" Square root of the ISWAP gate
"SQRTISWAPdag" Inverse of SQRTISWAP gate
"BERKELEY" Berkeley gate
"BERKELEYdag" Inverse of BERKELEY gate
"SWAPALPHA" SWAPALPHA gate
"MS" Mølmer-Sørensen gate
"RZX" RZX gate
"TOFFOLI" (CCX) Toffoli gate
"FREDKIN" Fredkin gate
"TOFFOLI" Toffoli gate
"GLOBALPHASE" Global phase
"GLOBALPHASE" Global phase gate
"IDENTITY" Identity gate
==================== ========================================

For some of the gates listed above, :class:`.QubitCircuit` also has a primitive :func:`.QubitCircuit.resolve_gates()` method that decomposes them into elementary gate sets such as CX or SWAP with single-qubit gates (RX, RY and RZ). However, this method is not fully optimized. It is very likely that the depth of the circuit can be further reduced by merging quantum gates. It is required that the gate resolution be carried out before the measurements to the circuit are added.
Expand Down
11 changes: 4 additions & 7 deletions tests/pytest.ini → pytest.ini
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
[pytest]
markers =
slow: Mark a test as taking a long time to run, and so can be skipped with `pytest -m "not slow"`.
repeat(n): Repeat the given test 'n' times.
requires_cython: Mark that the given test requires Cython to be installed. Such tests will be skipped if Cython is not available.

filterwarnings =
error
; ImportWarning: PyxImporter.find_spec() not found
ignore:PyxImporter:ImportWarning
; DeprecationWarning: Please use `upcast` from the `scipy.sparse` namespace
ignore::DeprecationWarning:qutip.fastsparse*:
ignore::UserWarning:
ignore:matplotlib not found:UserWarning
ignore:the imp module is deprecated in favour of importlib:DeprecationWarning
ignore:Dedicated options class are no longer needed, options should be passed as dict to solvers.:FutureWarning
ignore::DeprecationWarning:qiskit.utils.algorithm_globals:
# Deprecation warning for python = 3.9 with matplotlib 3.9.4
ignore:'mode' parameter is deprecated
# Deprecation warning for scipy disp interface, will be removed in scipy 1.18
ignore:.*`disp` and `iprint` options.*L-BFGS-B.*deprecated.*:DeprecationWarning



pythonpath = src
testpaths = tests
2 changes: 1 addition & 1 deletion src/qutip_qip/algorithms/bit_flip.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from qutip_qip.circuit import QubitCircuit
from qutip_qip.operations import CX, TOFFOLI, X
from qutip_qip.operations.gates import CX, TOFFOLI, X


class BitFlipCode:
Expand Down
2 changes: 1 addition & 1 deletion src/qutip_qip/algorithms/phase_flip.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from qutip_qip.circuit import QubitCircuit
from qutip_qip.operations import CX, H
from qutip_qip.operations.gates import CX, H


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

import numpy as np
from qutip_qip.operations import H, RZ, CX, CPHASE, SWAP, expand_operator
from qutip_qip.circuit import QubitCircuit
from qutip import Qobj
from qutip_qip.circuit import QubitCircuit
from qutip_qip.decompose import decompose_one_qubit_gate
from qutip_qip.operations import expand_operator
from qutip_qip.operations.gates import H, RZ, CX, CPHASE, SWAP


def qft(N=1):
Expand Down Expand Up @@ -66,7 +67,7 @@ def qft_steps(N=1, swapping=True):
for j in range(i):
U_step_list.append(
expand_operator(
CPHASE(np.pi / (2 ** (i - j))).get_qobj(),
CPHASE(theta=np.pi / (2 ** (i - j))).get_qobj(),
dims=[2] * N,
targets=[i, j],
)
Expand Down Expand Up @@ -113,7 +114,10 @@ def qft_gate_sequence(N=1, swapping=True, to_cnot=False):
for j in range(i):
if not to_cnot:
qc.add_gate(
CPHASE(np.pi / (2 ** (i - j)), arg_label=r"{\pi/2^{%d}}" % (i - j)),
CPHASE(
theta=np.pi / (2 ** (i - j)),
arg_label=r"{\pi/2^{%d}}" % (i - j),
),
targets=[j],
controls=[i],
)
Expand All @@ -136,6 +140,6 @@ def _cphase_to_cnot(targets, controls, arg_value, qc: QubitCircuit):
qc.add_gate(decomposed_gates[4], targets=targets)
qc.add_gate(CX, targets=targets, controls=controls)
qc.add_gate(RZ(arg_value / 2), targets=controls)
gate = decomposed_gates[7]
gate.arg_value[0] += arg_value / 4
gate = decomposed_gates[7] # This is a GLOBALPHASE Gate
gate.arg_value = gate.arg_value[0] + arg_value / 4
qc.add_gate(gate, targets=targets)
15 changes: 8 additions & 7 deletions src/qutip_qip/algorithms/qpe.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import numpy as np
from qutip_qip.circuit import QubitCircuit
from qutip_qip.algorithms import qft_gate_sequence
from qutip_qip.operations import custom_gate_factory, controlled_gate_factory, H
from qutip_qip.circuit import QubitCircuit
from qutip_qip.operations import get_unitary_gate, get_controlled_gate
from qutip_qip.operations.gates import H


def qpe(U, num_counting_qubits, target_qubits=None, to_cnot=False):
Expand Down Expand Up @@ -41,7 +42,7 @@ def qpe(U, num_counting_qubits, target_qubits=None, to_cnot=False):
target_qubits = list(
range(num_counting_qubits, num_counting_qubits + num_target_qubits)
)
elif isinstance(target_qubits, int):
elif type(target_qubits) is int:
target_qubits = [target_qubits]
num_target_qubits = 1
else:
Expand All @@ -61,11 +62,11 @@ def qpe(U, num_counting_qubits, target_qubits=None, to_cnot=False):
U_power = U if power == 1 else U**power

# Add controlled-U^power gate
controlled_u = controlled_gate_factory(
gate=custom_gate_factory(
gate_name="U^power gate",
controlled_u = get_controlled_gate(
gate=get_unitary_gate(
gate_name=f"U^{power}",
U=U_power,
)(),
),
)
qc.add_gate(controlled_u, targets=target_qubits, controls=[i])

Expand Down
28 changes: 0 additions & 28 deletions src/qutip_qip/circuit/__init__.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,12 @@
"""Circuit representation and simulation at the gate level."""

import warnings

from .instruction import (
CircuitInstruction,
GateInstruction,
MeasurementInstruction,
)
from .simulator import CircuitResult, CircuitSimulator
from .circuit import QubitCircuit
from qutip_qip.operations import Gate, Measurement


def _add_deprecation(fun, msg):
def newfun(*args, **kwargs):
warnings.warn(
msg,
DeprecationWarning,
stacklevel=2,
)
return fun(*args, **kwargs)

return newfun


Gate = _add_deprecation(
Gate,
"The class Gate has been moved to qutip_qip.operations."
"Please use update the import statement.\n",
)
Measurement = _add_deprecation(
Measurement,
"The class Measurement has been moved to qutip_qip.operations."
"Please use update the import statement.\n",
)


__all__ = [
"CircuitSimulator",
Expand Down
Loading
Loading