Code: Select all
from qiskit.aqua.circuits import StateVectorCircuit
from qiskit import Aer, execute
# Define the state vector for the X gate
state_vector = [0, 1, 1, 0]
# Create a StateVectorCircuit with 2 qubits
circuit = StateVectorCircuit(state_vector, num_qubits=1)
# Simulate the circuit
simulator = Aer.get_backend('statevector_simulator')
job = execute(circuit, simulator)
# Get the result
result = job.result()
# Get the final state vector
final_state_vector = result.get_statevector()
# Print the final state vector
print("State Vector:", final_state_vector)
When you run this code, you should see that the final state vector matches the expected state vector for the X gate, which is [0, 1, 1, 0]. This demonstrates how to construct a circuit representing an X gate using the StateVectorCircuit class in Qiskit Aqua.