From 0b096f9710431918f6a25ded7ac09815d044aca3 Mon Sep 17 00:00:00 2001 From: rawkintrevo Date: Wed, 9 Oct 2024 12:54:48 -0500 Subject: [PATCH 1/2] Add rotational gates --- qumat/amazon_braket_backend.py | 11 ++++++++++- qumat/cirq_backend.py | 15 ++++++++++++++- qumat/qiskit_backend.py | 11 ++++++++++- qumat/qumat.py | 11 ++++++++++- 4 files changed, 44 insertions(+), 4 deletions(-) diff --git a/qumat/amazon_braket_backend.py b/qumat/amazon_braket_backend.py index bddeae790..02419aa15 100644 --- a/qumat/amazon_braket_backend.py +++ b/qumat/amazon_braket_backend.py @@ -67,4 +67,13 @@ def draw_circuit(circuit): # Unfortunately, Amazon Braket does not have direct support for drawing circuits in the same way # as Qiskit and Cirq. You would typically visualize Amazon Braket circuits using external tools. # For simplicity, we'll print the circuit object which gives some textual representation. - print(circuit) \ No newline at end of file + print(circuit) + +def apply_rx_gate(circuit, qubit_index, angle): + circuit.rx(qubit_index, angle) + +def apply_ry_gate(circuit, qubit_index, angle): + circuit.ry(qubit_index, angle) + +def apply_rz_gate(circuit, qubit_index, angle): + circuit.rz(qubit_index, angle) diff --git a/qumat/cirq_backend.py b/qumat/cirq_backend.py index 056b302e6..b61d6a827 100644 --- a/qumat/cirq_backend.py +++ b/qumat/cirq_backend.py @@ -72,4 +72,17 @@ def execute_circuit(circuit, backend, backend_config): return result.histogram(key='result') def draw_circuit(circuit): - print(circuit) \ No newline at end of file + print(circuit) + +def apply_rx_gate(circuit, qubit_index, angle): + qubit = cirq.LineQubit(qubit_index) + circuit.append(cirq.rx(angle).on(qubit)) + +def apply_ry_gate(circuit, qubit_index, angle): + qubit = cirq.LineQubit(qubit_index) + circuit.append(cirq.ry(angle).on(qubit)) + +def apply_rz_gate(circuit, qubit_index, angle): + qubit = cirq.LineQubit(qubit_index) + circuit.append(cirq.rz(angle).on(qubit)) + diff --git a/qumat/qiskit_backend.py b/qumat/qiskit_backend.py index c8324dcf8..cc6c7afd1 100644 --- a/qumat/qiskit_backend.py +++ b/qumat/qiskit_backend.py @@ -89,4 +89,13 @@ def get_final_state_vector(circuit, backend, backend_config): def draw_circuit(circuit): # Use Qiskit's built-in drawing function - print(circuit.draw()) \ No newline at end of file + print(circuit.draw()) + +def apply_rx_gate(circuit, qubit_index, angle): + circuit.rx(angle, qubit_index) + +def apply_ry_gate(circuit, qubit_index, angle): + circuit.ry(angle, qubit_index) + +def apply_rz_gate(circuit, qubit_index, angle): + circuit.rz(angle, qubit_index) diff --git a/qumat/qumat.py b/qumat/qumat.py index dd5b03eb6..08919d7c6 100644 --- a/qumat/qumat.py +++ b/qumat/qumat.py @@ -60,4 +60,13 @@ def get_final_state_vector(self): return self.backend_module.get_final_state_vector(self.circuit, self.backend, self.backend_config) def draw(self): - return self.backend_module.draw_circuit(self.circuit) \ No newline at end of file + return self.backend_module.draw_circuit(self.circuit) + + def apply_rx_gate(self, qubit_index, angle): + self.backend_module.apply_rx_gate(self.circuit, qubit_index, angle) + + def apply_ry_gate(self, qubit_index, angle): + self.backend_module.apply_ry_gate(self.circuit, qubit_index, angle) + + def apply_rz_gate(self, qubit_index, angle): + self.backend_module.apply_rz_gate(self.circuit, qubit_index, angle) From a65168acdebec439be113676bc1fb3195f87c934 Mon Sep 17 00:00:00 2001 From: rawkintrevo Date: Wed, 9 Oct 2024 12:58:39 -0500 Subject: [PATCH 2/2] Add U gate --- qumat/amazon_braket_backend.py | 5 +++++ qumat/cirq_backend.py | 5 +++++ qumat/qiskit_backend.py | 4 ++++ qumat/qumat.py | 3 +++ 4 files changed, 17 insertions(+) diff --git a/qumat/amazon_braket_backend.py b/qumat/amazon_braket_backend.py index 02419aa15..9422dda8b 100644 --- a/qumat/amazon_braket_backend.py +++ b/qumat/amazon_braket_backend.py @@ -77,3 +77,8 @@ def apply_ry_gate(circuit, qubit_index, angle): def apply_rz_gate(circuit, qubit_index, angle): circuit.rz(qubit_index, angle) + +def apply_u_gate(circuit, qubit_index, theta, phi, lambd): + circuit.rx(qubit_index, theta) + circuit.ry(qubit_index, phi) + circuit.rz(qubit_index, lambd) diff --git a/qumat/cirq_backend.py b/qumat/cirq_backend.py index b61d6a827..e27ab0701 100644 --- a/qumat/cirq_backend.py +++ b/qumat/cirq_backend.py @@ -86,3 +86,8 @@ def apply_rz_gate(circuit, qubit_index, angle): qubit = cirq.LineQubit(qubit_index) circuit.append(cirq.rz(angle).on(qubit)) +def apply_u_gate(circuit, qubit_index, theta, phi, lambd): + qubit = cirq.LineQubit(qubit_index) + circuit.append(cirq.rz(lambd).on(qubit)) + circuit.append(cirq.ry(phi).on(qubit)) + circuit.append(cirq.rx(theta).on(qubit)) diff --git a/qumat/qiskit_backend.py b/qumat/qiskit_backend.py index cc6c7afd1..ca3b0ae62 100644 --- a/qumat/qiskit_backend.py +++ b/qumat/qiskit_backend.py @@ -99,3 +99,7 @@ def apply_ry_gate(circuit, qubit_index, angle): def apply_rz_gate(circuit, qubit_index, angle): circuit.rz(angle, qubit_index) + +def apply_u_gate(circuit, qubit_index, theta, phi, lambd): + # Apply the U gate directly with specified parameters + circuit.u(theta, phi, lambd, qubit_index) diff --git a/qumat/qumat.py b/qumat/qumat.py index 08919d7c6..97101a4a4 100644 --- a/qumat/qumat.py +++ b/qumat/qumat.py @@ -70,3 +70,6 @@ def apply_ry_gate(self, qubit_index, angle): def apply_rz_gate(self, qubit_index, angle): self.backend_module.apply_rz_gate(self.circuit, qubit_index, angle) + + def apply_u_gate(self, qubit_index, theta, phi, lambd): + self.backend_module.apply_u_gate(self.circuit, qubit_index, theta, phi, lambd)