0
$\begingroup$

Hi does anyone know how i could write a program to get the product of something like |1>|0>|0>?

$\endgroup$
2
  • $\begingroup$ Do you mean the tensor product? This can be done as you can use the "statevector simulator". The qubits can be prepared to the desired state $|\psi\rangle$. Then the total output statevector may be the desired output $\endgroup$
    – 刘环宇
    Nov 10 at 2:14
  • $\begingroup$ What sort of multiplication do you have in mind? Tensor product? Inner product? Outer product? $\endgroup$ Nov 10 at 2:21
0
$\begingroup$

Create computational basis state circuit

With qiskit, you can do it like this:

from qiskit.circuit  import QuantumCircuit 
def create_computational_basis_state(basis_state: str):
        qc = QuantumCircuit(len(basis_state))     
        for i, bit in enumerate(basis_state):
            if int(bit) == 1: qc.x(i)
        print(qc)
        return qc 

So for example:

qc = create_computational_basis_state('101')

     ┌───┐
q_0: ┤ X ├
     └───┘
q_1: ─────
     ┌───┐
q_2: ┤ X ├
     └───┘

Extract the state vector

And if you want to get the vector/array of this state (the vector resulting from the tensor product) you can do the following:

from qiskit import Aer, execute
from qiskit.quantum_info import Statevector
backend = Aer.get_backend("statevector_simulator")
result = execute(qc, backend=backend, shots=1).result()
print('State Vector:', result.get_statevector() )

State Vector: [0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 1.+0.j 0.+0.j 0.+0.j]
$\endgroup$
0
$\begingroup$

In Qiskit you can easily do tensor product of two states using ^ operator as follows:

from qiskit.quantum_info import Statevector

state1 = Statevector.from_label('++')
state2 = Statevector.from_label('--')

# Tensor product:
tensored_state = state1 ^ state2

# Or equivalently:
tensored_state = state1.tensor(state2)

# Print the result:
from qiskit.visualization import array_to_latex
array_to_latex(tensored_state, max_size = 16)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.