Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Cirq backend #83

Draft
wants to merge 39 commits into
base: main
Choose a base branch
from
Draft

add Cirq backend #83

wants to merge 39 commits into from

Conversation

yasuhito
Copy link
Contributor

No description provided.

@yasuhito yasuhito added the enhancement New feature or request label Feb 14, 2022
@yasuhito yasuhito self-assigned this Feb 14, 2022
@yasuhito yasuhito linked an issue Feb 14, 2022 that may be closed by this pull request
@yasuhito yasuhito marked this pull request as draft February 14, 2022 03:45
* Add Docker of cuStatevector version (WIP)

* Small fixes

* update Dockerfile

* Now use qsim as the backend. Looks like cuquantum is too primitive at the moment
and cannot install outside of conda.

* WIP: cannot install cuQuantum at the moment

* .

* a small fix and now cuquantum builds.

* Cleanups.

* qsim_nvidia -> cirq

* fix cuQuantum download url

* add pycall for gem

* move

* .

* avoid the following error:
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-2: ordinal not in range(128)

* test circuit

* .

* Update qni-cirqbridge.

* qsim GPU support requires to build from the source

* Updated cirqbridge. qsimcirq now runs on the GPU.

* Remove empty circuits.

* .

* .

* rename to cirq to cirq_backend

* Solve conflicts when merging from upstream

* Solve conflicts when merging from upstream

* back to my backend.

* .

* backout to my cirqbridge.

* .

* Impliment |0>, |1> initializations and H gate.

Co-authored-by: Yasuhito Takamiya <[email protected]>
@yasuhito yasuhito assigned nakatamaho and unassigned yasuhito Feb 14, 2022
@nakatamaho nakatamaho marked this pull request as ready for review February 24, 2022 00:08
@yasuhito
Copy link
Contributor Author

Cirq → Ruby へ状態ベクトルを渡す

Cirq バックエンドで計算した状態ベクトルを Ruby に渡すには、次のフォーマットの配列を返す必要があります。

# 振幅の[実部,虚部] の Array 
[[0.42678, -0.17678],[0.17678, -0.07322],[0.17678, 0.42678],[0.07322, 0.17678],[-0.42678, 0.17678],[-0.17678, 0.07322],[-0.17678, -0.42678],[-0.07322, -0.17678]]

たとえば、3 量子ビットの場合には振幅は 8 個なので、上のように [実部,虚部] のペアが 8 個になります。

Cirq バックエンドに渡される targets: オプションは、バックエンドが返すべき振幅のインデックスを指定します (量子ビット数が大きいときに全部返すと大変なので)。たとえば targets: [0, 1, 2, 3] の場合は、最初から 4 つぶんだけの振幅を返せば OK です。

どこで返すか

apps/www/lib/cirq.rbrun メソッドの最後で、上述の Array を返せば Ruby に渡ります。

qni/apps/www/lib/cirq.rb

Lines 99 to 103 in 7c5350d

def run
cirqbridge = PyCall.eval('cirqbridge').call
cirqbridge.run_simulation(@qubit_count, @steps)
@steps.map.with_index { |each, index| execute_step each, index }
end

ちなみにこの run メソッドは、BackendControllershow メソッドから呼ばれ、配列が Ruby の @step_results インスタンス変数に入ります。

@step_results =
Cirq.new(circuit_id: circuit_id, qubit_count: qubit_count, step_index: step_index, steps: steps, targets: targets)
.run

これは show.json.jbuilder の中で JSON 形式に変換されます。

json.array! @step_results

backend

@yasuhito yasuhito marked this pull request as draft April 27, 2022 23:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Now we use Cirq backend
2 participants