This is an implementation of IBM's Quantum Experience in simulation; a 5-qubit quantum computer with a limited set of gates. Please cite me if you end up using this academically.
I am following up on my research in the philosophical field of "quantum thinking" (not binary... false/true, good/evil, right/wrong ...) and, meanwhile, I try to deepen my technical knowledge on the functioning of the QASM language .
I'm new to Python3, just a month old, but I'm old in several other languages, including C++.
Unfortunately I still do not fully understand the QuantumComputer.py functionalities, but I'm working to.
Despite the online availability of the IBM Quantum-e platform, it naturally needs an internet connection and ends up being slow for many tests, as well as the limitations on the size of the QASM code, and the quantum score restrictions for CNOT gates.
For the huge amount of logical testing I need to do, your application is 100% effective. It is fast and flexible, precisely because it is not limited to the constraints of the real quantum computer.
Well ... after this long introduction, I explain below the reason for my post:
Are the qubits in |psi>=|100> from Probability.pretty_print_probabilities function in "reverse" order 01234 ?
I was testing the Toffoli gate, and I expected the following results in 43210 order:
00 --> |psi>=|000>
01 --> |psi>=|001>
10 --> |psi>=|010>
11 --> |psi>=|111>
But, I always get the following result:
00 --> |psi>=|000>
01 --> |psi>=|100> <-------Look at this! In reverse order 01234 !
10 --> |psi>=|010>
11 --> |psi>=|111>
I thought I had typed something wrong in the qasm code, but I realized that the sequence is in reverse order 01234.
Well... I'm working hard to assimilate the logic of QuantumComputer.py
Looking at the internal array Python structures, we can see that always start in 0, then is natural to work with qubits in that order: 012434
Then, it is more simple adjust the sequence of qubits at end of process.
The field 'state_desc' in 'pretty_print_probabilities' function own the solution.
The field 'QuantumRegister.num_qubits(state)' give us the number of 'state_desc' digits to be inverted.
This is the "new" pretty_print_probabilities: (Note the #MVCM remarks in the modified lines)
def pretty_print_probabilities(state):
probs=Probability.get_probabilities(state)
am_desc='|psi>='
pr_desc=''
#MVCM get num qubits to print: 1 to 5
nqb = QuantumRegister.num_qubits(state)
for am,pr,state_desc in zip(state.flat,probs,State.all_state_strings( QuantumRegister.num_qubits(state))):
#MVCM invert state_desc binary sequence from 01234 to 43210 for |psi> print
state_desc_inverted = ''
offset = nqb - 1
for n in range(0,nqb):
occ = ((n+offset)-(2*n))
state_desc_inverted += str(state_desc[occ:occ+1])
if am!=0:
if am!=1:
#MVCM am_desc+='%r|%s>+'%(am,state_desc)
am_desc+='%r|%s>+'%(am,state_desc_inverted)
else:
#MVCM am_desc+='|%s>+'%(state_desc)
am_desc+='|%s>+'%(state_desc_inverted)
if pr!=0:
#MVCM pr_desc+='Pr(|%s>)=%f; '%(state_desc,pr)
pr_desc+='Pr(|%s>)=%f; '%(state_desc_inverted,pr)
print(am_desc[0:-1])
print(pr_desc)
if state.shape==(4,1):
print("<state>=%f" % float(probs[0]+probs[3]-probs[1]-probs[2]))
The sample attached adjust the qubit0 to |1> using a X gate to give us a 00001 at end, in 43210 order.
Because the boring warning from module at start, I did change also the "if state==None:" clause to "if state is None:" in the lines 201 and 567, and, you see below the print result 'before' and 'after' the changes:
Before changes...
Python 3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 17:54:52) [MSC v.1900 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
Warning (from warnings module):
File "C:\Users\Usuario\Dropbox\IBM\QUBIT\QUINTUPLE\FONTES\QuantumComputer.py", line 200
if state==None:
FutureWarning: comparison to None will result in an elementwise object comparison in the future.
Python 3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 17:54:52) [MSC v.1900 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
I am following up on my research in the philosophical field of "quantum thinking" (not binary... false/true, good/evil, right/wrong ...) and, meanwhile, I try to deepen my technical knowledge on the functioning of the QASM language .
I'm new to Python3, just a month old, but I'm old in several other languages, including C++. Unfortunately I still do not fully understand the QuantumComputer.py functionalities, but I'm working to.
Despite the online availability of the IBM Quantum-e platform, it naturally needs an internet connection and ends up being slow for many tests, as well as the limitations on the size of the QASM code, and the quantum score restrictions for CNOT gates.
For the huge amount of logical testing I need to do, your application is 100% effective. It is fast and flexible, precisely because it is not limited to the constraints of the real quantum computer.
Well ... after this long introduction, I explain below the reason for my post:
Are the qubits in |psi>=|100> from Probability.pretty_print_probabilities function in "reverse" order 01234 ?
I was testing the Toffoli gate, and I expected the following results in 43210 order: 00 --> |psi>=|000> 01 --> |psi>=|001> 10 --> |psi>=|010> 11 --> |psi>=|111>
But, I always get the following result: 00 --> |psi>=|000> 01 --> |psi>=|100> <-------Look at this! In reverse order 01234 ! 10 --> |psi>=|010> 11 --> |psi>=|111>
I thought I had typed something wrong in the qasm code, but I realized that the sequence is in reverse order 01234.
Well... I'm working hard to assimilate the logic of QuantumComputer.py
Looking at the internal array Python structures, we can see that always start in 0, then is natural to work with qubits in that order: 012434
Then, it is more simple adjust the sequence of qubits at end of process.
The field 'state_desc' in 'pretty_print_probabilities' function own the solution. The field 'QuantumRegister.num_qubits(state)' give us the number of 'state_desc' digits to be inverted.
This is the "new" pretty_print_probabilities: (Note the #MVCM remarks in the modified lines)
The sample attached adjust the qubit0 to |1> using a X gate to give us a 00001 at end, in 43210 order.
Because the boring warning from module at start, I did change also the "if state==None:" clause to "if state is None:" in the lines 201 and 567, and, you see below the print result 'before' and 'after' the changes:
Before changes...
Python 3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 17:54:52) [MSC v.1900 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information.
Warning (from warnings module): File "C:\Users\Usuario\Dropbox\IBM\QUBIT\QUINTUPLE\FONTES\QuantumComputer.py", line 200 if state==None: FutureWarning: comparison to
None
will result in an elementwise object comparison in the future.========== QUANTUM REGISTER ========== QUBIT 0 |psi>=|10000> Pr(|10000>)=1.000000; QUBIT 1 |psi>=|10000> Pr(|10000>)=1.000000; QUBIT 2 |psi>=|10000> Pr(|10000>)=1.000000; QUBIT 3 |psi>=|10000> Pr(|10000>)=1.000000; QUBIT 4 |psi>=|10000> Pr(|10000>)=1.000000;
Then, after changes...
Python 3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 17:54:52) [MSC v.1900 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information.
========== QUANTUM REGISTER ========== QUBIT 0 |psi>=|00001> Pr(|00001>)=1.000000; QUBIT 1 |psi>=|00001> Pr(|00001>)=1.000000; QUBIT 2 |psi>=|00001> Pr(|00001>)=1.000000; QUBIT 3 |psi>=|00001> Pr(|00001>)=1.000000; QUBIT 4 |psi>=|00001> Pr(|00001>)=1.000000;
Solved! :)
Marcus Mello UNIRIO Universidade Federal do Estado do Rio de Janeiro Departamento de Filosofia
Toffoli_0+1=2+3=4.txt