circuit
Circuit
The Circuit class is the only interface to access OpenSquirrel's features.
Examples:
>>> c = Circuit.from_string("version 3.0; qubit[3] q; h q[0]")
>>> c
version 3.0
qubit[3] q
h q[0]
>>> c.decomposer(decomposer=mckay_decomposer.McKayDecomposer)
>>> c
version 3.0
qubit[3] q
x90 q[0]
rz q[0], 1.5707963
x90 q[0]
Source code in opensquirrel\circuit.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
|
__init__(register_manager, ir)
__repr__()
decompose(decomposer)
Generic decomposition pass. It applies the given decomposer function to every gate in the circuit.
Source code in opensquirrel\circuit.py
from_string(cqasm3_string, gate_set=default_gate_set, gate_aliases=default_gate_aliases, measurement_set=default_measurement_set)
classmethod
Create a circuit object from a cQasm3 string. All the gates in the circuit need to be defined in
the gates
argument.
- type-checking is performed, eliminating qubit indices errors and incoherences
- checks that used gates are supported and mentioned in
gates
with appropriate signatures - does not support map or variables, and other things...
- for example of
gates
dictionary, please look at TestGates.py
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cqasm3_string |
str
|
a cQASM 3 string |
required |
gate_set |
list[Callable[..., Gate]]
|
an array of gate semantic functions. See default_gates for examples |
default_gate_set
|
gate_aliases |
Mapping[str, Callable[..., Gate]]
|
a dictionary of extra gate aliases, mapping strings to functions in the gate set |
default_gate_aliases
|
measurement_set |
list[Callable[..., Measure]]
|
an array of measurement semantic functions. See default_measurements for examples |
default_measurement_set
|
Source code in opensquirrel\circuit.py
map(mapper)
Generic qubit mapper pass. Map the (virtual) qubits of the circuit to the physical qubits of the target hardware.
Source code in opensquirrel\circuit.py
merge_single_qubit_gates()
Merge all consecutive 1-qubit gates in the circuit. Gates obtained from merging other gates become anonymous gates.
Source code in opensquirrel\circuit.py
replace(gate_generator, f)
Manually replace occurrences of a given gate with a list of gates.
f
is a callable that takes the arguments of the gate that is to be replaced and
returns the decomposition as a list of gates.