wy_qcos.transpiler.cmss.circuit package
Subpackages
Submodules
wy_qcos.transpiler.cmss.circuit.circuit_equiv module
- class wy_qcos.transpiler.cmss.circuit.circuit_equiv.CircuitEquivChecker(qc1, qc2)
基类:
objectCircuitEquivChecker scope for different methods.
- Description:
Operator(Recommended scope for circuit): width of circuit in (1, 10], depth of circuit in (1, 50]. QCEC(Recommended scope for circuit): width of circuit in (10, 50], depth of circuit in (50, 2000].
- 参数:
qc1 (QuantumCircuit)
qc2 (QuantumCircuit)
- static cicuit_equiv_by_qcec(qc1, qc2)
Return True if qc1 is equal to qc2 by qcec.
- 参数:
qc1 (str | os.PathLike[str]) -- quantum circuit represented by
path. (qasm string or)
qc2 (str | os.PathLike[str]) -- quantum circuit represented by
path.
- algo_equiv(algo_no=0)
Compare the quantum circuits by selecting different algorithms.
- 参数:
algo_no (int) -- the algorithm number, default 0.
0 (If algo_no is)
Operator (verifying by)
QCEC. (otherwise)
1 (If algo_no is)
Operator
2 (If algo_no is)
and (verifying by MQT QCEC(Decision Diagrams)
Checking). (Alternating Equivalence)
- 返回类型:
bool
wy_qcos.transpiler.cmss.circuit.collect_blocks module
- class wy_qcos.transpiler.cmss.circuit.collect_blocks.BlockCollector(dag)
基类:
objectDividing a DAG into blocks of nodes that satisfy certain criteria.
- 参数:
dag (DAGCircuit)
- collect_matching_block(filter_fn)
Collects the largest block that matches the filter function.
- collect_all_matching_blocks(filter_fn, split_blocks=True, min_block_size=2, collect_from_back=False)
Collects all blocks that match a given filtering function filter_fn.
This iteratively finds the largest block that does not match filter_fn, then the largest block that matches filter_fn, and so on, until no more uncollected nodes remain. Intuitively, finding larger blocks of non-matching nodes helps to find larger blocks of matching nodes later on.
- 参数:
filter_fn -- the filter function.
split_blocks (bool, optional) -- If true, split collected blocks into sub-blocks over disjoint qubit subsets. Defaults to True.
min_block_size (int, optional) -- the minimum number of gates in the block for the block to be collected. Defaults to 2.
collect_from_back (bool, optional) -- collect blocks from the outputs towards the inputs of the circuit. Defaults to False.
- class wy_qcos.transpiler.cmss.circuit.collect_blocks.BlockSplitter
基类:
objectSplits a block of nodes into sub-blocks over disjoint qubits.
The implementation is based on the Disjoint Set Union data structure.
- find_leader(index)
Find leader in DSU.
- 参数:
index (int) -- bit index to find.
- 返回:
leader qubit index.
- 返回类型:
int
- union_leaders(index1, index2)
Union in DSU.
- 参数:
index1 (int) -- First qubit index.
index2 (int) -- Second qubit index.
- run(block)
Splits block of nodes into sub-blocks over disjoint qubits.
- 参数:
block (list) -- List of nodes to split.
- 返回:
- List of sub-blocks, each containing nodes acting on connected
qubit sets.
- 返回类型:
list
wy_qcos.transpiler.cmss.circuit.dag_circuit module
- class wy_qcos.transpiler.cmss.circuit.dag_circuit.DAGCircuit
基类:
objectQuantum circuit as a directed acyclic graph.
There are 3 types of nodes in the graph: inputs, outputs, and operations. The nodes are connected by directed edges that correspond to qubits.
- property wires
Return a list of the wires in order.
- property node_counter
Returns the number of nodes in the dag.
- add_qubits(num_qubits)
Add qubit wires.
- 参数:
num_qubits (int) -- number of qubits
- rename_op(old_op, new_op)
Convert between Rz and T,Z,S gates.
- 参数:
old_op (GateOperation) -- decrease old_op count.
new_op (GateOperation) -- increase new_op count.
- parameterize_all_rz()
Convert all T/Tdg/S/Sdg/Z into Rz gates.
- deparameterize_all_rz()
Convert all Rz gates into T/Tdg/S/Sdg/Z.
- apply_operation_back(op, qargs=None)
Apply an operation/gate to the output of the circuit.
- 参数:
op -- the operation associated with the DAG node
qargs -- qubits that op will be applied to, GateOperation has targets, so qargs can be None.
- 返回:
the node for the op that was added to the dag
- 返回类型:
- apply_operation_front(op, qargs=None, cargs=None)
Apply an operation to the input of the circuit.
- 参数:
op -- the operation associated with the DAG node
qargs -- qubits that op will be applied to
cargs (tuple[Clbit]) -- cbits that op will be applied to
- 返回:
the node for the op that was added to the dag
- 返回类型:
- size()
Return the number of operations.
- 返回:
the circuit size
- 返回类型:
int
- depth()
Return the circuit depth.
- 返回:
the circuit depth
- 返回类型:
int
- width()
Return the total number of qubits used by the circuit.
- nodes_on_wire(wire, only_ops=False)
Iterator for nodes that affect a given wire.
- 参数:
wire (Bit) -- the wire to be looked at.
only_ops (bool) -- True if only the ops nodes are wanted; otherwise, all nodes are returned.
- 生成器:
Iterator -- the successive nodes on the given wire
- 抛出:
ValueError -- if the given wire doesn't exist in the DAG
- topological_nodes(key=None)
Yield nodes in topological order.
- 参数:
key (Callable) -- A callable which will take a DAGNode object and return a string sort key. If not specified the
sort_keyattribute will be used as the sort key for each node.- 返回:
node in topological order
- 返回类型:
generator(DAGNode)
- topological_op_nodes(key=None)
Yield op nodes in topological order.
Allowed to pass in specific key to break ties in top order
- 参数:
key (Callable) -- A callable which will take a DAGNode object and return a string sort key. If not specified the
sort_keyattribute will be used as the sort key for each node.- 返回:
op node in topological order
- 返回类型:
generator(DAGOpNode)
- node(node_id)
Get the node in the dag.
- 参数:
node_id (int) -- Node identifier.
- 返回:
the node.
- 返回类型:
node
- nodes()
Iterator for node values.
- 生成器:
node -- the node.
- op_nodes()
Get the list of "op" nodes in the dag.
- 返回:
the list of op node.
- 返回类型:
list[DAGOpNode]
- two_qubit_ops()
Get list of 2 qubit operations.
- multi_qubit_ops()
Get list of 3+ qubit operations.
- longest_path()
Returns the longest path in the dag as a list of DAGNodes.
- successors(node)
Returns iterator of the successors of a node as DAGNodes.
- predecessors(node)
Returns iterator of the predecessors of a node as DAGNodes.
- is_successor(node, node_succ)
Checks if a second node is in the successors of node.
- is_predecessor(node, node_pred)
Checks if a second node is in the predecessors of node.
- ancestors(node)
Returns set of the ancestors of a node.
- descendants(node)
Returns set of the descendants of a node.
- remove_op_node(node)
Remove an operation node n.
Add edges from predecessors to successors.
- collect_runs(namelist)
Return a set of runs of "op" nodes with the given names.
For example, "... h q[0]; cx q[0],q[1]; cx q[0],q[1]; h q[1]; .." would produce the tuple of cx nodes as an element of the set returned from a call to collect_runs(["cx"]). If instead the cx nodes were "cx q[0],q[1]; cx q[1],q[0];", the method would still return the pair in a tuple. The namelist can contain names that are not in the circuit's basis.
Nodes must have only one successor to continue the run.
- count_ops()
Count the occurrences of operation names.
- 返回:
- a mapping of operation names to
the number of times it appears.
- 返回类型:
Mapping[str, int]
- replace_block_with_op(node_block, op, cycle_check=True)
Replace a block of nodes with a single node.
- 参数:
node_block (list[DAGNode]) -- A list of dag nodes that represents the node block to be replaced
op (GateOperation) -- The operation to replace the block with.
cycle_check (bool, optional) -- check that replacing with a single node would introduce a cycle. Defaults to True.
- 返回:
The op node that replaces the block.
- 返回类型:
- substitute_node_with_dag(node, input_dag, wires=None)
Replace one node with dag.
- 参数:
node (DAGOpNode) -- node to substitute.
input_dag (DAGCircuit) -- circuit that will substitute the node.
wires (list | dict) -- gives an order for qubits in the input circuit. Defaults to None.
- 返回:
maps node IDs from input_dag to their new node in self.
- 返回类型:
dict
- classmethod ir_to_dag(ir)
Convert IR to DAGCircuit.
- 参数:
ir (list) -- gates list.
- 返回:
DAGCircuit corresponding to IR.
- 返回类型:
- classmethod circuit_to_dag(circ)
Convert QuantumCircuit to DAGCircuit.
- 参数:
circ (QuantumCircuit) -- quantum circuit.
- 返回:
DAGCircuit corresponding to circuit.
- 返回类型:
- dag_to_circuit(num_qubits=0)
Convert DAG to QuantumCircuit.
- 参数:
num_qubits (int) -- number of qubits in the circuit.
- 返回:
QuantumCircuit corresponding to DAG.
- 返回类型:
- get_multi_graph()
Get DAG Graph.
- 返回:
DAG Graph
- 返回类型:
rx.PyDAG
- two_qubit_ops_to_dag()
Convert two-qubit gates operations into a DAG.
- 返回:
Directed acyclic graph containing two-bit gates.
- 返回类型:
- edges(nodes=None)
Iterator for edge values and source and dest node.
- 参数:
nodes (DAGOpNode, DAGInNode, or DAGOutNode | list) -- Either a list of nodes or a single input node.
- 生成器:
edge --
- the edge in the same format as out_edges the tuple
(source node, destination node, edge data).
wy_qcos.transpiler.cmss.circuit.dag_node module
- class wy_qcos.transpiler.cmss.circuit.dag_node.DAGNode(nid=-1)
基类:
objectParent class for DAGOpNode, DAGInNode, and DAGOutNode.
- class wy_qcos.transpiler.cmss.circuit.dag_node.DAGOpNode(op, qargs=(), cargs=())
基类:
DAGNodeObject to represent an Gate at a node in the DAGCircuit.
- 参数:
qargs (Iterable[int])
cargs (Iterable[int])
- op
- qargs
- cargs
- sort_key
- flag
- property name
Returns the Gate name corresponding to the op for this node.
- class wy_qcos.transpiler.cmss.circuit.dag_node.DAGInNode(wire)
基类:
DAGNodeObject to represent an incoming wire node in the DAGCircuit.
- wire
- sort_key
- class wy_qcos.transpiler.cmss.circuit.dag_node.DAGOutNode(wire)
基类:
DAGNodeObject to represent an outgoing wire node in the DAGCircuit.
- wire
- sort_key
wy_qcos.transpiler.cmss.circuit.quantum_circuit module
- class wy_qcos.transpiler.cmss.circuit.quantum_circuit.QuantumCircuit(num_qubits=0, num_clbits=0, global_phase=0)
基类:
object- 参数:
num_qubits (int)
num_clbits (int)
global_phase (float)
- classmethod from_ir(ir, num_qubits=0)
Create a quantum circuit from a list of gate operations.
- 参数:
ir (list[BaseOperation]) -- gate operations of ir.
num_qubits (int) -- number of qubits in the circuit.
- 返回:
a quantum circuit corresponding to the ir.
- 返回类型:
- append(operation)
Append a gate operation to the quantum circuit.
- 参数:
operation (BaseOperation) -- The gate operation to append.
- append_operations(operations)
Append multiple gate operations to the quantum circuit.
- 参数:
operations (list[BaseOperation]) -- The list of gate
append. (operations to)
- get_operations()
- property num_qubits
- property num_clbits
- property global_phase
- set_global_phase(phase)
Set the global phase.
- 参数:
phase (float)
- set_num_qubits(num_qubits)
- 参数:
num_qubits (int)
- set_num_clbits(num_clbits)
- 参数:
num_clbits (int)
- depth()
Calculate the depth of the quantum circuit.
- 返回:
depth of the quantum circuit
- 返回类型:
depth (int)
- width()
Calculate the width of the quantum circuit.
- 返回:
number of bits in the quantum circuit
- 返回类型:
width (int)
- size()
Returns total number of operations in circuit.
- 返回:
Total number of gate operations.
- 返回类型:
int
- add_register(*regs)
Add registers to the quantum circuit.
- 参数:
*regs (Register|QuantumRegister|ClassicalRegister) -- registers
added (to be)
- measure(qubits)
Measure quantum bits.
- 参数:
qubits (list) -- qubit(s) to measure.
- measure_all()
Adds measurement to all qubits.
By default, adds new classical bits in a
ClassicalRegisterto store these measurements.
wy_qcos.transpiler.cmss.circuit.register module
- class wy_qcos.transpiler.cmss.circuit.register.Register(size=None, name=None, init_pos=0, bits=None)
基类:
objectCreate a quantum register.
- 参数:
size (int | None)
name (str | None)
init_pos (int)
bits (list[int] | None)
- instances_counter = count(0)
- prefix = 'reg'
- property name
Get the register name.
- property size
Get the register size.
- index(bit)
Find the index of the provided bit within this register.
- class wy_qcos.transpiler.cmss.circuit.register.QuantumRegister(size=None, name=None, init_pos=0, bits=None)
基类:
RegisterCreate a quantum register.
- 参数:
size (int | None)
name (str | None)
init_pos (int)
bits (list[int] | None)
- instances_counter = count(0)
- prefix = 'q'
- class wy_qcos.transpiler.cmss.circuit.register.ClassicalRegister(size=None, name=None, init_pos=0, bits=None)
基类:
RegisterCreate a classical register.
- 参数:
size (int | None)
name (str | None)
init_pos (int)
bits (list[int] | None)
- instances_counter = count(0)
- prefix = 'c'
wy_qcos.transpiler.cmss.circuit.utils module
- class wy_qcos.transpiler.cmss.circuit.utils.RandomCircuitGen
基类:
objectRandom circuit generator.
- Description:
Generate random circuit with depth or number of gates.
- random_circuit_with_depth(num_qubits, depth, max_operands=2, measure=False, reset=False, seed=None, gate_type=1, density=0.05, outfile=None)
Generate random circuit of arbitrary size and form.
- 参数:
num_qubits (int) -- number of qubits.
depth (int) -- depth of circuit.
max_operands (int, optional) -- max qubits of the gates operation.
2. (Defaults to)
measure (bool) -- whether to measure the qubits. Defaults to False.
reset (bool) -- whether to reset the qubits. Defaults to False.
seed (int, optional) -- random seed. Defaults to None.
gate_type (int) -- type of gates. 0 for random gates,
T. (1 for Clifford +)
density (float) -- the number of qubits that would be used to filled
gates (with)
circuit. (representing density of gates in the)
0.3. (Defaults to)
outfile (str, optional) -- output file path. Defaults to None.
- 返回:
random ir list.
- 返回类型:
list
- random_circuit_with_gates(num_qubits, num_gates, basis_gates=('x', 's', 'sdg', 't', 'tdg', 'z', 'h', 'rz', 'cx'), seed=None, outfile=None)
Generate a random ir.
- 参数:
num_qubits (int) -- number of qubits.
num_gates (int) -- number of gates.
basis_gates (tuple, optional) -- basis gates. Defaults to ("x", "s", "sdg", "t", "tdg", "z", "h", "rz", "cx").
seed (int) -- random seed.
outfile (str, optional) -- output file path. Defaults to None.
- 返回:
random ir list.
- 返回类型:
list
- wy_qcos.transpiler.cmss.circuit.utils.is_equal(circ1, circ2)
Compare two quantum circuits.
- 参数:
circ1 (QuantumCircuit) -- the first quantum circuit.
circ2 (QuantumCircuit) -- the second quantum circuit.
- 返回:
equal or not.
- 返回类型:
bool