This commit is contained in:
ismael faro 2017-05-15 10:00:02 -04:00
parent b97d30f0ba
commit 611ee62ddb
1 changed files with 50 additions and 140 deletions

View File

@ -91,7 +91,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"metadata": {
"collapsed": true
},
@ -113,20 +113,11 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
">> quantum_registers created: qr 2\n",
">> classical_registers created: cr 2\n"
]
}
],
"outputs": [],
"source": [
"# Creating Programs\n",
"# create your first QuantumProgram object instance.\n",
@ -153,7 +144,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": null,
"metadata": {
"collapsed": true
},
@ -185,20 +176,11 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
">> quantum_registers created: qr 4\n",
">> classical_registers created: cr 4\n"
]
}
],
"outputs": [],
"source": [
"new_Q_program = QuantumProgram(specs=Q_SPECS)"
]
@ -212,7 +194,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": null,
"metadata": {
"collapsed": true
},
@ -242,22 +224,11 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"<qiskit._measure.Measure at 0x1123cae10>"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"# H (Hadamard) gate to the Qbit 0 in the Quantum Register \"qr\" \n",
"circuit.h(quantum_r[0])\n",
@ -313,36 +284,11 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"OPENQASM 2.0;\n",
"include \"qelib1.inc\";\n",
"qreg qr[4];\n",
"creg cr[4];\n",
"h qr[0];\n",
"x qr[1];\n",
"y qr[2];\n",
"z qr[3];\n",
"cx qr[0],qr[2];\n",
"barrier qr[0],qr[1],qr[2],qr[3];\n",
"u1(0.300000000000000) qr[0];\n",
"u2(0.300000000000000,0.200000000000000) qr[1];\n",
"u3(0.300000000000000,0.200000000000000,0.100000000000000) qr[2];\n",
"u1(1.570796326794897) qr[0];\n",
"u1(0.785398163397448) qr[1];\n",
"id qr[1];\n",
"measure qr[0] -> cr[0];\n",
"\n"
]
}
],
"outputs": [],
"source": [
"# QASM from a circuit\n",
"\n",
@ -353,35 +299,11 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"OPENQASM 2.0;\n",
"include \"qelib1.inc\";\n",
"qreg qr[4];\n",
"creg cr[4];\n",
"u1(3.141592653589793) qr[3];\n",
"u3(3.141592653589793,1.5707963267948966,1.5707963267948966) qr[2];\n",
"u3(3.141592653589793,0.0,3.141592653589793) qr[1];\n",
"u2(0.0,3.141592653589793) qr[0];\n",
"cx qr[0],qr[2];\n",
"barrier qr[0],qr[1],qr[2],qr[3];\n",
"u1(0.3) qr[0];\n",
"u1(1.570796326794897) qr[0];\n",
"measure qr[0] -> cr[0];\n",
"u2(0.3,0.2) qr[1];\n",
"u1(0.785398163397448) qr[1];\n",
"id qr[1];\n",
"u3(0.3,0.2,0.1) qr[2];\n"
]
}
],
"outputs": [],
"source": [
"# Qasm from a program\n",
"\n",
@ -406,22 +328,11 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"device = 'simulator' #Backend where execute your program, in this case it is the online simulator\n",
"circuits = [circuit] #Group of circuits to exec\n",
@ -431,23 +342,11 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'qasm': 'OPENQASM 2.0;\\ninclude \"qelib1.inc\";\\nqreg qr[4];\\ncreg cr[4];\\nu1(3.141592653589793) qr[3];\\nu3(3.141592653589793,1.5707963267948966,1.5707963267948966) qr[2];\\nu3(3.141592653589793,0.0,3.141592653589793) qr[1];\\nu2(0.0,3.141592653589793) qr[0];\\ncx qr[0],qr[2];\\nbarrier qr[0],qr[1],qr[2],qr[3];\\nu1(0.3) qr[0];\\nu1(1.570796326794897) qr[0];\\nmeasure qr[0] -> cr[0];\\nu2(0.3,0.2) qr[1];\\nu1(0.785398163397448) qr[1];\\nid qr[1];\\nu3(0.3,0.2,0.1) qr[2];\\n'}\n",
"status = RUNNING (2 seconds)\n",
"status = RUNNING (4 seconds)\n",
"status = RUNNING (6 seconds)\n",
"{'qasms': [{'qasm': '\\ninclude \"qelib1.inc\";\\nqreg qr[4];\\ncreg cr[4];\\nu1(3.141592653589793) qr[3];\\nu3(3.141592653589793,1.5707963267948966,1.5707963267948966) qr[2];\\nu3(3.141592653589793,0.0,3.141592653589793) qr[1];\\nu2(0.0,3.141592653589793) qr[0];\\ncx qr[0],qr[2];\\nbarrier qr[0],qr[1],qr[2],qr[3];\\nu1(0.3) qr[0];\\nu1(1.570796326794897) qr[0];\\nmeasure qr[0] -> cr[0];\\nu2(0.3,0.2) qr[1];\\nu1(0.785398163397448) qr[1];\\nid qr[1];\\nu3(0.3,0.2,0.1) qr[2];\\n', 'status': 'DONE', 'executionId': 'b070f5eb42bf1b0c636280c1c63088e5', 'result': {'date': '2017-05-15T13:56:16.556Z', 'data': {'time': 0.10589289665222168, 'counts': {'0000': 516, '0001': 508}}}}], 'shots': 1024, 'backend': {'name': 'simulator'}, 'status': 'COMPLETED', 'maxCredits': 3, 'usedCredits': 0, 'creationDate': '2017-05-15T13:56:15.769Z', 'deleted': False, 'id': '21fffc66396ac274a5be97779a781095', 'userId': '933a590a13327c52eb5310484d6bcf54'}\n"
]
}
],
"outputs": [],
"source": [
"Q_program.compile(circuits, device) #Compile your program\n",
"\n",
@ -478,21 +377,11 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'qasm': 'OPENQASM 2.0;\\ninclude \"qelib1.inc\";\\nqreg qr[4];\\ncreg cr[4];\\nu1(3.141592653589793) qr[3];\\nu3(3.141592653589793,1.5707963267948966,1.5707963267948966) qr[2];\\nu3(3.141592653589793,0.0,3.141592653589793) qr[1];\\nu2(0.0,3.141592653589793) qr[0];\\ncx qr[0],qr[2];\\nbarrier qr[0],qr[1],qr[2],qr[3];\\nu1(0.3) qr[0];\\nu1(1.570796326794897) qr[0];\\nmeasure qr[0] -> cr[0];\\nu2(0.3,0.2) qr[1];\\nu1(0.785398163397448) qr[1];\\nid qr[1];\\nu3(0.3,0.2,0.1) qr[2];\\n'}\n",
"status = RUNNING (2 seconds)\n",
"status = RUNNING (4 seconds)\n"
]
}
],
"outputs": [],
"source": [
"result = Q_program.execute(circuits, device, wait=2, timeout=240)"
]
@ -534,19 +423,11 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'qasm': 'OPENQASM 2.0;\\ninclude \"qelib1.inc\";\\nqreg qr[4];\\ncreg cr[4];\\nu1(3.141592653589793) qr[3];\\nu3(3.141592653589793,1.5707963267948966,1.5707963267948966) qr[2];\\nu3(3.141592653589793,0.0,3.141592653589793) qr[1];\\nu2(0.0,3.141592653589793) qr[0];\\ncx qr[0],qr[2];\\nbarrier qr[0],qr[1],qr[2],qr[3];\\nu1(0.3) qr[0];\\nu1(1.570796326794897) qr[0];\\nmeasure qr[0] -> cr[0];\\nu2(0.3,0.2) qr[1];\\nu1(0.785398163397448) qr[1];\\nid qr[1];\\nu3(0.3,0.2,0.1) qr[2];\\n'}\n"
]
}
],
"outputs": [],
"source": [
"device = 'qx5qv2' #Backed where execute your program, in this case in the Real Quantum Chip online \n",
"circuits = [circuit] #Group of circuits to exec\n",
@ -564,6 +445,35 @@
"You can access to the result in the element: qasms[n].result.data.counts "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"result['qasms'][0]['result']['data']['counts']"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"or you can use the function tool get_data(n) to obtain it directly"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"Q_program.get_data(result,0) "
]
},
{
"cell_type": "code",
"execution_count": null,