Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ORNL Quantum Computing Institute
xacc
Commits
14d5bd87
Commit
14d5bd87
authored
May 29, 2020
by
Mccaskey, Alex
Browse files
Adding initial pass at pyzx ir transformation
Signed-off-by:
Alex McCaskey
<
mccaskeyaj@ornl.gov
>
parent
9d5c25b6
Pipeline
#105121
passed with stage
in 71 minutes and 29 seconds
Changes
4
Pipelines
6
Hide whitespace changes
Inline
Side-by-side
python/CMakeLists.txt
View file @
14d5bd87
...
...
@@ -47,5 +47,6 @@ file(GLOB PYDECORATORS benchmark/chemistry/*.py benchmark/qpt/*.py
plugins/cirq/*.py
plugins/qiskit/*.py
plugins/observables/*.py
plugins/pyzx/*.py
plugins/optimizers/*.py
)
install
(
FILES
${
PYDECORATORS
}
DESTINATION
${
CMAKE_INSTALL_PREFIX
}
/py-plugins
)
python/examples/pyzx_example.py
0 → 100644
View file @
14d5bd87
import
xacc
qpu
=
xacc
.
getAccelerator
(
'aer'
,
{
'sim-type'
:
'statevector'
})
q
=
xacc
.
qalloc
(
2
)
# Create a bell state program with too many cnots
xacc
.
qasm
(
'''
.compiler xasm
.circuit foo
.parameters x,y,z
.qbit q
H(q[0]);
CX(q[0], q[1]);
CX(q[0], q[1]);
CX(q[0], q[1]);
Measure(q[0]);
Measure(q[1]);
'''
)
f
=
xacc
.
getCompiled
(
'foo'
)
# Run the python contributed IRTransformation that uses qiskit
optimizer
=
xacc
.
getIRTransformation
(
'pyzx'
)
optimizer
.
apply
(
f
,
None
,
{})
# should have 4 instructions, not 6
assert
(
4
==
f
.
nInstructions
())
print
(
f
.
toString
())
qbits
=
xacc
.
qalloc
(
2
)
qpu
.
execute
(
qbits
,
f
)
print
(
qbits
)
python/plugins/pyzx/README.md
0 → 100644
View file @
14d5bd87
To use this plugin, you need pyzx greater than 0.5.1. As of this
writing you have to install from source
```
bash
$
git clone https://github.com/Quantomatic/pyzx
&&
cd
pyzx
$
python3
-m
pip
install
.
--user
```
\ No newline at end of file
python/plugins/pyzx/pyzx_pass.py
0 → 100644
View file @
14d5bd87
import
xacc
from
pelix.ipopo.decorators
import
ComponentFactory
,
Property
,
Requires
,
Provides
,
\
Validate
,
Invalidate
,
Instantiate
@
ComponentFactory
(
"pyzx_pass_factory"
)
@
Provides
(
"irtransformation"
)
@
Property
(
"_irtransformation"
,
"irtransformation"
,
"pyzx"
)
@
Property
(
"_name"
,
"name"
,
"pyzx"
)
@
Instantiate
(
"pyzx_pass_instance"
)
class
PyzxIRTransformation
(
xacc
.
IRTransformation
):
def
__init__
(
self
):
xacc
.
IRTransformation
.
__init__
(
self
)
def
type
(
self
):
return
xacc
.
IRTransformationType
.
Optimization
def
name
(
self
):
return
'pyzx'
def
apply
(
self
,
program
,
accelerator
,
options
):
# Import qiskit modules here so that users
# who don't have qiskit can still use rest of xacc
from
pyzx.circuit
import
Circuit
from
pyzx
import
simplify
,
extract
,
optimize
# Map CompositeInstruction program to OpenQasm string
openqasm_compiler
=
xacc
.
getCompiler
(
'staq'
)
src
=
openqasm_compiler
.
translate
(
program
).
replace
(
'
\\
'
,
''
)
measures
=
[]
lines
=
src
.
split
(
'
\n
'
)
for
l
in
lines
:
if
'measure'
in
l
or
'creg'
in
l
:
measures
.
append
(
l
)
c
=
Circuit
.
from_qasm
(
src
)
g
=
c
.
to_graph
()
simplify
.
full_reduce
(
g
,
quiet
=
True
)
c2
=
extract
.
extract_circuit
(
g
)
c3
=
optimize
.
basic_optimization
(
c2
.
to_basic_gates
())
c3
=
c3
.
to_basic_gates
()
c3
=
c3
.
split_phase_gates
()
output
=
c3
.
to_qasm
()
for
measure
in
measures
:
output
+=
'
\n
'
+
measure
# Map the output to OpenQasm and map to XACC IR
out_prog
=
openqasm_compiler
.
compile
(
output
,
accelerator
).
getComposites
()[
0
]
# update the given program CompositeInstruction reference
program
.
clear
()
for
inst
in
out_prog
.
getInstructions
():
program
.
addInstruction
(
inst
)
return
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment