StateVector in Qibo #1695
-
|
does Qibo support some analogy for qiskit for i in ["".join(seq) for seq in itertools.product("01", repeat=4)]:
# Qiskit
cu = QuantumCircuit(4)
# Qibo
init = Circuit(4)
for j, c in filter(lambda x: int(x[1]) == 1, enumerate(i)):
init.add(gates.X(j))
init = init + xymod4
cu.ccx(1, 3, 2)
cu.cx(1, 3)
cu.cx(0, 2)
# print (cu)
sv = Statevector.from_label(i[::-1])
sv1 = sv.evolve(cu)
# sv = partial_trace(sv, [2,3])
# r = list(sv.data.real).index(1.)
print(i, sv1.data.real,
# 0 if qubit_state(sv1, [1, 2, 3])[0].real == 1 else 1,
# 0 if qubit_state(sv1, [0, 2, 3])[0].real == 1 else 1,
str(0 if qubit_state(sv1, [0, 1, 3])[0].real == 1 else 1)+
str(0 if qubit_state(sv1, [0, 1, 2])[0].real == 1 else 1))#, "result", r, "expected")
init.add(gates.M(*range(2,4)))
# print (init)
result = init(nshots=4096)
print(i, result, list(result.frequencies(binary=True).keys())[0]) |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
|
@geexie It is hard from this snippet alone to understand exactly what you want to do. Could you go a bit more into detail? Also, this snippet is incomplete. For instance, |
Beta Was this translation helpful? Give feedback.
-
|
I wonder whether you want
Is it one of the first three? |
Beta Was this translation helpful? Give feedback.
-
|
For 3 there is `qibo.models.encodings.comp_basis_encoder`.
…On Tue, 22 Jul 2025 at 11:53, Alessandro Candido ***@***.***> wrote:
I wonder whether you want
1. to use the state vector as initial state (which is available in
Qibo), or
2. to get it as a result (which is the default result), or
3. just a constructor to create some specific state out of a bit
string, or some other information (which can do, but you just need to
directly manipulate arrays with NumPy or another array framework, not going
through Qibo - but we could introduce convenient constructors, if
relevant), or
4. something else
Is it one of the first three?
—
Reply to this email directly, view it on GitHub
<#1695 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABH5QVRQSQMHVN2SINGFV5D3JXUYLAVCNFSM6AAAAACCBLYGWSVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTGOBUGM2TQNQ>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
When it comes to measurements, adding them or not is a choice. I do not think there is a more concise way than the one you are already doing. If you want the exact statevector, you could just …