Skip to content

Commit

Permalink
Merge pull request #18 from YuChenSSR:dev
Browse files Browse the repository at this point in the history
Added parameters for the pulse gate
  • Loading branch information
YuChenSSR committed May 6, 2023
2 parents 04d64d6 + c593262 commit 81a35b5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
16 changes: 10 additions & 6 deletions src/quafu/dagcircuits/circuit_dag.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from typing import Dict, Any, List, Union
import copy

from .instruction_node import InstructionNode # instruction_node.py in the same folder as circuit_dag.py now
from quafu.dagcircuits.instruction_node import InstructionNode # instruction_node.py in the same folder as circuit_dag.py now

# import pygraphviz as pgv
from networkx.drawing.nx_pydot import write_dot
Expand Down Expand Up @@ -42,12 +42,14 @@ def gate_to_node(input_gate,specific_label: str):
gate.paras = getattr(gate, 'paras', None) or None
gate.duration = getattr(gate, 'duration', None) or None
gate.unit = getattr(gate, 'unit', None) or None
gate.channel = getattr(gate, 'channel', None) or None
gate.time_func = getattr(gate, 'time_func', None) or None

if gate.paras and not isinstance(gate.paras, list): # if paras is True and not a list, make it a list
gate.paras = [gate.paras]

# hashable_gate = InstructionNode(gate.name, gate.pos, gate.paras,gate.matrix,gate.duration,gate.unit, label=i)
hashable_gate = InstructionNode(gate.name, gate.pos, gate.paras,gate.duration, gate.unit, label=specific_label)
hashable_gate = InstructionNode(gate.name, gate.pos, gate.paras,gate.duration, gate.unit,gate.channel,gate.time_func, label=specific_label)
return hashable_gate


Expand Down Expand Up @@ -113,9 +115,9 @@ def circuit_to_dag(circuit):
# Add measure_gate node
qm = Any
qm.name = "measure"
qm.paras, qm.duration, qm.unit = [None,None,None]
qm.paras, qm.duration, qm.unit,qm.channel,qm.time_func = [None,None,None,None,None]
qm.pos = copy.deepcopy(circuit.measures) # circuit.measures is a dict
measure_gate = InstructionNode(qm.name, qm.pos, qm.paras, qm.duration, qm.unit, label="m")
measure_gate = InstructionNode(qm.name, qm.pos, qm.paras, qm.duration, qm.unit,qm.channel,qm.time_func, label="m")
g.add_node(measure_gate,color="blue")
# Add edges from qubit_last_use[qubit] to measure_gate
for qubit in measure_gate.pos.keys():
Expand Down Expand Up @@ -245,7 +247,8 @@ def node_to_gate(gate_in_dag):
unit = gate_in_dag.unit
paras = gate_in_dag.paras
pos = gate_in_dag.pos[0]
channel = gate_in_dag.label
channel = gate_in_dag.channel
# time_func = gate_in_dag.time_func

return gate_class(pos, *paras, duration, unit, channel)

Expand Down Expand Up @@ -339,8 +342,9 @@ def draw_dag(dep_g, output_format="png"):
'''
import pygraphviz
write_dot(dep_g, "dag.dot")
G = pgv.AGraph("dag.dot")
G = pygraphviz.AGraph("dag.dot")
G.layout(prog="dot")

if output_format == "png":
Expand Down
14 changes: 7 additions & 7 deletions src/quafu/dagcircuits/dag_test.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -48,7 +48,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 3,
"metadata": {},
"outputs": [
{
Expand All @@ -58,7 +58,7 @@
"<IPython.core.display.Image object>"
]
},
"execution_count": 7,
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
Expand Down Expand Up @@ -97,7 +97,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 4,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -126,7 +126,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 5,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -396,7 +396,7 @@
"<IPython.core.display.SVG object>"
]
},
"execution_count": 9,
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -414,7 +414,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 6,
"metadata": {},
"outputs": [
{
Expand Down
6 changes: 4 additions & 2 deletions src/quafu/dagcircuits/instruction_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ class InstructionNode:
pos:Union[List[Any], Dict[Any,Any]] # gate.pos | Dict[Any,Any] for measure
paras:List[Any] # gate.paras
# matrix:List[Any] # for gate in [QuantumGate]
duration:int # for gate in [Delay,XYResonance] in quafu
duration: Union[float,int] # for gate in [Delay,XYResonance,QuantumPulse] in quafu
unit:str # for gate in [Delay,XYResonance] in quafu
label:str
channel:str # for gate in [QuantumPulse] in quafu
time_func: Any # for gate in [QuantumPulse] in quafu
label:str # used for specifying the instruction node

def __hash__(self):
return hash((type(self.name), tuple(self.pos) ,self.label))
Expand Down

0 comments on commit 81a35b5

Please sign in to comment.