CircuitBased
QuICT.core.utils.CircuitBased ¶
Bases: object
Based Class for Circuit and Composite Gate.
Parameters:
-
name(str) –The name of current Quantum Circuit
Source code in QuICT/core/utils/circuit_based.py
fast_gates
property
¶
Return the list of tuple(gate, qubit_indexes, size) in the current circuit.
gates
property
¶
Return the list of BasicGate/CompositeGate/Operator in the current circuit.
Warning: this is slowly due to the copy of gates, you can use self.fast_gates to get list of tuple(gate, qubit_indexes, size) for further using.
assigned_value ¶
Whether all symbols in the Circuit/CompositeGate are assigned values.
Returns:
-
bool–If True, all symbols in the Circuit/CompositeGate are assigned values.
Source code in QuICT/core/utils/circuit_based.py
count_1qubit_gate ¶
The number of the one qubit gates in the Circuit/CompositeGate
Returns:
-
int(int) –the number of the one qubit gates
count_2qubit_gate ¶
The number of the two qubit gates in the Circuit/CompositeGate
Returns:
-
int(int) –the number of the two qubit gates
count_gate_by_gatetype ¶
The number of the target Quantum Gate in the Circuit/CompositeGate
Parameters:
-
gateType(GateType)–the type of gates to be count
Returns:
-
int(int) –the number of the gates
Source code in QuICT/core/utils/circuit_based.py
count_training_gate ¶
The number of the trainable gates in the Circuit/CompositeGate
Returns:
-
int–the number of the trainable gates
count_variables ¶
The number of the variables in the Circuit/CompositeGate.
Returns:
-
int–The number of variables.
decomposition ¶
decomposition_gates ¶
Decomposition the CompositeGate or BasicGate which has build_gate function.
Returns:
-
list(list) –The list of BasicGate
draw ¶
draw(method: str = 'matp_auto', filename: str = None, flatten: bool = False, hidden_empty_qubits: bool = True)
Draw the figure of circuit.
Parameters:
-
method(str)–the method to draw the circuit matp_inline: Show the figure interactively but do not save it to file. matp_file: Save the figure to file but do not show it interactively. matp_auto: Automatically select inline or file mode according to matplotlib backend. matp_silent: Return the drawn figure without saving or showing. command : command
-
filename(str)–the output filename without file extensions, default to None. If filename is None, it will using matlibplot.show() except matlibplot.backend is agg, it will output jpg file named circuit's name.
-
flatten(bool)–Whether draw the Circuit with CompositeGate or Decomposite it.
-
hidden_empty_qubits(bool)–Whether hidden the empty qubits in the circuit's graph.
Returns:
-
–
If method is 'matp_silent', a matplotlib Figure is returned. Note that that figure is created in matplotlib
-
–
Object Oriented interface, which means it must be display with IPython.display.
Examples:
>>> from IPython.display import display
>>> circ = Circuit(5)
>>> circ.random_append()
>>> silent_fig = circ.draw(method="matp_silent")
>>> display(silent_fig)
>>> from IPython.display import display
>>> compositegate = CompositeGate()
>>> cx_gate=CX & [1,3]
>>> u2_gate= U2(1, 0)
>>> H| compositegate(1)
>>> cx_gate | compositegate
>>> u2_gate | compositegate(1)
>>> silent_fig = compositegate.draw(method="matp_silent")
>>> display(silent_fig)
Source code in QuICT/core/utils/circuit_based.py
420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 | |
flatten ¶
flatten_gates ¶
free_symbols ¶
gate_combination ¶
Combination all consecutive single-qubit gate / bi-qubits gate in the circuit. It will flat all CompositeGate here.
Source code in QuICT/core/utils/circuit_based.py
gate_length ¶
get_all_gatetype ¶
get_gates_by_depth ¶
Get the list of Quantum Gates in target qubits and depth.
Parameters:
-
depth(int) –The target depth.
Source code in QuICT/core/utils/circuit_based.py
init_pargs ¶
Initialize the trainable parameters of the Circuit/CompositeGate.
Parameters:
-
symbols(list) –The symbols that needs to be assigned values.
-
values(Union[list, ndarray]) –The values to be assigned.
Source code in QuICT/core/utils/circuit_based.py
insert ¶
insert a Quantum Gate into current Circuit with given index.
Parameters:
-
gate(Union[BasicGate, CompositeGate]) –The quantum gate want to insert.
-
index(int) –The index of gate list.
Source code in QuICT/core/utils/circuit_based.py
insert_by_position ¶
Insert a Quantum Gate into current Circuit with given qubits and depth, it will cause the gate list to be flatten due to the insert gate into CompositeGate.
Parameters:
-
gate(Union[BasicGate, CompositeGate]) –The quantum gate want to insert
-
qubits(list[int], default:None) –The target qubit indexes.
-
depth(int, default:-1) –The index of insert position.
Source code in QuICT/core/utils/circuit_based.py
pop ¶
Pop the BasicGate/Operator/CompositeGate from current Quantum Circuit.
Parameters:
-
index(int, default:-1) –The target gate's index. Defaults to 0.
pop_by_position ¶
Pop the BasicGate/Operator/CompositeGate from current Quantum Circuit with given qubits and depth.
Parameters:
-
qubits(list) –The indexes of qubits.
-
depth(int) –The target depth.
Source code in QuICT/core/utils/circuit_based.py
qasm ¶
The qasm of current CompositeGate/Circuit. The Operator will be ignore.
Parameters:
-
output_file(str, default:None) –The output qasm file's name or path
Returns:
-
str–The string of Circuit/CompositeGate's qasm.
Source code in QuICT/core/utils/circuit_based.py
qcis ¶
generate the qcis of current CompositeGate/Circuit. WARNING: Only support the instruction set of QCIS.
Parameters:
-
output_file(str, default:None) –The output qcis file's name or path
Returns:
-
str–The string of Circuit/CompositeGate's qcis.
Source code in QuICT/core/utils/circuit_based.py
size ¶
the number of BasicGate/Operator in the Circuit.
Returns:
-
int(int) –the number of gates in circuit
symbol_pargs ¶
Returns the symbols in the Circuit/CompositeGate and their corresponding values.
Returns:
-
dict–Symbols with corresponding values.