Skip to content

Commit

Permalink
comment issue resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
raunakkumarsingh committed Aug 4, 2024
1 parent fa9dc09 commit 58df6d2
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 244 deletions.
12 changes: 6 additions & 6 deletions qdao/circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ class BasePartitioner:
Base class for circuit partitioning.
Attributes:
np (int): Number of partitions.
nl (int): Number of layers.
np (int): Number of primary qubits.
nl (int): Number of local qubits.
backend (str): The backend used for the partitioning process.
"""

Expand All @@ -68,22 +68,22 @@ def __init__(self, np=4, nl=2, backend="qiskit") -> None:

@property
def np(self):
"""Gets the number of partitions."""
"""Gets the number of primary qubits."""
return self._np

@np.setter
def np(self, n):
"""Sets the number of partitions."""
"""Sets the number of primary qubits."""
self._np = n

@property
def nl(self):
"""Sets the number of layers."""
"""Sets the number of local qubits."""
return self._nl

@nl.setter
def nl(self, n):
"""Sets the number of layers."""
"""Sets the number of local qubits."""
self._nl = n

def run(self, circuit: Any) -> List[QdaoCircuit]:
Expand Down
4 changes: 2 additions & 2 deletions qdao/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class ConstantPoolParallelExecutor:
"""
Executes a function in parallel using a constant-sized thread pool.
When the number of qubits (NQ) is much larger than the number of layers (NL),
When the number of qubits (NQ) is much larger than the number of local qubits (NL),
there will be excessive overhead. This class tries to run a thread pool group
by group with each group of CPU_COUNT size.
"""
Expand Down Expand Up @@ -154,7 +154,7 @@ class AsyncIoExecutor:
"""
Executes a function in parallel using asyncio for asynchronous I/O operations.
When the number of qubits (NQ) is much larger than the number of layers (NL),
When the number of qubits (NQ) is much larger than the number of local qubits (NL),
there will be excessive overhead. This class tries to run thread pool group
by group with each group of CPU_COUNT size.
"""
Expand Down
51 changes: 11 additions & 40 deletions qdao/qiskit/annotated_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,7 @@
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.

"""
Annotated Operations
====================
This module defines the `AnnotatedOperation` class and various modifier classes
used to create annotated operations in Qiskit. Annotated operations allow the
addition of modifiers to base operations, enabling more abstract representations
and optimizations during transpilation.
Classes:
--------
- Modifier: Base class for all modifiers.
- InverseModifier: Modifier to specify that the operation is inverted.
- ControlModifier: Modifier to specify that the operation is controlled.
- PowerModifier: Modifier to specify that the operation is raised to a power.
- AnnotatedOperation: Class representing an annotated operation.
Functions:
----------
- _canonicalize_modifiers: Returns the canonical representative of the modifier list.
"""
"""Annotated Operations."""

from __future__ import annotations

Expand Down Expand Up @@ -107,8 +84,8 @@ def __init__(self, base_op: Operation, modifiers: Union[Modifier, List[Modifier]
that is immediately followed by its inverse.
Args:
base_op (Operation): base operation being modified
modifiers (Union[Modifier, List[Modifier]]): ordered list of modifiers. Supported modifiers include
base_op: base operation being modified
modifiers: ordered list of modifiers. Supported modifiers include
``InverseModifier``, ``ControlModifier`` and ``PowerModifier``.
Examples::
Expand Down Expand Up @@ -192,14 +169,14 @@ def control(
Implemented as an annotated operation, see :class:`.AnnotatedOperation`.
Args:
num_ctrl_qubits (int): number of controls to add to gate (default: ``1``)
label (str | None): ignored (used for consistency with other control methods)
ctrl_state (int | str | None): The control state in decimal or as a bitstring
num_ctrl_qubits: number of controls to add to gate (default: ``1``)
label: ignored (used for consistency with other control methods)
ctrl_state: The control state in decimal or as a bitstring
(e.g. ``'111'``). If ``None``, use ``2**num_ctrl_qubits-1``.
annotated (bool): ignored (used for consistency with other control methods)
annotated: ignored (used for consistency with other control methods)
Returns:
AnnotatedOperation: Controlled version of the given operation.
Controlled version of the given operation.
"""
# pylint: disable=unused-argument
extended_modifiers = self.modifiers.copy()
Expand All @@ -215,10 +192,10 @@ def inverse(self, annotated: bool = True):
Implemented as an annotated operation, see :class:`.AnnotatedOperation`.
Args:
annotated (bool): ignored (used for consistency with other inverse methods)
annotated: ignored (used for consistency with other inverse methods)
Returns:
AnnotatedOperation: Inverse version of the given operation.
Inverse version of the given operation.
"""
# pylint: disable=unused-argument
extended_modifiers = self.modifiers.copy()
Expand All @@ -234,12 +211,6 @@ def _canonicalize_modifiers(modifiers):
of control qubits / control state and the total power. The InverseModifier
will be present if total power is negative, whereas the power modifier will
be present only with positive powers different from 1.
Args:
modifiers (List[Modifier]): List of modifiers to canonicalize.
Returns:
List[Modifier]: Canonical list of modifiers.
"""
power = 1
num_ctrl_qubits = 0
Expand All @@ -266,4 +237,4 @@ def _canonicalize_modifiers(modifiers):
if num_ctrl_qubits > 0:
canonical_modifiers.append(ControlModifier(num_ctrl_qubits, ctrl_state))

return canonical_modifiers
return canonical_modifiers
115 changes: 16 additions & 99 deletions qdao/qiskit/gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,50 +10,7 @@
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.

"""
Unitary Gate Module
====================
This module provides a `Gate` class to represent unitary gates in quantum circuits.
It includes methods for matrix conversion, exponentiation, control, and argument broadcasting.
Modules:
--------
- qiskit.circuit.exceptions: Contains exceptions related to quantum circuits.
- qiskit.circuit.parameterexpression: Handles parameter expressions in quantum circuits.
- .annotated_operation: Provides classes for annotated operations.
- .instruction: Defines the base `Instruction` class.
Classes:
--------
- Gate: Represents a unitary gate in a quantum circuit.
Methods:
--------
- __init__(self, name: str, num_qubits: int, params: list, label: str | None = None, duration: Any = None, unit: str = "dt")
Create a new gate.
- to_matrix(self) -> np.ndarray
Return a Numpy.array for the gate unitary matrix.
- power(self, exponent: float)
Creates a unitary gate as `gate^exponent`.
- __pow__(self, exponent: float) -> "Gate"
Allows exponentiation using the `**` operator.
- _return_repeat(self, exponent: float) -> "Gate"
Returns a repeated version of the gate.
- control(self, num_ctrl_qubits: int = 1, label: str | None = None, ctrl_state: int | str | None = None, annotated: bool = False)
Return the controlled version of itself.
- _broadcast_single_argument(qarg: list) -> Iterator[tuple[list, list]]
Expands a single argument for broadcasting.
- _broadcast_2_arguments(qarg0: list, qarg1: list) -> Iterator[tuple[list, list]]
Expands two arguments for broadcasting.
- _broadcast_3_or_more_args(qargs: list) -> Iterator[tuple[list, list]]
Expands three or more arguments for broadcasting.
- broadcast_arguments(self, qargs: list, cargs: list) -> Iterable[tuple[list, list]]
Validation and handling of the arguments and their relationships.
- validate_parameter(self, parameter: Any)
Gate parameters should be int, float, or ParameterExpression.
"""
"""Unitary gate."""

from __future__ import annotations

Expand Down Expand Up @@ -82,12 +39,10 @@ def __init__(
"""Create a new gate.
Args:
name (str): The Qobj name of the gate.
num_qubits (int): The number of qubits the gate acts on.
params (list): A list of parameters.
label (str | None): An optional label for the gate.
duration (Any): The duration of the gate.
unit (str): The unit of the gate duration.
name: The Qobj name of the gate.
num_qubits: The number of qubits the gate acts on.
params: A list of parameters.
label: An optional label for the gate.
"""
self.definition = None
super().__init__(
Expand Down Expand Up @@ -154,13 +109,13 @@ def control(
Implemented either as a controlled gate (ref. :class:`.ControlledGate`)
or as an annotated operation (ref. :class:`.AnnotatedOperation`).
Args:
num_ctrl_qubits (int): number of controls to add to gate (default: ``1``)
label (str | None): optional gate label. Ignored if implemented as an annotated
Args:
num_ctrl_qubits: number of controls to add to gate (default: ``1``)
label: optional gate label. Ignored if implemented as an annotated
operation.
ctrl_state (int | str | None): the control state in decimal or as a bitstring
ctrl_state: the control state in decimal or as a bitstring
(e.g. ``'111'``). If ``None``, use ``2**num_ctrl_qubits-1``.
annotated (bool): indicates whether the controlled gate can be implemented
annotated: indicates whether the controlled gate can be implemented
as an annotated gate.
Returns:
Expand All @@ -184,13 +139,7 @@ def control(
@staticmethod
def _broadcast_single_argument(qarg: list) -> Iterator[tuple[list, list]]:
"""Expands a single argument.
Args:
qarg (list): List of qubit arguments.
Returns:
Iterator[tuple[list, list]]: Iterator of expanded arguments.
For example: [q[0], q[1]] -> [q[0]], [q[1]]
"""
# [q[0], q[1]] -> [q[0]]
Expand All @@ -200,18 +149,6 @@ def _broadcast_single_argument(qarg: list) -> Iterator[tuple[list, list]]:

@staticmethod
def _broadcast_2_arguments(qarg0: list, qarg1: list) -> Iterator[tuple[list, list]]:
"""Expands two arguments for broadcasting.
Args:
qarg0 (list): First list of qubit arguments.
qarg1 (list): Second list of qubit arguments.
Returns:
Iterator[tuple[list, list]]: Iterator of expanded arguments.
Raises:
CircuitError: If the arguments cannot be combined.
"""
if len(qarg0) == len(qarg1):
# [[q[0], q[1]], [r[0], r[1]]] -> [q[0], r[0]]
# -> [q[1], r[1]]
Expand All @@ -234,18 +171,6 @@ def _broadcast_2_arguments(qarg0: list, qarg1: list) -> Iterator[tuple[list, lis

@staticmethod
def _broadcast_3_or_more_args(qargs: list) -> Iterator[tuple[list, list]]:
"""Expands three or more arguments for broadcasting.
Args:
qargs (list): List of lists of qubit arguments.
Returns:
Iterator[tuple[list, list]]: Iterator of expanded arguments.
Raises:
CircuitError: If the arguments cannot be combined.
"""

if all(len(qarg) == len(qargs[0]) for qarg in qargs):
for arg in zip(*qargs):
yield list(arg), []
Expand Down Expand Up @@ -283,16 +208,15 @@ def broadcast_arguments(
[q[0], q[1]], [r[0], r[1]], ...] -> [q[0], r[0], ...], [q[1], r[1], ...]
Args:
qargs (list): List of quantum bit arguments.
cargs (list): List of classical bit arguments.
qargs: List of quantum bit arguments.
cargs: List of classical bit arguments.
Returns:
Iterable[tuple[list, list]]: A tuple with single arguments.
A tuple with single arguments.
Raises:
CircuitError: If the input is not valid. For example, the number of
arguments does not match the gate expectation.
"""
if len(qargs) != self.num_qubits or cargs:
raise CircuitError(
Expand All @@ -317,14 +241,7 @@ def broadcast_arguments(
raise CircuitError("This gate cannot handle %i arguments" % len(qargs))

def validate_parameter(self, parameter):
"""Gate parameters should be int, float, or ParameterExpression
Args:
parameter (Any): Parameter to validate.
Raises:
CircuitError: If the parameter is invalid.
"""
"""Gate parameters should be int, float, or ParameterExpression"""
if isinstance(parameter, ParameterExpression):
if len(parameter.parameters) > 0:
return (
Expand All @@ -341,4 +258,4 @@ def validate_parameter(self, parameter):
else:
raise CircuitError(
f"Invalid param type {type(parameter)} for gate {self.name}."
)
)
7 changes: 2 additions & 5 deletions qdao/qiskit/instruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
# that they have been altered from the originals.

"""
Qiskit Instruction Module
==========================
This module contains the definition and functionality of a generic quantum instruction.
A generic quantum instruction.
Instructions can be implementable on hardware (u, cx, etc.) or in simulation
(snapshot, noise, etc.).
Expand Down Expand Up @@ -681,4 +678,4 @@ def _compare_parameters(self, other):
except TypeError:
if x != y:
return False
return True
return True
Loading

0 comments on commit 58df6d2

Please sign in to comment.