CircuitFeature(circ: Circuit, vqm: VirtualQuantumMachine, step: int = 1, mapping: List[int] = None)
Parameters:
-
circ(Circuit)
–
an initial circuit and can be changed. This class is used
-
vqm(VirtualQuantumMachine)
–
this vqm should not be changed
-
step(int)
–
the step of the path in circuit to be considered
-
mapping(List[int])
–
Info:
use this class to compute features of circuits
Source code in QuICT/qcda/utility/fidelity_estimator/circuit_feature.py
| def __init__(
self,
circ: Circuit,
vqm: VirtualQuantumMachine,
step: int = 1,
mapping: List[int] = None):
"""
Args:
circ(Circuit): an initial circuit and can be changed. This class is used
to extract feature of this circuit.
vqm(VirtualQuantumMachine): this vqm should not be changed
step(int): the step of the path in circuit to be considered
mapping(List[int]): mapping of qubits
Info:
use this class to compute features of circuits
"""
self.circ = circ
if mapping is None:
mapping = list(range(vqm.qubit_number))
self.mapping = mapping
self.depth = circ.depth()
self.step = step
self.circ_2d = self.get_circ_2d()
self.vqm = vqm
|
count_path
count_path(path: CircuitPath)
Parameters:
Returns:
int: the count of this path
Source code in QuICT/qcda/utility/fidelity_estimator/circuit_feature.py
| def count_path(self, path: CircuitPath):
"""
Args:
path(CircuitPath): desired path
Returns:
int: the count of this path
"""
count = 0
for depth in range(self.depth - len(path)):
for g in self.circ_2d[depth]:
if path.get_gate_type(0) != g.type:
continue
else:
# match the start gate, then check path. first parallel then next
next_depth = depth
exclude = [g]
next_gate = g
for path_depth in range(1, len(path) + 1):
r_type = path.get_r_type(path_depth)
if r_type == "next" or r_type == "next2" or r_type == "next3":
next_depth = next_depth + 1
next_gate = self._find_gate(next_gate, path.get_gate_type(path_depth),
r_type,
next_depth, exclude=exclude)
if next_gate is None:
break
exclude.append(next_gate)
else:
count += 1
return count
|
get_circ_2d
Returns:
Source code in QuICT/qcda/utility/fidelity_estimator/circuit_feature.py
| def get_circ_2d(self):
"""
Returns:
list(list): the 2d circuit layout
"""
out = []
for ii in range(1, self.depth + 1):
out.append(self.circ.get_gates_by_depth(ii))
return out
|