Skip to content

Commit

Permalink
Merge pull request #2 from ColibrITD-SAS/dev
Browse files Browse the repository at this point in the history
add implementation of the identity gate (ColibrITD-SAS#25)
  • Loading branch information
saguiras authored Mar 7, 2024
2 parents a9606aa + 9d42550 commit bc41434
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 77 deletions.
81 changes: 40 additions & 41 deletions mpqp/all.py
Original file line number Diff line number Diff line change
@@ -1,63 +1,62 @@
# pyright: reportUnusedImport=false
import numpy as np
from . import QCircuit, Barrier, Language, Instruction

from mpqp.execution.providers_execution.atos_execution import get_result_from_qlm_job_id

from . import Barrier, Instruction, Language, QCircuit
from .execution import (
Job,
JobStatus,
JobType,
Result,
Sample,
StateVector,
adjust_measure,
run,
submit,
)
from .execution.connection.qlm_connection import get_all_job_ids
from .execution.devices import ATOSDevice, AWSDevice, IBMDevice
from .execution.vqa import Optimizer, minimize
from .gates import (
X,
Y,
Z,
H,
P,
S,
T,
SWAP,
U,
Rx,
Ry,
Rz,
Rk,
CNOT,
CZ,
CRk,
SWAP,
TOF,
ControlledGate,
CRk,
CustomGate,
Gate,
ParametrizedGate,
symbols,
GateDefinition,
H,
Id,
KrausRepresentation,
P,
ParametrizedGate,
PauliDecomposition,
CustomGate,
Rk,
Rx,
Ry,
Rz,
S,
T,
U,
UnitaryMatrix,
X,
Y,
Z,
symbols,
)
from .measures import (
ComputationalBasis,
Basis,
HadamardBasis,
VariableSizeBasis,
BasisMeasure,
ComputationalBasis,
ExpectationMeasure,
Observable,
HadamardBasis,
Measure,
Observable,
VariableSizeBasis,
)
from .execution import (
Result,
StateVector,
Sample,
run,
adjust_measure,
submit,
Job,
JobStatus,
JobType,
)
from .execution.devices import (
ATOSDevice,
IBMDevice,
AWSDevice,
)
from .execution.vqa import minimize, Optimizer
from .execution.connection.qlm_connection import get_all_job_ids
from mpqp.execution.providers_execution.atos_execution import get_result_from_qlm_job_id
from .qasm import open_qasm_file_conversion_2_to_3, open_qasm_hard_includes

theta, k = symbols("θ k") # type: ignore
Expand Down
35 changes: 16 additions & 19 deletions mpqp/core/instruction/gates/__init__.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
# pyright: reportUnusedImport=false
from .controlled_gate import ControlledGate
from .custom_gate import CustomGate, UnitaryMatrix
from .gate import Gate
from .parametrized_gate import ParametrizedGate, symbols
from .gate_definition import (
GateDefinition,
KrausRepresentation,
PauliDecomposition,
)
from .gate_definition import GateDefinition, KrausRepresentation, PauliDecomposition
from .native_gates import (
X,
Y,
Z,
CNOT,
CZ,
SWAP,
TOF,
CRk,
H,
Id,
P,
S,
T,
SWAP,
U,
Rk,
Rx,
Ry,
Rz,
Rk,
CNOT,
CZ,
CRk,
TOF,
S,
T,
U,
X,
Y,
Z,
)
from .custom_gate import CustomGate, UnitaryMatrix
from .parametrized_gate import ParametrizedGate, symbols
44 changes: 27 additions & 17 deletions mpqp/core/instruction/gates/native_gates.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,40 @@

import numpy as np
import numpy.typing as npt

from qiskit.circuit import Parameter
from qiskit.circuit.library import (
ZGate,
YGate,
CCXGate,
CPhaseGate,
CXGate,
CZGate,
HGate,
IGate,
PhaseGate,
SGate,
UGate,
TGate,
SwapGate,
RXGate,
RYGate,
RZGate,
HGate,
CXGate,
SGate,
SwapGate,
TGate,
UGate,
XGate,
CPhaseGate,
CZGate,
YGate,
ZGate,
)
from sympy import Expr, pi

# pylance doesn't handle well Expr, so a lot of "type:ignore" will happen in
# this file :/
from typeguard import typechecked

from mpqp.core.languages import Language
from mpqp.core.instruction.gates.gate import Gate, InvolutionGate, SingleQubitGate
from mpqp.core.instruction.gates.controlled_gate import ControlledGate
from mpqp.core.instruction.gates.gate import Gate, InvolutionGate, SingleQubitGate
from mpqp.core.instruction.gates.gate_definition import UnitaryMatrix
from mpqp.core.instruction.gates.parametrized_gate import ParametrizedGate
from mpqp.core.languages import Language
from mpqp.tools.generics import Matrix
from mpqp.tools.maths import cos, sin, exp
from mpqp.tools.maths import cos, exp, sin


@typechecked
def _qiskit_parameter_adder(param: Expr | float, qiskit_parameters: set[Parameter]):
Expand Down Expand Up @@ -162,6 +163,7 @@ class NoParameterGate(NativeGate, ABC):
| CXGate
| CZGate
| CCXGate
| IGate
]
"""Corresponding ``qiskit``'s gate class."""
matrix: npt.NDArray[np.complex64]
Expand Down Expand Up @@ -194,11 +196,19 @@ def __init__(self, target: int):


class Id(OneQubitNoParamGate, InvolutionGate):
"""TODO hamza/muhammad
"""One qubit identity gate.
Args:
target: Index referring to the qubit on which the gate will be applied.
Example:
>>> Id(0).to_matrix()
array([[1, 0],
[0, 1]])
"""

qiskit_gate = ...
matrix = ...
qiskit_gate = IGate
matrix = np.eye(2)


class X(OneQubitNoParamGate, InvolutionGate):
Expand Down

0 comments on commit bc41434

Please sign in to comment.