From 3ca29bf7b48e075a176c6b44ca285af786ff8f8d Mon Sep 17 00:00:00 2001 From: Mark Skilbeck Date: Fri, 20 Nov 2020 19:31:17 +0000 Subject: [PATCH] Support controlled gates in PyQVM Really this hands off matrix calculation to `pyquil.simulation.tools.lifted_gate()` which has better support for the various gate modifiers. --- pyquil/simulation/_numpy.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/pyquil/simulation/_numpy.py b/pyquil/simulation/_numpy.py index b27525634..11db726b0 100644 --- a/pyquil/simulation/_numpy.py +++ b/pyquil/simulation/_numpy.py @@ -22,6 +22,7 @@ from pyquil.pyqvm import AbstractQuantumSimulator from pyquil.quilbase import Gate from pyquil.simulation.matrices import QUANTUM_GATES +from pyquil.simulation.tools import lifted_gate # The following function is lovingly copied from the Cirq project # https://github.com/quantumlib/Cirq @@ -149,11 +150,7 @@ def _get_gate_tensor_and_qubits(gate: Gate) -> Tuple[np.ndarray, List[int]]: :param gate: the instruction :return: tensor, qubit_inds. """ - if len(gate.params) > 0: - matrix = QUANTUM_GATES[gate.name](*gate.params) - else: - matrix = QUANTUM_GATES[gate.name] - + matrix = lifted_gate(gate, n_qubits=len(gate.qubits)) qubit_inds = [q.index for q in gate.qubits] # e.g. 2-qubit matrix is 4x4; turns into (2,2,2,2) tensor.