Skip to content

Commit

Permalink
MAHOUT 464/5/6/7 - Add rotational gates (#471)
Browse files Browse the repository at this point in the history
* Add rotational gates

* Add U gate
  • Loading branch information
rawkintrevo authored Oct 15, 2024
1 parent 955050e commit 56e62c5
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 4 deletions.
16 changes: 15 additions & 1 deletion qumat/amazon_braket_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,18 @@ 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)
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)

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)
20 changes: 19 additions & 1 deletion qumat/cirq_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,22 @@ def execute_circuit(circuit, backend, backend_config):
return result.histogram(key='result')

def draw_circuit(circuit):
print(circuit)
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))

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))
15 changes: 14 additions & 1 deletion qumat/qiskit_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,17 @@ def get_final_state_vector(circuit, backend, backend_config):

def draw_circuit(circuit):
# Use Qiskit's built-in drawing function
print(circuit.draw())
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)

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)
14 changes: 13 additions & 1 deletion qumat/qumat.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,16 @@ 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)
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)

def apply_u_gate(self, qubit_index, theta, phi, lambd):
self.backend_module.apply_u_gate(self.circuit, qubit_index, theta, phi, lambd)

0 comments on commit 56e62c5

Please sign in to comment.