Skip to content
Permalink
Browse files

cleanup

  • Loading branch information...
vtomole committed Aug 18, 2018
1 parent 4a0bf60 commit 5c496cbf3f3457b28a3330660fac4634bb24a7cb
Showing with 893 additions and 2,575 deletions.
  1. +108 −0 cirq/bell_inequality.py
  2. +56 −0 cirq/bell_inequality.qasm
  3. +126 −0 cirq/bernstein_vazirani.py
  4. +2 −0 cirq/hello.cirq
  5. +11 −0 cirq/hello.qasm
  6. +3 −0 cirq/line_qubit.py
  7. +34 −0 cirq/run_qasm.py
  8. +9 −0 cirq/wavefunction.py
  9. +2 −1 projectq/epr.py
  10. +27 −0 pyquil/api_test.py
  11. +1 −1 pyquil/berstein-vazirani.quil
  12. +0 −1 pyquil/composite_gates.py
  13. +28 −46 pyquil/deutsch.py
  14. +1 −1 pyquil/epr.py
  15. +6 −6 pyquil/experiments.py
  16. +1 −1 pyquil/gate_noise.py
  17. +0 −2 pyquil/ghz.py
  18. +1 −1 pyquil/grover-3.py
  19. +12 −17 pyquil/grover.py
  20. +1 −1 pyquil/grover.quil
  21. +1 −1 pyquil/grover3.quil
  22. +8 −8 pyquil/grover_garbage.py
  23. +1 −1 pyquil/grover_one.quil
  24. +1 −3 pyquil/grover_three.quil
  25. +1 −3 pyquil/grover_two.quil
  26. +2 −2 pyquil/grover_zero.quil
  27. +9 −6 pyquil/hadamard_test.py
  28. +1 −2 pyquil/hhl.py
  29. +1 −1 pyquil/hidden_shift.quil
  30. +2 −2 pyquil/hll.py
  31. +3 −3 pyquil/inqnet.py
  32. +30 −0 pyquil/introduction.py
  33. +4 −7 pyquil/linear.py
  34. +2 −2 pyquil/linear.quil
  35. +1 −1 pyquil/lpn.quil
  36. +100 −0 pyquil/nonlocal.py
  37. +19 −0 pyquil/pauli.py
  38. +2 −2 pyquil/phase_estimation.py
  39. +20 −0 pyquil/qa.py
  40. +91 −89 pyquil/qec.py
  41. +34 −27 pyquil/qpu_results.txt
  42. +26 −30 pyquil/qram.py
  43. +1 −1 pyquil/real-bernstein.quil
  44. +4 −1 pyquil/run_quil.py
  45. +4 −1 pyquil/run_quil_qpu.py
  46. +10 −10 pyquil/shor.py
  47. +5 −5 pyquil/stabilizer.py
  48. +6 −6 pyquil/superdense_coding.py
  49. +1 −1 pyquil/swap.quil
  50. +8 −8 pyquil/teleportation.py
  51. +2 −2 pyquil/teleportation.quil
  52. +32 −0 pyquil/test.py
  53. +20 −0 pyquil/test1.py
  54. +12 −14 pyquil/test_runs.py
  55. +0 −11 qchackers.asd
  56. +0 −65 reversible/irreversible.lisp
  57. +0 −17 reversible/package.lisp
  58. +0 −30 reversible/reversible.lisp
  59. +0 −37 reversible/sat.lisp
  60. BIN web-app/images/hll-circuit.png
  61. BIN web-app/images/sphere-visualization.png
  62. BIN web-app/site/.DS_Store
  63. +0 −1 web-app/site/.gitignore
  64. +0 −17 web-app/site/.meteor/.finished-upgraders
  65. +0 −1 web-app/site/.meteor/.gitignore
  66. +0 −7 web-app/site/.meteor/.id
  67. +0 −30 web-app/site/.meteor/packages
  68. +0 −2 web-app/site/.meteor/platforms
  69. +0 −1 web-app/site/.meteor/release
  70. +0 −88 web-app/site/.meteor/versions
  71. +0 −8 web-app/site/client/head.html
  72. +0 −4 web-app/site/client/main.js
  73. +0 −203 web-app/site/client/main.less
  74. BIN web-app/site/imports/.DS_Store
  75. +0 −5 web-app/site/imports/api/links/links.js
  76. +0 −24 web-app/site/imports/api/links/links.tests.js
  77. +0 −18 web-app/site/imports/api/links/methods.js
  78. +0 −24 web-app/site/imports/api/links/methods.tests.js
  79. +0 −8 web-app/site/imports/api/links/server/publications.js
  80. +0 −28 web-app/site/imports/api/links/server/publications.tests.js
  81. +0 −2 web-app/site/imports/startup/both/index.js
  82. +0 −74 web-app/site/imports/startup/client/Detector.js
  83. +0 −5 web-app/site/imports/startup/client/index.js
  84. +0 −31 web-app/site/imports/startup/client/routes.js
  85. +0 −882 web-app/site/imports/startup/client/three.min.js
  86. +0 −21 web-app/site/imports/startup/server/fixtures.js
  87. +0 −4 web-app/site/imports/startup/server/index.js
  88. +0 −4 web-app/site/imports/startup/server/register-api.js
  89. BIN web-app/site/imports/ui/.DS_Store
  90. BIN web-app/site/imports/ui/components/.DS_Store
  91. +0 −3 web-app/site/imports/ui/components/hello/hello.html
  92. +0 −19 web-app/site/imports/ui/components/hello/hello.js
  93. +0 −17 web-app/site/imports/ui/components/hll-viz/hll-viz.html
  94. +0 −239 web-app/site/imports/ui/components/hll-viz/hll-viz.js
  95. BIN web-app/site/imports/ui/components/hll/.DS_Store
  96. +0 −27 web-app/site/imports/ui/components/hll/hll.html
  97. +0 −30 web-app/site/imports/ui/components/hll/hll.js
  98. +0 −15 web-app/site/imports/ui/components/info/info.html
  99. +0 −32 web-app/site/imports/ui/components/info/info.js
  100. +0 −3 web-app/site/imports/ui/layouts/body/body.html
  101. +0 −1 web-app/site/imports/ui/layouts/body/body.js
  102. BIN web-app/site/imports/ui/pages/home/.DS_Store
  103. +0 −21 web-app/site/imports/ui/pages/home/home.js
  104. +0 −11 web-app/site/imports/ui/pages/not-found/not-found.html
  105. +0 −1 web-app/site/imports/ui/pages/not-found/not-found.js
  106. +0 −5 web-app/site/imports/ui/pages/viz/viz.html
  107. +0 −3 web-app/site/imports/ui/pages/viz/viz.js
  108. +0 −35 web-app/site/imports/ui/stylesheets/not-found.less
  109. +0 −12 web-app/site/package.json
  110. +0 −3 web-app/site/private/README.md
  111. +0 −113 web-app/site/public/img/404.svg
  112. +0 −12 web-app/site/public/img/bg-footer.svg
  113. BIN web-app/site/public/img/brendon.jpg
  114. BIN web-app/site/public/img/edan.jpg
  115. BIN web-app/site/public/img/victory.jpg
  116. +0 −4 web-app/site/server/main.js
@@ -0,0 +1,108 @@
"""Creates and simulates a circuit equivalent to a Bell inequality test.
=== EXAMPLE OUTPUT ===
Circuit:
(0, 0): ───H───@───X^-0.25───────X^0.5───M───
│ │
(0, 1): ───────┼─────────────H───@───────M───
(1, 0): ───────X─────────────────X^0.5───M───
(1, 1): ─────────────────────H───@───────M───
Simulating 75 repetitions...
Results
a: _1__11111___111111_1__1_11_11__111________1___1_111_111_____1111_1_111__1_1
b: _1__1__11_1_1_1__1_1_1_1_11____111_111__11_____1_1__1111_1_11___111_11_1__1
x: ____11______11111__1_1111111____1_111__1111___1111_1__11_1__11_11_11_1__11_
y: 11_111_____1_1_111__11111_111_1____1____11_____11___11_1_1___1_111111_1_1_1
(a XOR b) == (x AND y):
1111_1_111_11111111111111111_1111111__1111_111_111_11111111_11_11111111_111
Win rate: 84.0%
"""

from typing import Union, Iterable

import numpy as np

import cirq


def main():
# Create circuit.
circuit = make_bell_test_circuit()
print('Circuit:')
print(circuit.to_qasm())

# Run simulations.
print()
repetitions = 75
print('Simulating {} repetitions...'.format(repetitions))
result = cirq.google.XmonSimulator().run(circuit=circuit,
repetitions=repetitions)

# Collect results.
a = np.array(result.measurements['a'][:, 0])
b = np.array(result.measurements['b'][:, 0])
x = np.array(result.measurements['x'][:, 0])
y = np.array(result.measurements['y'][:, 0])
outcomes = a ^ b == x & y
win_percent = len([e for e in outcomes if e]) * 100 / repetitions

# Print data.
print()
print('Results')
print('a:', bitstring(a))
print('b:', bitstring(b))
print('x:', bitstring(x))
print('y:', bitstring(y))
print('(a XOR b) == (x AND y):\n ', bitstring(outcomes))
print('Win rate: {}%'.format(win_percent))


def make_bell_test_circuit():
alice = cirq.GridQubit(0, 0)
bob = cirq.GridQubit(1, 0)
alice_referee = cirq.GridQubit(0, 1)
bob_referee = cirq.GridQubit(1, 1)

circuit = cirq.Circuit()

# Prepare shared entangled state.
circuit.append([
cirq.H(alice),
cirq.CNOT(alice, bob),
cirq.X(alice)**-0.25,
])

# Referees flip coins.
circuit.append([
cirq.H(alice_referee),
cirq.H(bob_referee),
])

# Players do a sqrt(X) based on their referee's coin.
circuit.append([
cirq.CNOT(alice_referee, alice)**0.5,
cirq.CNOT(bob_referee, bob)**0.5,
])

# Then results are recorded.
circuit.append([
cirq.measure(alice, key='a'),
cirq.measure(bob, key='b'),
cirq.measure(alice_referee, key='x'),
cirq.measure(bob_referee, key='y'),
])

return circuit


def bitstring(bits: Iterable[Union[bool, int]]) -> str:
return ''.join('1' if e else '_' for e in bits)


if __name__ == '__main__':
main()
@@ -0,0 +1,56 @@
// Generated from Cirq

OPENQASM 2.0
include "qelib1.inc"


// Qubits: [(0, 0), (0, 1), (1, 0), (1, 1)]
qreg q[4]
creg m_a[1]
creg m_b[1]
creg m_x[1]
creg m_y[1]


h q[0]
cx q[0], q[2]
rx(pi*-0.25) q[0]
h q[1]
h q[3]

// Gate: CNOT**0.5
ry(pi*-0.5) q[0]
u3(pi*0.5, pi*1.0, pi*1.0) q[1]
u3(pi*0.5, pi*1.0, pi*1.0) q[0]
rx(pi*0.5) q[1]
cx q[1], q[0]
rx(pi*0.25) q[1]
ry(pi*0.5) q[0]
cx q[0], q[1]
rx(pi*-0.5) q[0]
rz(pi*0.5) q[0]
cx q[1], q[0]
u3(pi*0.5, pi*0.25, 0) q[1]
u3(pi*0.5, pi*0.25, 0) q[0]
ry(pi*0.5) q[0]

// Gate: CNOT**0.5
ry(pi*-0.5) q[2]
u3(pi*0.5, pi*1.0, pi*1.0) q[3]
u3(pi*0.5, pi*1.0, pi*1.0) q[2]
rx(pi*0.5) q[3]
cx q[3], q[2]
rx(pi*0.25) q[3]
ry(pi*0.5) q[2]
cx q[2], q[3]
rx(pi*-0.5) q[2]
rz(pi*0.5) q[2]
cx q[3], q[2]
u3(pi*0.5, pi*0.25, 0) q[3]
u3(pi*0.5, pi*0.25, 0) q[2]
ry(pi*0.5) q[2]

measure q[0] -> m_a[0]
measure q[2] -> m_b[0]
measure q[1] -> m_x[0]
measure q[3] -> m_y[0]
@@ -0,0 +1,126 @@
"""Demonstrates the Bernstein-Vazirani algorithm.
The (non-recursive) Bernstein-Vazirani algorithm takes a black-box oracle
implementing a function f(a) = a·factors + bias (mod 2), where 'bias' is 0 or 1,
'a' and 'factors' are vectors with all elements equal to 0 or 1, and the
algorithm solves for 'factors' in a single query to the oracle.
=== REFERENCE ===
Bernstein, Ethan, and Umesh Vazirani. "Quantum complexity theory."
SIAM Journal on Computing 26.5 (1997): 1411-1473.
=== EXAMPLE OUTPUT ===
Secret function:
f(a) = a·<0, 1, 1, 1, 0, 0, 1, 0> + 1 (mod 2)
Circuit:
(0, 0): ───────H───────────────────────H───M───
(1, 0): ───────H───────@───────────────H───M───
│ │
(2, 0): ───────H───────┼───@───────────H───M───
│ │ │
(3, 0): ───────H───────┼───┼───@───────H───M───
│ │ │ │
(4, 0): ───────H───────┼───┼───┼───────H───M───
│ │ │ │
(5, 0): ───────H───────┼───┼───┼───────H───M───
│ │ │ │
(6, 0): ───────H───────┼───┼───┼───@───H───M───
│ │ │ │ │
(7, 0): ───────H───────┼───┼───┼───┼───H───M───
│ │ │ │
(8, 0): ───X───H───X───X───X───X───X───────────
Sampled results:
Counter({'01110010': 3})
Most common matches secret factors:
True
"""

import random

import cirq


def main():
qubit_count = 8
circuit_sample_count = 3

# Choose qubits to use.
input_qubits = [cirq.GridQubit(i, 0) for i in range(qubit_count)]
output_qubit = cirq.GridQubit(qubit_count, 0)

# Pick coefficients for the oracle and create a circuit to query it.
secret_bias_bit = random.randint(0, 1)
secret_factor_bits = [random.randint(0, 1) for _ in range(qubit_count)]
oracle = make_oracle(input_qubits,
output_qubit,
secret_factor_bits,
secret_bias_bit)
print('Secret function:\nf(a) = a·<{}> + {} (mod 2)'.format(
', '.join(str(e) for e in secret_factor_bits),
secret_bias_bit))

# Embed the oracle into a special quantum circuit querying it exactly once.
circuit = make_bernstein_vazirani_circuit(
input_qubits, output_qubit, oracle)
print('Circuit:')
print(circuit)

# Sample from the circuit a couple times.
simulator = cirq.google.XmonSimulator()
result = simulator.run(circuit, repetitions=circuit_sample_count)
frequencies = result.histogram(key='result', fold_func=bitstring)
print('Sampled results:\n{}'.format(frequencies))

# Check if we actually found the secret value.
most_common_bitstring = frequencies.most_common(1)[0][0]
print('Most common matches secret factors:\n{}'.format(
most_common_bitstring == bitstring(secret_factor_bits)))


def make_oracle(input_qubits,
output_qubit,
secret_factor_bits,
secret_bias_bit):
"""Gates implementing the function f(a) = a·factors + bias (mod 2)."""

if secret_bias_bit:
yield cirq.X(output_qubit)

for qubit, bit in zip(input_qubits, secret_factor_bits):
if bit:
yield cirq.CNOT(qubit, output_qubit)


def make_bernstein_vazirani_circuit(input_qubits, output_qubit, oracle):
"""Solves for factors in f(a) = a·factors + bias (mod 2) with one query."""

c = cirq.Circuit()

# Initialize qubits.
c.append([
cirq.X(output_qubit),
cirq.H(output_qubit),
cirq.H.on_each(input_qubits),
])

# Query oracle.
c.append(oracle)

# Measure in X basis.
c.append([
cirq.H.on_each(input_qubits),
cirq.measure(*input_qubits, key='result')
])

return c


def bitstring(bits):
return ''.join(str(int(b)) for b in bits)


if __name__ == '__main__':
main()
@@ -0,0 +1,2 @@
cirq.X(qubit) # Square root of NOT.
cirq.measure(qubit, key='m') # Measurement.
@@ -0,0 +1,11 @@
OPENQASM 2.0
include "qelib1.inc"


// Qubits: [(0, 0)]
qreg q[1]
creg m_m[1]


x q[0]
measure q[0] -> m_m[0]
@@ -0,0 +1,3 @@
from cirq import LineQubit

print(LineQubit.range(6))
@@ -0,0 +1,34 @@
import cirq

# Pick a qubit.
qubit = cirq.GridQubit(0, 0)
prag = ""
fname = "hello.cirq"


prog = """
cirq.X(qubit), # Square root of NOT.
cirq.measure(qubit, key=\'m\') # Measurement.
"""


with open(fname) as f:
for line in f:
prag += line

print(prag)


begin = "cirq.Circuit.from_ops({})".format(prag)

# print(begin)
# Create a circu
circuit = eval(begin)

simulator = cirq.google.XmonSimulator()
result = simulator.run(circuit, repetitions=20)
print("Results:")
print(result)


#print (circuit.to_qasm())
@@ -0,0 +1,9 @@
import cirq

Q1 = cirq.GridQubit(0, 0)

circuit = cirq.Circuit.from_ops(cirq.H(Q1))
simulator = cirq.google.XmonSimulator()
result = simulator.simulate(circuit)

print(simulator.wavefunction(result))
@@ -1,5 +1,6 @@
from projectq import MainEngine # import the main compiler engine
from projectq.ops import H, Measure # import the operations we want to perform (Hadamard and measurement)
# import the operations we want to perform (Hadamard and measurement)
from projectq.ops import H, Measure

eng = MainEngine() # create a default compiler (the back-end is a simulator)
qubit = eng.allocate_qubit() # allocate 1 qubit
@@ -0,0 +1,27 @@
import json
import requests

url = "https://api.rigetti.com/qvm"


api_key = "nmRPAVunQl19TtQz9eMd11iiIsArtUDTaEnsSV6u"
user_id = "4c2166b5-a99d-433c-a289-afcfcd1f1bda"

headers = {'Accept': 'application/octet-stream',
'X-User-Id': user_id,
"X-Api-Key": api_key}

payload = {
"type": "multishot",
"addresses": [0, 1],
"trials": 1,
"compiled-quil": "I 0\nMEASURE 0 [0]\n"

}

# print(payload)

response = requests.post(url, data=json.dumps(payload), headers=headers)


print(type(response.text))
@@ -23,4 +23,4 @@ H 3
MEASURE 0 [0]
MEASURE 1 [1]
MEASURE 2 [2]
MEASURE 3 [3]
MEASURE 3 [3]
Oops, something went wrong.

0 comments on commit 5c496cb

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.