Skip to content

Commit

Permalink
fix multi controlled operations params in circuit handler
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrieleMessina committed Apr 12, 2024
1 parent 6653086 commit 6f66d01
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
4 changes: 3 additions & 1 deletion qutes.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
"visitors": true
},
"cSpell.words": [
"Antlr"
"Antlr",
"Qiskit",
"qustring"
],
"pylint.importStrategy": "fromEnvironment",
"python.testing.cwd": "./src",
Expand Down
3 changes: 2 additions & 1 deletion src/quantum_circuit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
from quantum_circuit.quantum_circuit import QuantumCircuit
from quantum_circuit.quantum_circuit_handler import QuantumCircuitHandler
from quantum_circuit.quantum_register import QuantumRegister
from quantum_circuit.qutes_gates import QutesGates
from quantum_circuit.qutes_gates import QutesGates
from quantum_circuit.quantum_register import QiskitQubit
18 changes: 9 additions & 9 deletions src/quantum_circuit/quantum_circuit_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import Any, Callable, cast
from quantum_circuit.classical_register import ClassicalRegister
from quantum_circuit.quantum_circuit import QuantumCircuit
from quantum_circuit.quantum_register import QuantumRegister
from quantum_circuit.quantum_register import QuantumRegister, QiskitQubit
from symbols.types import Qubit, Quint, Qustring, QutesDataType
from qiskit import IBMQ, Aer, QiskitError, transpile
from qiskit.primitives import Sampler
Expand Down Expand Up @@ -219,20 +219,20 @@ def push_pauliy_operation(self, quantum_register : QuantumRegister) -> None:
def push_pauliz_operation(self, quantum_register : QuantumRegister) -> None:
self._current_operation_stack.append(lambda circuit : cast(QuantumCircuit, circuit).z(quantum_register))

def push_MCZ_operation(self, quantum_registers : list[QuantumRegister]) -> None:
mcz_gate = MCMT(ZGate(), sum([q.size for q in quantum_registers]) - 1, 1)
def push_MCZ_operation(self, quantum_registers : list[QuantumRegister] | list[QiskitQubit]) -> None:
mcz_gate = MCMT(ZGate(), sum([1 if isinstance(q, QiskitQubit) else q.size for q in quantum_registers]) - 1, 1)
self._current_operation_stack.append(lambda circuit : cast(QuantumCircuit, circuit).compose(mcz_gate, unwrap(quantum_registers), inplace=True))

def push_MCX_operation(self, quantum_registers : list[QuantumRegister]) -> None:
mcx_gate = MCMT(XGate(), sum([len(q) for q in quantum_registers]) - 1, 1)
def push_MCX_operation(self, quantum_registers : list[QuantumRegister] | list[QiskitQubit]) -> None:
mcx_gate = MCMT(XGate(), sum([1 if isinstance(q, QiskitQubit) else q.size for q in quantum_registers]) - 1, 1)
self._current_operation_stack.append(lambda circuit : cast(QuantumCircuit, circuit).compose(mcx_gate, unwrap(quantum_registers), inplace=True))

def push_MCY_operation(self, quantum_registers : list[QuantumRegister]) -> None:
mcy_gate = MCMT(YGate(), sum([q.size for q in quantum_registers]) - 1, 1)
def push_MCY_operation(self, quantum_registers : list[QuantumRegister] | list[QiskitQubit]) -> None:
mcy_gate = MCMT(YGate(), sum([1 if isinstance(q, QiskitQubit) else q.size for q in quantum_registers]) - 1, 1)
self._current_operation_stack.append(lambda circuit : cast(QuantumCircuit, circuit).compose(mcy_gate, unwrap(quantum_registers), inplace=True))

def push_MCP_operation(self, theta, quantum_registers : list[QuantumRegister]) -> None:
mcp_gate = MCMT(PhaseGate(theta), sum([q.size for q in quantum_registers]) - 1, 1)
def push_MCP_operation(self, theta, quantum_registers : list[QuantumRegister] | list[QiskitQubit]) -> None:
mcp_gate = MCMT(PhaseGate(theta), sum([1 if isinstance(q, QiskitQubit) else q.size for q in quantum_registers]) - 1, 1)
self._current_operation_stack.append(lambda circuit : cast(QuantumCircuit, circuit).compose(mcp_gate, unwrap(quantum_registers), inplace=True))

def push_hadamard_operation(self, quantum_register : QuantumRegister) -> None:
Expand Down
3 changes: 2 additions & 1 deletion src/quantum_circuit/quantum_register.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from qiskit import QuantumRegister as qr
from quantum_circuit.classical_register import ClassicalRegister
from qiskit.circuit.quantumregister import Qubit as QiskitQubit


class QuantumRegister(qr):
def __init__(self, size, var_name, bits = None):
Expand All @@ -8,4 +10,3 @@ def __init__(self, size, var_name, bits = None):

def __len__(self):
return self.size

0 comments on commit 6f66d01

Please sign in to comment.