Skip to content

Commit

Permalink
minor exporte fixtures for sympy, factorize grover example
Browse files Browse the repository at this point in the history
  • Loading branch information
dakk committed Dec 20, 2023
1 parent 8d38c34 commit bb9731d
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 8 deletions.
6 changes: 3 additions & 3 deletions docs/source/example_big_circuit.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Example: big circuits"
"# Working with big circuits"
]
},
{
Expand All @@ -18,7 +18,7 @@
},
{
"cell_type": "code",
"execution_count": 55,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -34,7 +34,7 @@
},
{
"cell_type": "code",
"execution_count": 56,
"execution_count": 2,
"metadata": {},
"outputs": [
{
Expand Down
102 changes: 102 additions & 0 deletions docs/source/example_grover_factors.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/source/exporter.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Exporting to other framworks"
"# Exporting to other frameworks"
]
},
{
Expand Down
1 change: 1 addition & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Python and translate them into unitary operators (gates) for use in quantum circ
example_grover_subset.ipynb
example_grover_hash.ipynb
example_grover_sudoku.ipynb
example_grover_factorize.ipynb
example_simon.ipynb
example_deutsch_jozsa.ipynb
example_unitary_of_f.ipynb
Expand Down
8 changes: 5 additions & 3 deletions qlasskit/qcircuit/exporter_sympy.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def toffoli(q0, q1, q2):

class SympyExporter(QCircuitExporter):
def export(self, _selfqc, mode: Literal["circuit", "gate"]):
qstate = Qubit("0" * _selfqc.num_qubits)
qstate = Qubit("0" * _selfqc.num_qubits) if mode == 'circuit' else None

for g, w, p in _selfqc.gates:
ga = None
Expand All @@ -50,7 +50,9 @@ def export(self, _selfqc, mode: Literal["circuit", "gate"]):
else:
raise Exception("not handled")

if ga:
if ga and qstate:
qstate = ga * qstate

elif ga:
qstate = ga

return qstate
8 changes: 7 additions & 1 deletion test/test_qcircuit_exporters.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,18 @@ def test_export_qasm_circuit(self):
],
)
class TestQCircuitExportSympy(unittest.TestCase):
def test_export_sympy(self):
def test_export_sympy_circuit(self):
sym_circ = self.qc.export("circuit", "sympy")
statev = qapply(sym_circ)
meas = measure_all(statev)
self.assertEqual(meas, self.result)

def test_export_sympy_gate(self):
sym_circ = self.qc.export("gate", "sympy")
statev = qapply(sym_circ * Qubit("0" * self.qc.num_qubits))
meas = measure_all(statev)
self.assertEqual(meas, self.result)


@parameterized_class(
("qc", "result"),
Expand Down

0 comments on commit bb9731d

Please sign in to comment.