diff --git a/docs/api.md b/docs/api.md index 4b8642aed..418ca1287 100644 --- a/docs/api.md +++ b/docs/api.md @@ -88,9 +88,9 @@ ## `draw_circuit(self)` - **Purpose**: Visualizes the quantum circuit. -- **Usage**: Provides a graphical representation of the quantum circuit for better understanding. -- **Note**: Just a pass through function, will use underlying libraries - method for drawing circuit. +- **Returns**: A string representation of the circuit visualization (format depends on backend). +- **Usage**: Returns a visualization string that can be printed or used programmatically. Example: `print(qc.draw_circuit())` or `viz = qc.draw_circuit()`. +- **Note**: Uses underlying libraries' methods for drawing circuits (Qiskit's `draw()`, Cirq's `str()`, or Braket's `str()`). ## `apply_rx_gate(self, qubit_index, angle)` - **Purpose**: Applies a rotation around the X-axis to a specified qubit with an optional parameter for optimization. diff --git a/qumat/amazon_braket_backend.py b/qumat/amazon_braket_backend.py index a5e8c1bbe..7f6ad6fd5 100644 --- a/qumat/amazon_braket_backend.py +++ b/qumat/amazon_braket_backend.py @@ -114,8 +114,8 @@ def get_final_state_vector(circuit, backend, backend_config): 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) + # For simplicity, we'll return the circuit object's string representation. + return str(circuit) def apply_rx_gate(circuit, qubit_index, angle): diff --git a/qumat/cirq_backend.py b/qumat/cirq_backend.py index dc09b0856..e22b3e3b6 100644 --- a/qumat/cirq_backend.py +++ b/qumat/cirq_backend.py @@ -128,7 +128,8 @@ def execute_circuit(circuit, backend, backend_config): def draw_circuit(circuit): - print(circuit) + # Use Cirq's string representation for circuit visualization + return str(circuit) def apply_rx_gate(circuit, qubit_index, angle): diff --git a/qumat/qiskit_backend.py b/qumat/qiskit_backend.py index 94b773b89..958c8e3b7 100644 --- a/qumat/qiskit_backend.py +++ b/qumat/qiskit_backend.py @@ -139,7 +139,7 @@ def get_final_state_vector(circuit, backend, backend_config): def draw_circuit(circuit): # Use Qiskit's built-in drawing function - print(circuit.draw()) + return circuit.draw() def apply_rx_gate(circuit, qubit_index, angle): diff --git a/qumat/qumat.py b/qumat/qumat.py index 99791d8af..f926da40b 100644 --- a/qumat/qumat.py +++ b/qumat/qumat.py @@ -362,6 +362,18 @@ def draw_circuit(self): self._ensure_circuit_initialized() return self.backend_module.draw_circuit(self.circuit) + def draw(self): + """Alias for draw_circuit() for convenience. + + Provides a shorter method name that matches common quantum computing + library conventions and documentation examples. + + :returns: Circuit visualization. The exact type depends on the backend. + :rtype: str | object + :raises RuntimeError: If the circuit has not been initialized. + """ + return self.draw_circuit() + def apply_rx_gate(self, qubit_index, angle): """Apply a rotation around the X-axis to the specified qubit. diff --git a/website/quantum-computing-primer/03_qubits/index.md b/website/quantum-computing-primer/03_qubits/index.md index aaf61a965..a5c986cfb 100644 --- a/website/quantum-computing-primer/03_qubits/index.md +++ b/website/quantum-computing-primer/03_qubits/index.md @@ -94,7 +94,7 @@ You can also visualize the quantum circuit using the draw method: qc.draw() ``` -This will print a textual representation of the circuit, showing the sequence of gates applied to the qubits. +This returns a textual representation of the circuit, which you can print with `print(qc.draw())` or use programmatically. The visualization shows the sequence of gates applied to the qubits. --- diff --git a/website/quantum-computing-primer/05_quantum_circuits/index.md b/website/quantum-computing-primer/05_quantum_circuits/index.md index fa3a71f73..0a9dd8725 100644 --- a/website/quantum-computing-primer/05_quantum_circuits/index.md +++ b/website/quantum-computing-primer/05_quantum_circuits/index.md @@ -87,7 +87,7 @@ qc.apply_cnot_gate(0, 1) qc.draw() ``` -This code will print a textual representation of the quantum circuit, showing the sequence of gates applied to the qubits. This visualization helps in understanding the structure of the circuit and the flow of quantum information. +This code returns a textual representation of the quantum circuit, which you can print with `print(qc.draw())` or use programmatically. The visualization shows the sequence of gates applied to the qubits and helps in understanding the structure of the circuit and the flow of quantum information. ## 5.3 Combining Gates to Create Complex Circuits