Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

  • 5047386
  • /
  • qasmf2qc.sh
Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
content badge
swh:1:cnt:c63e88d06d65984412eeb011169e529710393ec0
directory badge
swh:1:dir:50473866082fc18b42173bdb06907d59a8383528

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
qasmf2qc.sh
#!/bin/bash
#Shell script that converts .qasmf files to .qc files,
#which are compatible with the QX simulator.
#
# qubits #
# qubit a0 -> map q0, a0
# cbit ma0 -> map b0, ma0
# CNOT a0, a1 -> cnot a0, a1
# Toffoli a0, a1, a2 -> toffoli a0, a1, a2
# MeasZ a0 -> measure a0


exec 10<&0

if [ -z "$1" ]
  then
    echo "[QC Transformer] No arguments supplied, invoke with a qasm file"
    echo -e "\t./qasmf2qc.sh <application_name>.qasmf"
	exit
fi

exec < $1
in=$1

#init
file="${in/qasmf/qc}"
init_file="init_file.qc"
err=0
qubit="qubit *"
cbit="cbit *"
cnot="CNOT *"
toffoli="Tof *"
measZ="MeasZ *"
measX="MeasX *"
prepX="PrepX *"

if [ -f "$file" ]; then echo "Stopped: $file already exists."
else
echo "[QCTransform] Generating $file ..."
let count=0
c_index=0
m_index=0
q_pre='qubit '
c_pre='cbit '
mz_pre='MeasZ '
declare -A labels #associative array requires bash 4.0 or above

while read LINE
do
  case $LINE in
    $qubit)
      # initialize qubits
      echo "${LINE/qubit /map q$count, }" >> $init_file
      labels["${LINE#$q_pre}"]=$count #labels["a0"]=0
      #echo "${LINE/qubit /map b$count, m}" >> $file
      (( count++ ))
    ;;
    $cbit)
      # initialize classical bits (measurement results)
      c_array[$c_index]="${LINE#$c_pre}" #c_array[0]=ma0
      (( c_index++ ))
    ;;
    $cnot)
      # cnot gate
      arrIn=(${LINE/,/ })
      echo "cnot ${arrIn[1]}, ${arrIn[2]}" >> $file
    ;;
    $toffoli)
      # toffoli gate
      arrIn=(${LINE//,/ })
      echo "toffoli ${arrIn[1]}, ${arrIn[2]}, ${arrIn[3]}" >> $file
    ;;
    $measZ)
      # measurement
      echo "${LINE/MeasZ/measure}" >> $file
      c_name=${c_array[m_index]}
      c_bit="b${labels["${LINE#$mz_pre}"]}"
      echo "map $c_bit, $c_name" >> $init_file
      (( m_index++ ))
    ;;
    $measX | $prepX )
      # unsupported gates
      echo "Stopped: Gate not supported (MeasX or PrepX)!"
      err=1
    ;;
    *)
      echo $LINE >> $file
    ;;
  esac
done

if [ "$err" -ne 0 ];
  then
    rm "$file"
    echo "No file generated."
  else
    echo "display" >> $file
    echo "qubits $count" | cat - $init_file > temp && mv temp $init_file
    cat $file >> $init_file && mv $init_file $file
    echo "[QCTransform] Done. Number of qubits: $count"
fi
fi
exec 0<&10 10<&-

back to top

Software Heritage — Copyright (C) 2015–2026, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API