Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Update qpy qiskit 0.45 #736

Merged
merged 22 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
34 changes: 25 additions & 9 deletions qiskit_ibm_provider/qpy/binary_io/circuits.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@

from qiskit import circuit as circuit_mod
from qiskit import extensions
from qiskit.circuit import library, controlflow, CircuitInstruction
from qiskit.circuit import library, controlflow, CircuitInstruction, ControlFlowOp
from qiskit.circuit.classical import expr
from qiskit.circuit.classicalregister import ClassicalRegister, Clbit
from qiskit.circuit.gate import Gate
from qiskit.circuit.singleton_gate import SingletonGate
from qiskit.circuit.controlledgate import ControlledGate
from qiskit.circuit.instruction import Instruction
from qiskit.circuit.quantumcircuit import QuantumCircuit
Expand Down Expand Up @@ -289,8 +290,10 @@ def _read_instruction( # type: ignore[no-untyped-def]
else:
raise AttributeError("Invalid instruction type: %s" % gate_name)

if instruction.label_size <= 0:
label = None
if gate_name in {"IfElseOp", "WhileLoopOp"}:
gate = gate_class(condition, *params)
gate = gate_class(condition, *params, label=label)
elif version >= 5 and issubclass(gate_class, ControlledGate):
if gate_name in {
"MCPhaseGate",
Expand All @@ -300,9 +303,9 @@ def _read_instruction( # type: ignore[no-untyped-def]
"MCXRecursive",
"MCXVChain",
}:
gate = gate_class(*params, instruction.num_ctrl_qubits)
gate = gate_class(*params, instruction.num_ctrl_qubits, label=label)
else:
gate = gate_class(*params)
gate = gate_class(*params, label=label)
gate.num_ctrl_qubits = instruction.num_ctrl_qubits
gate.ctrl_state = instruction.ctrl_state
gate.condition = condition
Expand All @@ -321,10 +324,19 @@ def _read_instruction( # type: ignore[no-untyped-def]
params = [len(qargs)]
elif gate_name in {"BreakLoopOp", "ContinueLoopOp"}:
params = [len(qargs), len(cargs)]
gate = gate_class(*params)
gate.condition = condition
if instruction.label_size > 0:
gate.label = label
if label is not None:
if issubclass(gate_class, SingletonGate):
gate = gate_class(*params, label=label)
else:
gate = gate_class(*params)
gate.label = label
else:
gate = gate_class(*params)
if condition:
if not isinstance(gate, ControlFlowOp):
gate = gate.c_if(*condition)
else:
gate.condition = condition
if circuit is None:
return gate
if not isinstance(gate, Instruction):
Expand Down Expand Up @@ -580,14 +592,18 @@ def _write_instruction( # type: ignore[no-untyped-def]
)
or gate_class_name == "Gate"
or gate_class_name == "Instruction"
or gate_class_name == "ControlledGate"
or isinstance(instruction.operation, library.BlueprintCircuit)
):
if instruction.operation.name not in custom_operations:
custom_operations[instruction.operation.name] = instruction.operation
custom_operations_list.append(instruction.operation.name)
gate_class_name = instruction.operation.name

elif gate_class_name == "ControlledGate":
gate_class_name = instruction.operation.name + "_" + str(uuid.uuid4())
custom_operations[gate_class_name] = instruction.operation
custom_operations_list.append(gate_class_name)

elif isinstance(instruction.operation, library.PauliEvolutionGate):
gate_class_name = r"###PauliEvolutionGate_" + str(uuid.uuid4())
custom_operations[gate_class_name] = instruction.operation
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
qiskit>=0.44.1
qiskit>=0.45
requests>=2.19
requests_ntlm>=1.1.0
numpy>=1.13
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import setuptools

REQUIREMENTS = [
"qiskit>=0.44.1",
"qiskit>=0.45",
"requests>=2.19",
"requests-ntlm>=1.1.0",
"numpy>=1.13",
Expand Down
Loading