|
2 | 2 | from tequila.wavefunction.qubit_wavefunction import QubitWaveFunction |
3 | 3 | from tequila.utils import TequilaException |
4 | 4 | from tequila.hamiltonian import PauliString |
5 | | -from tequila.circuit._gates_impl import ExponentialPauliGateImpl, QGateImpl, RotationGateImpl, QubitHamiltonian, QubitExcitationImpl |
| 5 | +from tequila.circuit._gates_impl import ExponentialPauliGateImpl, QGateImpl, RotationGateImpl, QubitHamiltonian |
| 6 | +from tequila.circuit.gates import QubitExcitationImpl |
6 | 7 | from tequila import BitNumbering |
7 | 8 |
|
8 | 9 |
|
@@ -218,15 +219,28 @@ def add_basic_gate(self, gate, circuit, *args, **kwargs): |
218 | 219 | self.add_basic_gate(sub_gate, circuit, *args, **kwargs) |
219 | 220 |
|
220 | 221 | elif isinstance(gate, QGateImpl): |
221 | | - # Convert standard gates to Pauli rotations |
222 | | - for ps in gate.make_generator(include_controls=True).paulistrings: |
223 | | - angle = numpy.pi * ps.coeff |
224 | | - if self.angle_threshold is not None and abs(angle) < self.angle_threshold: |
225 | | - continue |
226 | | - exp_term = spex_tequila.ExpPauliTerm() |
227 | | - exp_term.pauli_map = dict(ps.items()) |
228 | | - exp_term.angle = angle |
229 | | - circuit.append(exp_term) |
| 222 | + if gate.name.lower() in ["x","y","z"]: |
| 223 | + # Convert standard gates to Pauli rotations |
| 224 | + for ps in gate.make_generator(include_controls=True).paulistrings: |
| 225 | + angle = numpy.pi * ps.coeff |
| 226 | + if self.angle_threshold is not None and abs(angle) < self.angle_threshold: |
| 227 | + continue |
| 228 | + exp_term = spex_tequila.ExpPauliTerm() |
| 229 | + exp_term.pauli_map = dict(ps.items()) |
| 230 | + exp_term.angle = angle |
| 231 | + circuit.append(exp_term) |
| 232 | + elif gate.name.lower() in ["h", "hadamard"]: |
| 233 | + assert len(gate.target)==1 |
| 234 | + target = gate.target[0] |
| 235 | + for ps in ["-0.25*Y({q})", "Z({q})", "0.25*Y({q})"]: |
| 236 | + ps = QubitHamiltonian(ps.format(q=gate.target[0])).paulistrings[0] |
| 237 | + angle = numpy.pi * ps.coeff |
| 238 | + exp_term = spex_tequila.ExpPauliTerm() |
| 239 | + exp_term.pauli_map = dict(ps.items()) |
| 240 | + exp_term.angle = angle |
| 241 | + circuit.append(exp_term) |
| 242 | + else: |
| 243 | + raise TequilaSpexException("{} not supported. Only x,y,z,h".format(gate.name.lower())) |
230 | 244 |
|
231 | 245 | else: |
232 | 246 | raise TequilaSpexException(f"Unsupported gate object type: {type(gate)}. " |
|
0 commit comments